porn4fans fix
This commit is contained in:
@@ -188,7 +188,9 @@ impl HqpornerProvider {
|
||||
.await
|
||||
.map_err(|e| Error::from(format!("Request failed: {}", e)))?;
|
||||
|
||||
let video_items = self.get_video_items_from_html(text, &mut requester, &options).await;
|
||||
let video_items = self
|
||||
.get_video_items_from_html(text, &mut requester, &options)
|
||||
.await;
|
||||
if !video_items.is_empty() {
|
||||
cache.insert(video_url, video_items.clone());
|
||||
}
|
||||
@@ -234,7 +236,9 @@ impl HqpornerProvider {
|
||||
.await
|
||||
.map_err(|e| Error::from(format!("Request failed: {}", e)))?;
|
||||
|
||||
let video_items = self.get_video_items_from_html(text, &mut requester, &options).await;
|
||||
let video_items = self
|
||||
.get_video_items_from_html(text, &mut requester, &options)
|
||||
.await;
|
||||
if !video_items.is_empty() {
|
||||
cache.insert(video_url, video_items.clone());
|
||||
}
|
||||
|
||||
@@ -356,7 +356,9 @@ impl JavtifulProvider {
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let duration = parse_time_to_seconds(&raw_duration).unwrap_or(0) as u32;
|
||||
let (tags, formats, views) = self.extract_media(&video_url, &mut requester, options).await?;
|
||||
let (tags, formats, views) = self
|
||||
.extract_media(&video_url, &mut requester, options)
|
||||
.await?;
|
||||
|
||||
if preview.len() == 0 {
|
||||
preview = format!("https://trailers.jav.si/preview/{id}.mp4");
|
||||
|
||||
@@ -296,7 +296,11 @@ pub fn strip_url_scheme(url: &str) -> String {
|
||||
|
||||
pub fn build_proxy_url(options: &ServerOptions, proxy: &str, target: &str) -> String {
|
||||
let target = target.trim_start_matches('/');
|
||||
let base = options.public_url_base.as_deref().unwrap_or("").trim_end_matches('/');
|
||||
let base = options
|
||||
.public_url_base
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.trim_end_matches('/');
|
||||
|
||||
if base.is_empty() {
|
||||
format!("/proxy/{proxy}/{target}")
|
||||
|
||||
@@ -150,7 +150,10 @@ impl NoodlemagazineProvider {
|
||||
|
||||
list.split("<div class=\"item\">")
|
||||
.skip(1)
|
||||
.filter_map(|segment| self.get_video_item(segment.to_string(), proxy_base_url).ok())
|
||||
.filter_map(|segment| {
|
||||
self.get_video_item(segment.to_string(), proxy_base_url)
|
||||
.ok()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user