70 lines
2.1 KiB
Rust
70 lines
2.1 KiB
Rust
use ntex::web;
|
|
use wreq::Version;
|
|
|
|
use crate::util::requester::Requester;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct JavtifulProxy {}
|
|
|
|
impl JavtifulProxy {
|
|
pub fn new() -> Self {
|
|
JavtifulProxy {}
|
|
}
|
|
|
|
pub async fn get_video_url(
|
|
&self,
|
|
url: String,
|
|
requester: web::types::State<Requester>,
|
|
) -> String {
|
|
let mut requester = requester.get_ref().clone();
|
|
let endpoint = url
|
|
.trim_start_matches('/')
|
|
.strip_prefix("https://")
|
|
.or_else(|| url.trim_start_matches('/').strip_prefix("http://"))
|
|
.unwrap_or(url.trim_start_matches('/'))
|
|
.trim_start_matches("www.javtiful.com/")
|
|
.trim_start_matches("javtiful.com/")
|
|
.trim_start_matches('/')
|
|
.to_string();
|
|
let detail_url = format!("https://javtiful.com/{endpoint}");
|
|
let text = requester.get(&detail_url, None).await.unwrap_or_default();
|
|
if text.is_empty() {
|
|
return "".to_string();
|
|
}
|
|
let video_id = endpoint.split('/').nth(1).unwrap_or("").to_string();
|
|
|
|
let token = text
|
|
.split("data-csrf-token=\"")
|
|
.nth(1)
|
|
.and_then(|s| s.split('"').next())
|
|
.unwrap_or("")
|
|
.to_string();
|
|
|
|
let form = wreq::multipart::Form::new()
|
|
.text("video_id", video_id.clone())
|
|
.text("pid_c", "".to_string())
|
|
.text("token", token.clone());
|
|
let resp = match requester
|
|
.post_multipart(
|
|
"https://javtiful.com/ajax/get_cdn",
|
|
form,
|
|
vec![("Referer".to_string(), detail_url)],
|
|
Some(Version::HTTP_11),
|
|
)
|
|
.await
|
|
{
|
|
Ok(r) => r,
|
|
Err(_) => return "".to_string(),
|
|
};
|
|
let text = resp.text().await.unwrap_or_default();
|
|
let json: serde_json::Value =
|
|
serde_json::from_str(&text).unwrap_or(serde_json::Value::Null);
|
|
let video_url = json
|
|
.get("playlists")
|
|
.map(|v| v.to_string().replace("\"", ""))
|
|
.unwrap_or_default();
|
|
|
|
return video_url;
|
|
}
|
|
}
|