javtiful fix

This commit is contained in:
Simon
2026-05-02 14:11:06 +00:00
parent 6a4fc98720
commit e4d409fe1f
2 changed files with 19 additions and 53 deletions

View File

@@ -81,20 +81,16 @@ impl JavtifulProvider {
colorName: "blue".to_string(),
options: vec![
FilterOption {
id: "newest".into(),
title: "Newest".into(),
id: "relevance".into(),
title: "Relevance".into(),
},
FilterOption {
id: "top rated".into(),
title: "Top Rated".into(),
id: "latest".into(),
title: "Latest".into(),
},
FilterOption {
id: "most viewed".into(),
title: "Most Viewed".into(),
},
FilterOption {
id: "top favorites".into(),
title: "Top Favorites".into(),
id: "popular".into(),
title: "Popular".into(),
},
],
multiSelect: false,
@@ -120,8 +116,8 @@ impl JavtifulProvider {
options: ServerOptions,
) -> Result<Vec<VideoItem>> {
let sort_string = match sort {
"top rated" => "/sort=top_rated",
"most viewed" => "/sort=most_viewed",
"latest" => "sort=latest&",
"popular" => "sort=popular&",
_ => "",
};
let video_url = format!("{}/videos{}?page={}", self.url, sort_string, page);
@@ -180,12 +176,12 @@ impl JavtifulProvider {
options: ServerOptions,
) -> Result<Vec<VideoItem>> {
let sort_string = match options.sort.as_deref().unwrap_or("") {
"top rated" => "/sort=top_rated",
"most viewed" => "/sort=most_viewed",
"latest" => "sort=latest&",
"popular" => "sort=popular&",
_ => "",
};
let video_url = format!(
"{}/search/videos{}?search_query={}&page={}",
"{}/search?{}q={}&page={}",
self.url,
sort_string,
query.replace(" ", "+"),

View File

@@ -1,5 +1,4 @@
use ntex::web;
use serde_json::Value;
use url::Url;
use wreq::Version;
@@ -66,37 +65,16 @@ impl JavtifulProxy {
&& parsed.path().starts_with("/video/")
}
fn extract_token(html: &str) -> Option<String> {
html.split("data-csrf-token=\"")
.nth(1)
.and_then(|value| value.split('"').next())
.map(|value| value.trim().to_string())
.filter(|value| !value.is_empty())
}
fn extract_playlist_url(payload: &str) -> Option<String> {
let json = serde_json::from_str::<Value>(payload).ok()?;
json.get("playlist")
.and_then(Value::as_str)
.or_else(|| json.get("playlists").and_then(Value::as_str))
.map(str::trim)
.map(ToOwned::to_owned)
.filter(|value| value.starts_with("https://"))
}
pub async fn get_video_url(
&self,
url: String,
requester: web::types::State<Requester>,
) -> String {
println!("JavtifulProxy: Getting video URL for {url}");
let mut requester = requester.get_ref().clone();
let Some((detail_url, video_id)) = Self::normalize_detail_request(&url) else {
let Some((detail_url, _)) = Self::normalize_detail_request(&url) else {
println!("JavtifulProxy: Invalid detail URL: {url}");
return String::new();
};
println!("Normalized detail URL: {detail_url}, video ID: {video_id}");
let html = requester.get(&detail_url, Some(Version::HTTP_11)).await;
let Ok(html) = html else {
return String::new();
@@ -104,15 +82,16 @@ impl JavtifulProxy {
if html.is_empty() {
return String::new();
}
println!("Fetched HTML content for {detail_url} (length: {})", html.len());
let media_url = format!("https://javtiful.com{}", html.split("playerSources\":[{\"src\":\"")
let mut media_url: String = html.split("playerSources\":[{\"src\":\"")
.nth(1)
.and_then(|s| s.split('"').next())
.map(str::trim)
.map(ToOwned::to_owned).unwrap_or_default());
println!("{media_url}");
media_url
.map(ToOwned::to_owned).unwrap_or_default().replace("\\u0026", "&");
media_url = match media_url.starts_with("/"){
true => format!("https://javtiful.com{media_url}"),
false => media_url
};
return media_url;
}
}
@@ -136,13 +115,4 @@ mod tests {
assert_eq!(url, "https://javtiful.com/video/1000/demo");
assert_eq!(video_id, "1000");
}
#[test]
fn extracts_playlist_from_payload() {
let payload = r#"{"status":"ok","playlist":"https://cdn.example/106796.mp4"}"#;
assert_eq!(
JavtifulProxy::extract_playlist_url(payload).as_deref(),
Some("https://cdn.example/106796.mp4")
);
}
}