porn4fans fix

This commit is contained in:
Simon
2026-03-13 12:13:04 +00:00
parent 2e1223e519
commit 6a62582c09
10 changed files with 345 additions and 33 deletions

View File

@@ -49,6 +49,7 @@ impl Porn4fansProvider {
fn sort_by(sort: &str) -> &'static str {
match sort {
"popular" => "video_viewed",
_ => "post_date",
}
}
@@ -136,7 +137,8 @@ impl Porn4fansProvider {
return Ok(old_items);
}
let video_items = self.get_video_items_from_html(text);
let video_items =
self.get_video_items_from_html(text, options.public_url_base.as_deref().unwrap_or(""));
if !video_items.is_empty() {
cache.remove(&video_url);
cache.insert(video_url.clone(), video_items.clone());
@@ -193,7 +195,8 @@ impl Porn4fansProvider {
return Ok(old_items);
}
let video_items = self.get_video_items_from_html(text);
let video_items =
self.get_video_items_from_html(text, options.public_url_base.as_deref().unwrap_or(""));
if !video_items.is_empty() {
cache.remove(&video_url);
cache.insert(video_url.clone(), video_items.clone());
@@ -229,6 +232,20 @@ impl Porn4fansProvider {
format!("{}/{}", self.url, url.trim_start_matches("./"))
}
fn proxy_url(&self, proxy_base_url: &str, url: &str) -> String {
let path = url
.strip_prefix(&self.url)
.unwrap_or(url)
.trim_start_matches('/');
if proxy_base_url.is_empty() {
return format!("/proxy/porn4fans/{path}");
}
format!(
"{}/proxy/porn4fans/{path}",
proxy_base_url.trim_end_matches('/')
)
}
fn extract_thumb_url(&self, segment: &str) -> String {
let thumb_raw = Self::first_non_empty_attr(
segment,
@@ -265,7 +282,7 @@ impl Porn4fansProvider {
.and_then(|m| m.as_str().trim().parse::<f32>().ok())
}
fn get_video_items_from_html(&self, html: String) -> Vec<VideoItem> {
fn get_video_items_from_html(&self, html: String, proxy_base_url: &str) -> Vec<VideoItem> {
if html.trim().is_empty() {
return vec![];
}
@@ -311,8 +328,14 @@ impl Porn4fansProvider {
let views = Self::extract_views(body).unwrap_or(0);
let rating = Self::extract_rating(body);
let mut item =
VideoItem::new(id, title, href, "porn4fans".to_string(), thumb, duration);
let mut item = VideoItem::new(
id,
title,
self.proxy_url(proxy_base_url, &href),
"porn4fans".to_string(),
thumb,
duration,
);
if views > 0 {
item = item.views(views);
}
@@ -423,12 +446,12 @@ mod tests {
</div>
"##;
let items = provider.get_video_items_from_html(html.to_string());
let items = provider.get_video_items_from_html(html.to_string(), "https://example.com");
assert_eq!(items.len(), 1);
assert_eq!(items[0].id, "10194");
assert_eq!(
items[0].url,
"https://www.porn4fans.com/video/10194/horny-police-officer-melztube-gets-banged-by-bbc/"
"https://example.com/proxy/porn4fans/video/10194/horny-police-officer-melztube-gets-banged-by-bbc/"
);
assert_eq!(
items[0].thumb,