views and bug fixes

This commit is contained in:
Simon
2025-07-16 19:00:42 +00:00
parent 19146616dc
commit 19a6115eb1
2 changed files with 27 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
use crate::util::parse_abbreviated_number;
use crate::DbPool;
use crate::providers::Provider;
use crate::util::cache::VideoCache;
@@ -200,6 +201,10 @@ impl PornhubProvider {
.collect::<Vec<&str>>()[0]
.to_string();
let duration = parse_time_to_seconds(&raw_duration).unwrap_or(0) as u32;
let views = parse_abbreviated_number(video_segment.split("iews\">").collect::<Vec<&str>>()[1]
.split("<var>").collect::<Vec<&str>>()[1]
.split("<")
.collect::<Vec<&str>>()[0]).unwrap_or(0);
let thumb = video_segment.split("src=\"").collect::<Vec<&str>>()[1]
.split("\"")
@@ -212,7 +217,9 @@ impl PornhubProvider {
"pornhub".to_string(),
thumb,
duration,
);
)
.views(views)
;
items.push(video_item);
}
return items;

View File

@@ -1,3 +1,21 @@
pub mod time;
pub mod flaresolverr;
pub mod cache;
pub mod cache;
pub fn parse_abbreviated_number(s: &str) -> Option<u32> {
let s = s.trim();
if s.is_empty() {
return None;
}
let (num_part, suffix) = s
.chars()
.partition::<String, _>(|c| c.is_ascii_digit() || *c == '.');
let multiplier = match suffix.trim().to_ascii_uppercase().as_str() {
"K" => 1_000.0,
"M" => 1_000_000.0,
"B" => 1_000_000_000.0,
"" => 1.0,
_ => return None,
};
num_part.parse::<f64>().ok().map(|n| (n * multiplier) as u32)
}