bugfixes
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user