javtiful fix
This commit is contained in:
@@ -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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user