init
This commit is contained in:
274
src/api.rs
Normal file
274
src/api.rs
Normal file
@@ -0,0 +1,274 @@
|
||||
use htmlentity::entity::decode;
|
||||
use htmlentity::entity::ICodedDataTrait;
|
||||
use ntex::http::header;
|
||||
use ntex::util::Buf;
|
||||
use ntex::web;
|
||||
use ntex::web::HttpRequest;
|
||||
use ntex::web::HttpResponse;
|
||||
use serde_json::json;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::providers::perverzija::PerverzijaProvider;
|
||||
use crate::{providers::*, status::*, videos::*};
|
||||
|
||||
// this function could be located in a different module
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
web::resource("/status")
|
||||
.route(web::post().to(status))
|
||||
.route(web::get().to(status)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/videos")
|
||||
// .route(web::get().to(videos_get))
|
||||
.route(web::post().to(videos_post)),
|
||||
);
|
||||
}
|
||||
|
||||
async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
let host = req
|
||||
.headers()
|
||||
.get(header::HOST)
|
||||
.and_then(|h| h.to_str().ok())
|
||||
.unwrap_or_default()
|
||||
.to_string();
|
||||
let mut status = Status::new();
|
||||
|
||||
// You can now use `method`, `host`, and `port` as needed
|
||||
|
||||
status.add_channel(Channel {
|
||||
id: "all".to_string(),
|
||||
name: "SpaceMoehre's Hottub".to_string(),
|
||||
favicon: format!("http://{}/static/favicon.ico", host).to_string(),
|
||||
premium: false,
|
||||
description: "Work in Progress".to_string(),
|
||||
status: "active".to_string(),
|
||||
categories: vec![],
|
||||
options: vec![
|
||||
Channel_Option {
|
||||
id: "channels".to_string(),
|
||||
title: "Sites".to_string(),
|
||||
description: "Websites included in search results.".to_string(),
|
||||
systemImage: "network".to_string(),
|
||||
colorName: "purple".to_string(),
|
||||
options: vec![
|
||||
Filter_Option {
|
||||
id: "perverzija".to_string(),
|
||||
title: "Perverzija".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: true,
|
||||
},
|
||||
Channel_Option {
|
||||
id: "sort".to_string(),
|
||||
title: "Sort".to_string(),
|
||||
description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
||||
systemImage: "list.number".to_string(),
|
||||
colorName: "blue".to_string(),
|
||||
options: vec![
|
||||
Filter_Option {
|
||||
id: "date".to_string(),
|
||||
title: "Date".to_string(),
|
||||
},
|
||||
Filter_Option {
|
||||
id: "name".to_string(),
|
||||
title: "Name".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
},
|
||||
Channel_Option {
|
||||
id: "duration".to_string(),
|
||||
title: "Duration".to_string(),
|
||||
description: "Filter the videos by duration.".to_string(),
|
||||
systemImage: "timer".to_string(),
|
||||
colorName: "green".to_string(),
|
||||
options: vec![
|
||||
Filter_Option {
|
||||
id: "short".to_string(),
|
||||
title: "< 1h".to_string(),
|
||||
},
|
||||
Filter_Option {
|
||||
id: "long".to_string(),
|
||||
title: "> 1h".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: true,
|
||||
},
|
||||
Channel_Option {
|
||||
id: "featured".to_string(),
|
||||
title: "Featured".to_string(),
|
||||
description: "Filter Featured Videos.".to_string(),
|
||||
systemImage: "star".to_string(),
|
||||
colorName: "red".to_string(),
|
||||
options: vec![
|
||||
Filter_Option {
|
||||
id: "all".to_string(),
|
||||
title: "No".to_string(),
|
||||
},
|
||||
Filter_Option {
|
||||
id: "featured".to_string(),
|
||||
title: "Yes".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
},
|
||||
],
|
||||
nsfw: true,
|
||||
});
|
||||
status.add_channel(Channel {
|
||||
id: "perverzija".to_string(),
|
||||
name: "Perverzija".to_string(),
|
||||
description: "Free videos from Perverzija".to_string(),
|
||||
premium: false,
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=tube.perverzija.com".to_string(),
|
||||
status: "active".to_string(),
|
||||
categories: vec![],
|
||||
options: vec![
|
||||
Channel_Option {
|
||||
id: "sort".to_string(),
|
||||
title: "Sort".to_string(),
|
||||
description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
||||
systemImage: "list.number".to_string(),
|
||||
colorName: "blue".to_string(),
|
||||
options: vec![
|
||||
Filter_Option {
|
||||
id: "date".to_string(),
|
||||
title: "Date".to_string(),
|
||||
},
|
||||
Filter_Option {
|
||||
id: "name".to_string(),
|
||||
title: "Name".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
},
|
||||
Channel_Option {
|
||||
id: "duration".to_string(),
|
||||
title: "Duration".to_string(),
|
||||
description: "Filter the videos by duration.".to_string(),
|
||||
systemImage: "timer".to_string(),
|
||||
colorName: "green".to_string(),
|
||||
options: vec![
|
||||
Filter_Option {
|
||||
id: "short".to_string(),
|
||||
title: "< 1h".to_string(),
|
||||
},
|
||||
Filter_Option {
|
||||
id: "long".to_string(),
|
||||
title: "> 1h".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: true,
|
||||
},
|
||||
],
|
||||
nsfw: true,
|
||||
});
|
||||
status.iconUrl = format!("http://{}/favicon.ico", host).to_string();
|
||||
Ok(web::HttpResponse::Ok().json(&status))
|
||||
}
|
||||
|
||||
async fn videos_post(
|
||||
video_request: web::types::Json<Videos_Request>,
|
||||
) -> Result<impl web::Responder, web::Error> {
|
||||
let mut format = Video_Format::new(
|
||||
"https://pervl2.xtremestream.xyz/player/xs1.php?data=794a51bb65913debd98f73111705738a"
|
||||
.to_string(),
|
||||
"1080p".to_string(),
|
||||
"m3u8".to_string(),
|
||||
);
|
||||
format.add_http_header(
|
||||
"Referer".to_string(),
|
||||
"https://pervl2.xtremestream.xyz/player/index.php?data=794a51bb65913debd98f73111705738a"
|
||||
.to_string(),
|
||||
);
|
||||
let mut videos = Videos {
|
||||
pageInfo: PageInfo {
|
||||
hasNextPage: true,
|
||||
resultsPerPage: 10,
|
||||
},
|
||||
items: vec![],
|
||||
};
|
||||
let channel: String = video_request
|
||||
.channel
|
||||
.as_deref()
|
||||
.unwrap_or("all")
|
||||
.to_string();
|
||||
let sort: String = video_request.sort.as_deref().unwrap_or("date").to_string();
|
||||
let mut query: Option<String> = video_request.query.clone();
|
||||
if video_request.query.as_deref() == Some("") {
|
||||
query = None;
|
||||
}
|
||||
let page: u8 = video_request
|
||||
.page
|
||||
.as_deref()
|
||||
.unwrap_or("1")
|
||||
.to_string()
|
||||
.parse()
|
||||
.unwrap();
|
||||
let perPage: u8 = video_request
|
||||
.perPage
|
||||
.as_deref()
|
||||
.unwrap_or("10")
|
||||
.to_string()
|
||||
.parse()
|
||||
.unwrap();
|
||||
let featured = video_request.featured.as_deref().unwrap_or("all").to_string();
|
||||
let provider = PerverzijaProvider::new();
|
||||
let video_items = provider
|
||||
.get_videos(channel, sort, query, page.to_string(), perPage.to_string(), featured)
|
||||
.await;
|
||||
videos.items = video_items.clone();
|
||||
Ok(web::HttpResponse::Ok().json(&videos))
|
||||
}
|
||||
|
||||
// async fn videos_get(_req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
// let mut http_headers: HashMap<String, String> = HashMap::new();
|
||||
// // http_headers.insert(
|
||||
// // "Referer".to_string(),
|
||||
// // "https://pervl2.xtremestream.xyz/player/index.php?data=794a51bb65913debd98f73111705738a"
|
||||
// // .to_string(),
|
||||
// // );
|
||||
// let mut format = Video_Format::new(
|
||||
// "https://pervl2.xtremestream.xyz/player/xs1.php?data=794a51bb65913debd98f73111705738a"
|
||||
// .to_string(),
|
||||
// "1080p".to_string(),
|
||||
// "m3u8".to_string(),
|
||||
// );
|
||||
// format.add_http_header(
|
||||
// "Referer".to_string(),
|
||||
// "https://pervl2.xtremestream.xyz/player/index.php?data=794a51bb65913debd98f73111705738a"
|
||||
// .to_string(),
|
||||
// );
|
||||
// let videos = Videos {
|
||||
// pageInfo: PageInfo {
|
||||
// hasNextPage: true,
|
||||
// resultsPerPage: 10,
|
||||
// },
|
||||
// items: vec![
|
||||
// Video_Item{
|
||||
// duration: 110, // 110,
|
||||
// views: Some(14622653), // 14622653,
|
||||
// rating: Some(0.0), // 0.0,
|
||||
// id: "794a51bb65913debd98f73111705738a".to_string(), // "c85017ca87477168d648727753c4ded8a35f173e22ef93743e707b296becb299",
|
||||
// title: "BrazzersExxtra – Give Me A D! The Best Of Cheerleaders".to_string(), // "20 Minutes of Adorable Kittens BEST Compilation",
|
||||
// // url: "https://tube.perverzija.com/brazzersexxtra-give-me-a-d-the-best-of-cheerleaders/".to_string(),
|
||||
// // url : "https://pervl2.xtremestream.xyz/player/xs1.php?data=794a51bb65913debd98f73111705738a".to_string(), // "https://www.youtube.com/watch?v=y0sF5xhGreA",
|
||||
// url : "https://pervl2.xtremestream.xyz/player/index.php?data=794a51bb65913debd98f73111705738a".to_string(),
|
||||
// channel: "perverzija".to_string(), // "youtube",
|
||||
// thumb: "https://tube.perverzija.com/wp-content/uploads/2025/05/BrazzersExxtra-Give-Me-A-D-The-Best-Of-Cheerleaders.jpg".to_string(), // "https://i.ytimg.com/vi/y0sF5xhGreA/hqdefault.jpg",
|
||||
// uploader: Some("Brazzers".to_string()), // "The Pet Collective",
|
||||
// uploaderUrl: Some("https://brazzers.com".to_string()), // "https://www.youtube.com/@petcollective",
|
||||
// verified: Some(false), // false,
|
||||
// tags: Some(vec![]), // [],
|
||||
// uploadedAt: Some(1741142954), // 1741142954
|
||||
// formats: Some(vec![format]), // Additional HTTP headers if needed
|
||||
|
||||
// }
|
||||
// ],
|
||||
// };
|
||||
|
||||
// println!("Video: {:?}", videos);
|
||||
// Ok(web::HttpResponse::Ok().json(&videos))
|
||||
// }
|
||||
Reference in New Issue
Block a user