This commit is contained in:
Simon
2026-03-05 13:51:57 +00:00
parent 8157e223fe
commit 76fd5a4f4f
5 changed files with 39 additions and 132 deletions

View File

@@ -5,11 +5,9 @@ use crate::status::*;
use crate::util::cache::VideoCache;
use crate::util::requester::Requester;
use crate::videos::VideoItem;
use crate::videos::{self, ServerOptions};
use crate::videos::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! {
@@ -214,77 +212,6 @@ impl ParadisehillProvider {
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]

View File

@@ -83,7 +83,10 @@ impl Porn00Provider {
_ => "list_videos_most_recent_videos",
};
let video_url = format!("{}{}/?mode=async^&function=get_block^&block_id={}^&from={}", self.url, sort_string, list_str, page);
let video_url = format!(
"{}{}/?mode=async&function=get_block&block_id={}&from={}",
self.url, sort_string, list_str, page
);
let old_items = match cache.get(&video_url) {
Some((time, items)) => {
if time.elapsed().unwrap_or_default().as_secs() < 60 * 5 {

View File

@@ -71,20 +71,18 @@ impl XxthotsProvider {
sort: &str,
options: ServerOptions,
) -> Result<Vec<VideoItem>> {
let sort_string = match sort {
"popular" => "/most-popular",
"top-rated" => "/top-rated",
_ => "/latest-updates/",
};
let list_str = match sort {
"popular" => "list_videos_common_videos_list",
"top-rated" => "list_videos_common_videos_list",
_ => "list_videos_most_recent_videos",
let (sort_path, list_str, sort_by) = match sort {
"popular" => ("/most-popular/", "list_videos_common_videos_list", "video_viewed"),
"top-rated" => ("/top-rated/", "list_videos_common_videos_list", "rating"),
_ => (
"/latest-updates/",
"list_videos_latest_videos_list",
"post_date",
),
};
let video_url = format!(
"{}{}?mode=async^&function=get_block^&block_id={}^&from={}",
self.url, sort_string, list_str, page
"{}{}?mode=async&function=get_block&block_id={}&sort_by={}&from={}",
self.url, sort_path, list_str, sort_by, page
);
let old_items = match cache.get(&video_url) {
Some((time, items)) => {
@@ -112,6 +110,15 @@ impl XxthotsProvider {
return Ok(old_items);
}
};
if text.trim().is_empty() {
crate::providers::report_provider_error(
"xxthots",
"get.empty_response",
&format!("url={video_url}"),
)
.await;
return Ok(old_items);
}
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone());
if !video_items.is_empty() {
cache.remove(&video_url);
@@ -161,6 +168,15 @@ impl XxthotsProvider {
return Ok(old_items);
}
};
if text.trim().is_empty() {
crate::providers::report_provider_error(
"xxthots",
"query.empty_response",
&format!("url={video_url}"),
)
.await;
return Ok(old_items);
}
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone());
if !video_items.is_empty() {
cache.remove(&video_url);
@@ -173,16 +189,15 @@ impl XxthotsProvider {
fn get_video_items_from_html(&self, html: String) -> Vec<VideoItem> {
if html.is_empty() {
println!("HTML is empty");
return vec![];
}
let mut items: Vec<VideoItem> = Vec::new();
let raw_videos = html
let raw_videos: Vec<&str> = html
.split("<div class=\"pagination\"")
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
.split("<div class=\"thumb thumb_rel item \">")
.collect::<Vec<&str>>()[1..]
.to_vec();
.skip(1)
.collect();
for video_segment in &raw_videos {
// let vid = video_segment.split("\n").collect::<Vec<&str>>();
// for (index, line) in vid.iter().enumerate() {
@@ -253,11 +268,10 @@ impl Provider for XxthotsProvider {
per_page: String,
options: ServerOptions,
) -> Vec<VideoItem> {
let _ = options;
let _ = per_page;
let _ = pool;
let videos: std::result::Result<Vec<VideoItem>, Error> = match query {
Some(q) => {
Some(q) if !q.trim().is_empty() => {
self.query(cache, page.parse::<u8>().unwrap_or(1), &q, options)
.await
}
@@ -265,6 +279,7 @@ impl Provider for XxthotsProvider {
self.get(cache, page.parse::<u8>().unwrap_or(1), &sort, options)
.await
}
_ => self.get(cache, page.parse::<u8>().unwrap_or(1), &sort, options).await,
};
match videos {
Ok(v) => v,