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

View File

@@ -1,5 +1,4 @@
use ntex::web; use ntex::web;
use serde_json::Value;
use url::Url; use url::Url;
use wreq::Version; use wreq::Version;
@@ -66,37 +65,16 @@ impl JavtifulProxy {
&& parsed.path().starts_with("/video/") && 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( pub async fn get_video_url(
&self, &self,
url: String, url: String,
requester: web::types::State<Requester>, requester: web::types::State<Requester>,
) -> String { ) -> String {
println!("JavtifulProxy: Getting video URL for {url}");
let mut requester = requester.get_ref().clone(); 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}"); println!("JavtifulProxy: Invalid detail URL: {url}");
return String::new(); 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 html = requester.get(&detail_url, Some(Version::HTTP_11)).await;
let Ok(html) = html else { let Ok(html) = html else {
return String::new(); return String::new();
@@ -104,15 +82,16 @@ impl JavtifulProxy {
if html.is_empty() { if html.is_empty() {
return String::new(); return String::new();
} }
println!("Fetched HTML content for {detail_url} (length: {})", html.len()); let mut media_url: String = html.split("playerSources\":[{\"src\":\"")
let media_url = format!("https://javtiful.com{}", html.split("playerSources\":[{\"src\":\"")
.nth(1) .nth(1)
.and_then(|s| s.split('"').next()) .and_then(|s| s.split('"').next())
.map(str::trim) .map(str::trim)
.map(ToOwned::to_owned).unwrap_or_default()); .map(ToOwned::to_owned).unwrap_or_default().replace("\\u0026", "&");
println!("{media_url}"); media_url = match media_url.starts_with("/"){
media_url 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!(url, "https://javtiful.com/video/1000/demo");
assert_eq!(video_id, "1000"); 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")
);
}
} }