fixes and cleanup

This commit is contained in:
Simon
2026-03-05 18:18:48 +00:00
parent 76fd5a4f4f
commit 2627505ade
49 changed files with 3245 additions and 1376 deletions

View File

@@ -11,9 +11,9 @@ use crate::videos::{ServerOptions, VideoFormat, VideoItem};
use async_trait::async_trait;
use error_chain::error_chain;
use futures::future::join_all;
use htmlentity::entity::{decode, ICodedDataTrait};
use htmlentity::entity::{ICodedDataTrait, decode};
use std::sync::{Arc, RwLock};
use std::{vec};
use std::vec;
use titlecase::Titlecase;
use wreq::Version;
@@ -118,10 +118,7 @@ impl JavtifulProvider {
"most viewed" => "/sort=most_viewed",
_ => "",
};
let video_url = format!(
"{}/videos{}?page={}",
self.url, sort_string, page
);
let video_url = format!("{}/videos{}?page={}", self.url, sort_string, page);
let old_items = match cache.get(&video_url) {
Some((time, items)) => {
if time.elapsed().unwrap_or_default().as_secs() < 60 * 5 {
@@ -149,7 +146,12 @@ impl JavtifulProvider {
return Ok(old_items);
}
};
if page > 1 && !text.contains(&format!("<li class=\"page-item active\"><span class=\"page-link\">{}</span>", page)) {
if page > 1
&& !text.contains(&format!(
"<li class=\"page-item active\"><span class=\"page-link\">{}</span>",
page
))
{
return Ok(vec![]);
}
let video_items: Vec<VideoItem> = self
@@ -178,7 +180,10 @@ impl JavtifulProvider {
};
let video_url = format!(
"{}/search/videos{}?search_query={}&page={}",
self.url, sort_string, query.replace(" ","+"), page
self.url,
sort_string,
query.replace(" ", "+"),
page
);
// Check our Video Cache. If the result is younger than 1 hour, we return it.
let old_items = match cache.get(&video_url) {
@@ -209,7 +214,12 @@ impl JavtifulProvider {
return Ok(old_items);
}
};
if page > 1 && !text.contains(&format!("<li class=\"page-item active\"><span class=\"page-link\">{}</span>", page)) {
if page > 1
&& !text.contains(&format!(
"<li class=\"page-item active\"><span class=\"page-link\">{}</span>",
page
))
{
return Ok(vec![]);
}
let video_items: Vec<VideoItem> = self
@@ -233,11 +243,10 @@ impl JavtifulProvider {
return vec![];
}
let block = match html
.split("pagination ")
.next()
.and_then(|s| s.split("row row-cols-1 row-cols-sm-2 row-cols-lg-3 row-cols-xl-4").nth(1))
{
let block = match html.split("pagination ").next().and_then(|s| {
s.split("row row-cols-1 row-cols-sm-2 row-cols-lg-3 row-cols-xl-4")
.nth(1)
}) {
Some(b) => b,
None => {
eprint!("Javtiful Provider: Failed to get block from html");
@@ -250,9 +259,10 @@ impl JavtifulProvider {
file!(),
line!(),
module_path!(),
).await;
return vec![]
},
)
.await;
return vec![];
}
};
let futures = block
@@ -281,7 +291,8 @@ impl JavtifulProvider {
file!(), // Note: these might report the utility line
line!(), // better to hardcode or pass from outside
module_path!(),
).await;
)
.await;
});
}
})
@@ -289,11 +300,7 @@ impl JavtifulProvider {
.collect()
}
async fn get_video_item(
&self,
seg: String,
mut requester: Requester,
) -> Result<VideoItem> {
async fn get_video_item(&self, seg: String, mut requester: Requester) -> Result<VideoItem> {
let video_url = seg
.split(" href=\"")
.nth(1)
@@ -309,7 +316,10 @@ impl JavtifulProvider {
.trim()
.to_string();
title = decode(title.as_bytes()).to_string().unwrap_or(title).titlecase();
title = decode(title.as_bytes())
.to_string()
.unwrap_or(title)
.titlecase();
let id = video_url
.split('/')
.nth(5)
@@ -340,26 +350,17 @@ 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).await?;
let (tags, formats, views) = self.extract_media(&video_url, &mut requester).await?;
if preview.len() == 0 {
preview = format!("https://trailers.jav.si/preview/{id}.mp4");
}
let video_item = VideoItem::new(
id,
title,
video_url,
"javtiful".into(),
thumb,
duration,
)
.formats(formats)
.tags(tags)
.preview(preview)
.views(views);
let video_item = VideoItem::new(id, title, video_url, "javtiful".into(), thumb, duration)
.formats(formats)
.tags(tags)
.preview(preview)
.views(views);
Ok(video_item)
}
async fn extract_media(
@@ -371,7 +372,9 @@ impl JavtifulProvider {
.get(url, Some(Version::HTTP_2))
.await
.map_err(|e| Error::from(format!("{}", e)))?;
let tags = text.split("related-actress").next()
let tags = text
.split("related-actress")
.next()
.and_then(|s| s.split("video-comments").next())
.and_then(|s| s.split(">Tags<").nth(1))
.map(|tag_block| {
@@ -383,26 +386,34 @@ impl JavtifulProvider {
.split('>')
.nth(1)
.and_then(|s| s.split('<').next())
.map(|s| decode(s.as_bytes()).to_string().unwrap_or(s.to_string()).titlecase())
.map(|s| {
decode(s.as_bytes())
.to_string()
.unwrap_or(s.to_string())
.titlecase()
})
})
.collect()
})
.unwrap_or_else(|| vec![]);
for tag in &tags {
Self::push_unique(&self.categories, FilterOption {
id: tag.to_ascii_lowercase().replace(" ","+"),
title: tag.to_string(),
});
Self::push_unique(
&self.categories,
FilterOption {
id: tag.to_ascii_lowercase().replace(" ", "+"),
title: tag.to_string(),
},
);
}
let views = text.split(" Views ")
let views = text
.split(" Views ")
.next()
.and_then(|s| s.split(" ").last())
.and_then(|s| s.replace(".","")
.parse::<u32>().ok())
.and_then(|s| s.replace(".", "").parse::<u32>().ok())
.unwrap_or(0);
let quality="1080p".to_string();
let video_url = url.replace("javtiful.com","hottub.spacemoehre.de/proxy/javtiful");
let quality = "1080p".to_string();
let video_url = url.replace("javtiful.com", "hottub.spacemoehre.de/proxy/javtiful");
Ok((
tags,
vec![VideoFormat::new(video_url, quality, "video/mp4".into())],