37 lines
1.0 KiB
Rust
37 lines
1.0 KiB
Rust
use ntex::web;
|
|
|
|
use crate::util::requester::Requester;
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct NoodlemagazineProxy {
|
|
}
|
|
|
|
impl NoodlemagazineProxy {
|
|
pub fn new() -> Self {
|
|
NoodlemagazineProxy {
|
|
}
|
|
}
|
|
|
|
pub async fn get_video_url(
|
|
&self,
|
|
url: String,
|
|
requester: web::types::State<Requester>,
|
|
) -> String {
|
|
let mut requester = requester.get_ref().clone();
|
|
let url = "https://noodlemagazine.com/".to_string() + &url;
|
|
let text = requester.get(&url).await.unwrap_or("".to_string());
|
|
if text.is_empty() {
|
|
return "".to_string();
|
|
}
|
|
let json_str = text.split("window.playlist = ")
|
|
.collect::<Vec<&str>>()[1]
|
|
.split(";")
|
|
.collect::<Vec<&str>>()[0];
|
|
let json: serde_json::Value = serde_json::from_str(json_str).unwrap();
|
|
|
|
let sources = json["sources"].as_array().unwrap();
|
|
let video_url = sources[0]["file"].as_str().unwrap().to_string();
|
|
return video_url;
|
|
}
|
|
} |