viralxxxporn fix

This commit is contained in:
Simon
2026-04-25 16:40:53 +00:00
committed by ForgeCode
parent 635c45d2c1
commit 2bd132820b

View File

@@ -5,7 +5,7 @@ use crate::status::*;
use crate::util::cache::VideoCache; use crate::util::cache::VideoCache;
use crate::util::parse_abbreviated_number; use crate::util::parse_abbreviated_number;
use crate::util::time::parse_time_to_seconds; use crate::util::time::parse_time_to_seconds;
use crate::videos::{ServerOptions, VideoFormat, VideoItem}; use crate::videos::{ServerOptions, VideoItem};
use async_trait::async_trait; use async_trait::async_trait;
use error_chain::error_chain; use error_chain::error_chain;
use htmlentity::entity::{ICodedDataTrait, decode}; use htmlentity::entity::{ICodedDataTrait, decode};
@@ -260,6 +260,14 @@ impl ViralxxxpornProvider {
format!("{}/{}", self.url, url.trim_start_matches("./")) format!("{}/{}", self.url, url.trim_start_matches("./"))
} }
fn normalize_video_item_url(&self, url: &str) -> String {
let normalized = self.normalize_url(url);
if normalized.contains("/videos/") {
return normalized.replacen("/videos/", "/video/", 1);
}
normalized
}
fn extract_id_from_url(url: &str) -> String { fn extract_id_from_url(url: &str) -> String {
let parts = url let parts = url
.trim_end_matches('/') .trim_end_matches('/')
@@ -353,7 +361,7 @@ impl ViralxxxpornProvider {
let href = captures let href = captures
.name("href") .name("href")
.map(|m| self.normalize_url(m.as_str())) .map(|m| self.normalize_video_item_url(m.as_str()))
.unwrap_or_default(); .unwrap_or_default();
let body = captures let body = captures
.name("body") .name("body")
@@ -402,13 +410,7 @@ impl ViralxxxpornProvider {
item = item.views(views); item = item.views(views);
} }
if !preview.is_empty() { if !preview.is_empty() {
let mut format = VideoFormat::new( item = item.preview(preview);
preview.clone(),
"preview".to_string(),
"video/mp4".to_string(),
);
format.add_http_header("Referer".to_string(), item.url.clone());
item = item.preview(preview).formats(vec![format]);
} }
items.push(item); items.push(item);
} }
@@ -450,7 +452,7 @@ impl ViralxxxpornProvider {
else { else {
continue; continue;
}; };
let video_url = self.normalize_url(&video_url_raw); let video_url = self.normalize_video_item_url(&video_url_raw);
let id = Self::extract_id_from_url(&video_url); let id = Self::extract_id_from_url(&video_url);
if id.is_empty() { if id.is_empty() {
continue; continue;
@@ -506,13 +508,7 @@ impl ViralxxxpornProvider {
item = item.views(views); item = item.views(views);
} }
if !preview.is_empty() { if !preview.is_empty() {
let mut format = VideoFormat::new( item = item.preview(preview);
preview.clone(),
"preview".to_string(),
"video/mp4".to_string(),
);
format.add_http_header("Referer".to_string(), item.url.clone());
item = item.preview(preview).formats(vec![format]);
} }
items.push(item); items.push(item);
} }
@@ -616,11 +612,12 @@ mod tests {
assert_eq!(items[0].title, "Sample & Title"); assert_eq!(items[0].title, "Sample & Title");
assert_eq!( assert_eq!(
items[0].url, items[0].url,
"https://viralxxxporn.com/videos/336186/sample-video/" "https://viralxxxporn.com/video/336186/sample-video/"
); );
assert_eq!(items[0].thumb, "https://cdn.example/thumb.jpg"); assert_eq!(items[0].thumb, "https://cdn.example/thumb.jpg");
assert_eq!(items[0].duration, 754); assert_eq!(items[0].duration, 754);
assert_eq!(items[0].views, Some(1_200_000)); assert_eq!(items[0].views, Some(1_200_000));
assert!(items[0].formats.is_none());
} }
#[test] #[test]
@@ -645,6 +642,7 @@ mod tests {
assert_eq!(items[0].thumb, "https://cdn.example.com/thumb.jpg"); assert_eq!(items[0].thumb, "https://cdn.example.com/thumb.jpg");
assert_eq!(items[0].duration, 780); assert_eq!(items[0].duration, 780);
assert_eq!(items[0].views, Some(29_000)); assert_eq!(items[0].views, Some(29_000));
assert!(items[0].formats.is_none());
} }
#[test] #[test]