provider refactors and fixes

This commit is contained in:
Simon
2026-03-05 13:28:38 +00:00
parent 060d8e7937
commit 8157e223fe
33 changed files with 3051 additions and 1694 deletions

View File

@@ -1,5 +1,7 @@
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;
@@ -28,13 +30,28 @@ impl 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 = options.requester.clone().unwrap();
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);
@@ -51,7 +68,18 @@ impl ParadisehillProvider {
}
};
let text = requester.get(&url_str, None).await.unwrap();
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)
@@ -73,7 +101,7 @@ impl ParadisehillProvider {
options: ServerOptions,
) -> Result<Vec<VideoItem>> {
// Extract needed fields from options at the start
let mut requester = options.requester.clone().unwrap();
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={}",
@@ -93,7 +121,18 @@ impl ParadisehillProvider {
vec![]
}
};
let text = requester.get(&url_str, None).await.unwrap();
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;
@@ -109,46 +148,90 @@ impl ParadisehillProvider {
async fn get_video_items_from_html(
&self,
html: String,
requester: Requester,
_requester: Requester,
) -> Vec<VideoItem> {
if html.is_empty() {
println!("HTML is empty");
return vec![];
}
let raw_videos = html.split("item list-film-item").collect::<Vec<&str>>()[1..].to_vec();
let mut urls: Vec<String> = vec![];
for video_segment in &raw_videos {
// let vid = video_segment.split("\n").collect::<Vec<&str>>();
// for (index, line) in vid.iter().enumerate() {
// println!("Line {}: {}", index, line.to_string().trim());
// }
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 url_str = format!(
"{}{}",
self.url,
video_segment.split("<a href=\"").collect::<Vec<&str>>()[1]
.split("\"")
.collect::<Vec<&str>>()[0]
.to_string()
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),
);
urls.push(url_str.clone());
}
let futures = urls
.into_iter()
.map(|el| self.get_video_item(el.clone(), requester.clone()));
let results: Vec<Result<VideoItem>> = join_all(futures).await;
let video_items: Vec<VideoItem> = results.into_iter().filter_map(Result::ok).collect();
return video_items;
items
}
async fn get_video_item(&self, url_str: String, mut requester: Requester) -> Result<VideoItem> {
let vid = requester.get(&url_str, None).await.unwrap();
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>>()[1]
.collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
.split("\"")
.collect::<Vec<&str>>()[0]
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
.trim()
.to_string();
title = decode(title.as_bytes()).to_string().unwrap_or(title);
@@ -156,27 +239,27 @@ impl ParadisehillProvider {
"{}{}",
self.url,
vid.split("<meta property=\"og:image\" content=\"")
.collect::<Vec<&str>>()[1]
.collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
.split("\"")
.collect::<Vec<&str>>()[0]
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
.to_string()
);
let video_urls = vid.split("var videoList = ").collect::<Vec<&str>>()[1]
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>>()[0]
.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().to_string())
.format_note(format!("{}", video_url.split("_").last().unwrap().replace(".mp4", "").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);
}
@@ -184,9 +267,9 @@ impl ParadisehillProvider {
formats.reverse();
let id = url_str
.split("/")
.collect::<Vec<&str>>()[3]
.collect::<Vec<&str>>().get(3).copied().unwrap_or_default()
.split("_")
.collect::<Vec<&str>>()[0]
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
.to_string();
let video_item = VideoItem::new(
@@ -237,4 +320,8 @@ impl Provider for ParadisehillProvider {
}
}
}
fn get_channel(&self, clientversion: ClientVersion) -> Option<Channel> {
Some(self.build_channel(clientversion))
}
}