328 lines
10 KiB
Rust
328 lines
10 KiB
Rust
use crate::api::ClientVersion;
|
|
use crate::DbPool;
|
|
use crate::providers::Provider;
|
|
use crate::status::*;
|
|
use crate::util::cache::VideoCache;
|
|
use crate::util::requester::Requester;
|
|
use crate::videos::VideoItem;
|
|
use crate::videos::{self, ServerOptions};
|
|
use error_chain::error_chain;
|
|
use futures::future::join_all;
|
|
use htmlentity::entity::{ICodedDataTrait, decode};
|
|
use std::vec;
|
|
use async_trait::async_trait;
|
|
|
|
error_chain! {
|
|
foreign_links {
|
|
Io(std::io::Error);
|
|
HttpRequest(wreq::Error);
|
|
JsonError(serde_json::Error);
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct ParadisehillProvider {
|
|
url: String,
|
|
}
|
|
impl ParadisehillProvider {
|
|
pub fn new() -> Self {
|
|
ParadisehillProvider {
|
|
url: "https://en.paradisehill.cc".to_string(),
|
|
}
|
|
}
|
|
|
|
fn build_channel(&self, _clientversion: ClientVersion) -> Channel {
|
|
Channel {
|
|
id: "paradisehill".to_string(),
|
|
name: "Paradisehill".to_string(),
|
|
description: "Porn Movies on Paradise Hill".to_string(),
|
|
premium: false,
|
|
favicon: "https://www.google.com/s2/favicons?sz=64&domain=en.paradisehill.cc".to_string(),
|
|
status: "active".to_string(),
|
|
categories: vec![],
|
|
options: vec![],
|
|
nsfw: true,
|
|
cacheDuration: None,
|
|
}
|
|
}
|
|
async fn get(
|
|
&self,
|
|
cache: VideoCache,
|
|
page: u8,
|
|
options: ServerOptions,
|
|
) -> Result<Vec<VideoItem>> {
|
|
let mut requester = crate::providers::requester_or_default(&options, module_path!(), "missing_requester");
|
|
|
|
let url_str = format!("{}/all/?sort=created_at&page={}", self.url, page);
|
|
|
|
let old_items = match cache.get(&url_str) {
|
|
Some((time, items)) => {
|
|
if time.elapsed().unwrap_or_default().as_secs() < 60 * 60 {
|
|
return Ok(items.clone());
|
|
} else {
|
|
items.clone()
|
|
}
|
|
}
|
|
None => {
|
|
vec![]
|
|
}
|
|
};
|
|
|
|
let text = match requester.get(&url_str, None).await {
|
|
Ok(text) => text,
|
|
Err(e) => {
|
|
crate::providers::report_provider_error(
|
|
"paradisehill",
|
|
"get.request",
|
|
&format!("url={url_str}; error={e}"),
|
|
)
|
|
.await;
|
|
return Ok(old_items);
|
|
}
|
|
};
|
|
// Pass a reference to options if needed, or reconstruct as needed
|
|
let video_items: Vec<VideoItem> = self
|
|
.get_video_items_from_html(text.clone(), requester)
|
|
.await;
|
|
if !video_items.is_empty() {
|
|
cache.remove(&url_str);
|
|
cache.insert(url_str.clone(), video_items.clone());
|
|
} else {
|
|
return Ok(old_items);
|
|
}
|
|
Ok(video_items)
|
|
}
|
|
|
|
async fn query(
|
|
&self,
|
|
cache: VideoCache,
|
|
page: u8,
|
|
query: &str,
|
|
options: ServerOptions,
|
|
) -> Result<Vec<VideoItem>> {
|
|
// Extract needed fields from options at the start
|
|
let mut requester = crate::providers::requester_or_default(&options, module_path!(), "missing_requester");
|
|
let search_string = query.replace(" ", "+");
|
|
let url_str = format!(
|
|
"{}/search/?pattern={}&page={}",
|
|
self.url, search_string, page
|
|
);
|
|
// Check our Video Cache. If the result is younger than 1 hour, we return it.
|
|
let old_items = match cache.get(&url_str) {
|
|
Some((time, items)) => {
|
|
if time.elapsed().unwrap_or_default().as_secs() < 60 * 60 {
|
|
return Ok(items.clone());
|
|
} else {
|
|
let _ = cache.check().await;
|
|
return Ok(items.clone());
|
|
}
|
|
}
|
|
None => {
|
|
vec![]
|
|
}
|
|
};
|
|
let text = match requester.get(&url_str, None).await {
|
|
Ok(text) => text,
|
|
Err(e) => {
|
|
crate::providers::report_provider_error(
|
|
"paradisehill",
|
|
"query.request",
|
|
&format!("url={url_str}; error={e}"),
|
|
)
|
|
.await;
|
|
return Ok(old_items);
|
|
}
|
|
};
|
|
let video_items: Vec<VideoItem> = self
|
|
.get_video_items_from_html(text.clone(), requester)
|
|
.await;
|
|
if !video_items.is_empty() {
|
|
cache.remove(&url_str);
|
|
cache.insert(url_str.clone(), video_items.clone());
|
|
} else {
|
|
return Ok(old_items);
|
|
}
|
|
Ok(video_items)
|
|
}
|
|
|
|
async fn get_video_items_from_html(
|
|
&self,
|
|
html: String,
|
|
_requester: Requester,
|
|
) -> Vec<VideoItem> {
|
|
if html.is_empty() {
|
|
println!("HTML is empty");
|
|
return vec![];
|
|
}
|
|
let mut items: Vec<VideoItem> = Vec::new();
|
|
for video_segment in html.split("item list-film-item").skip(1) {
|
|
let href = video_segment
|
|
.split("<a href=\"")
|
|
.nth(1)
|
|
.and_then(|s| s.split('"').next())
|
|
.unwrap_or_default();
|
|
if href.is_empty() {
|
|
continue;
|
|
}
|
|
|
|
let video_url = format!("{}{}", self.url, href);
|
|
let id = href
|
|
.trim_matches('/')
|
|
.split('/')
|
|
.next()
|
|
.unwrap_or_default()
|
|
.to_string();
|
|
if id.is_empty() {
|
|
continue;
|
|
}
|
|
|
|
let mut title = video_segment
|
|
.split("itemprop=\"name\">")
|
|
.nth(1)
|
|
.and_then(|s| s.split('<').next())
|
|
.unwrap_or_default()
|
|
.trim()
|
|
.to_string();
|
|
title = decode(title.as_bytes()).to_string().unwrap_or(title);
|
|
|
|
let mut thumb = video_segment
|
|
.split("itemprop=\"image\" src=\"")
|
|
.nth(1)
|
|
.and_then(|s| s.split('"').next())
|
|
.unwrap_or_default()
|
|
.to_string();
|
|
if thumb.starts_with('/') {
|
|
thumb = format!("{}{}", self.url, thumb);
|
|
}
|
|
|
|
let genre = video_segment
|
|
.split("itemprop=\"genre\">")
|
|
.nth(1)
|
|
.and_then(|s| s.split('<').next())
|
|
.unwrap_or_default()
|
|
.trim()
|
|
.to_string();
|
|
let tags = if genre.is_empty() { vec![] } else { vec![genre] };
|
|
|
|
items.push(
|
|
VideoItem::new(id, title, video_url, "paradisehill".to_string(), thumb, 0)
|
|
.aspect_ratio(0.697674419 as f32)
|
|
.tags(tags),
|
|
);
|
|
}
|
|
|
|
items
|
|
}
|
|
|
|
async fn get_video_item(&self, url_str: String, mut requester: Requester) -> Result<VideoItem> {
|
|
let vid = match requester.get(&url_str, None).await {
|
|
Ok(vid) => vid,
|
|
Err(e) => {
|
|
crate::providers::report_provider_error(
|
|
"paradisehill",
|
|
"get_video_item.request",
|
|
&format!("url={url_str}; error={e}"),
|
|
)
|
|
.await;
|
|
return Err(Error::from(e.to_string()));
|
|
}
|
|
};
|
|
let mut title = vid
|
|
.split("<meta property=\"og:title\" content=\"")
|
|
.collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
|
.split("\"")
|
|
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
|
.trim()
|
|
.to_string();
|
|
title = decode(title.as_bytes()).to_string().unwrap_or(title);
|
|
let thumb = format!(
|
|
"{}{}",
|
|
self.url,
|
|
vid.split("<meta property=\"og:image\" content=\"")
|
|
.collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
|
.split("\"")
|
|
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
|
.to_string()
|
|
);
|
|
|
|
let video_urls = vid.split("var videoList = ").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
|
.split("\"src\":\"")
|
|
.collect::<Vec<&str>>()[1..].to_vec();
|
|
let mut formats = vec![];
|
|
for url in video_urls {
|
|
let video_url = url
|
|
.split("\"")
|
|
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
|
.replace("\\", "")
|
|
.to_string();
|
|
let format =
|
|
videos::VideoFormat::new(video_url.clone(), "1080".to_string(), "mp4".to_string())
|
|
// .protocol("https".to_string())
|
|
.format_id(video_url.split("/").last().unwrap_or_default().to_string())
|
|
.format_note(video_url.split("_").last().unwrap_or_default().replace(".mp4", ""))
|
|
;
|
|
formats.push(format);
|
|
}
|
|
|
|
formats.reverse();
|
|
let id = url_str
|
|
.split("/")
|
|
.collect::<Vec<&str>>().get(3).copied().unwrap_or_default()
|
|
.split("_")
|
|
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
|
.to_string();
|
|
|
|
let video_item = VideoItem::new(
|
|
id,
|
|
title,
|
|
url_str.clone(),
|
|
"paradisehill".to_string(),
|
|
thumb,
|
|
0,
|
|
)
|
|
.aspect_ratio(0.697674419 as f32)
|
|
.formats(formats);
|
|
|
|
return Ok(video_item);
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl Provider for ParadisehillProvider {
|
|
async fn get_videos(
|
|
&self,
|
|
cache: VideoCache,
|
|
pool: DbPool,
|
|
sort: String,
|
|
query: Option<String>,
|
|
page: String,
|
|
per_page: String,
|
|
options: ServerOptions,
|
|
) -> Vec<VideoItem> {
|
|
let _ = pool;
|
|
let _ = sort;
|
|
let _ = per_page;
|
|
let videos: std::result::Result<Vec<VideoItem>, Error> = match query {
|
|
Some(q) => {
|
|
self.query(cache, page.parse::<u8>().unwrap_or(1), &q, options)
|
|
.await
|
|
}
|
|
None => {
|
|
self.get(cache, page.parse::<u8>().unwrap_or(1), options)
|
|
.await
|
|
}
|
|
};
|
|
match videos {
|
|
Ok(v) => v,
|
|
Err(e) => {
|
|
println!("Error fetching videos: {}", e);
|
|
vec![]
|
|
}
|
|
}
|
|
}
|
|
|
|
fn get_channel(&self, clientversion: ClientVersion) -> Option<Channel> {
|
|
Some(self.build_channel(clientversion))
|
|
}
|
|
}
|