diff --git a/src/api.rs b/src/api.rs index 9078ddf..86afb38 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,10 +1,10 @@ +use capitalize::Capitalize; use ntex::http::header; use ntex::web; use ntex::web::HttpRequest; use std::cmp::Ordering; use std::fs; use tokio::task; -use capitalize::Capitalize; use crate::providers::all::AllProvider; use crate::providers::hanime::HanimeProvider; @@ -17,7 +17,7 @@ use crate::providers::rule34video::Rule34videoProvider; // use crate::providers::spankbang::SpankbangProvider; use crate::util::cache::VideoCache; use crate::util::requester::Requester; -use crate::{db, providers::*, status::*, videos::*, DbPool}; +use crate::{DbPool, db, providers::*, status::*, videos::*}; use cute::c; #[derive(Debug)] @@ -123,7 +123,7 @@ async fn status(req: HttpRequest) -> Result { .unwrap_or_default() .to_string(); let mut status = Status::new(); - + // pronhub status.add_channel(Channel { id: "pornhub".to_string(), @@ -160,6 +160,7 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); if clientversion >= ClientVersion::new(22, 101, "22e".to_string()) { // pmvhaven @@ -171,67 +172,70 @@ async fn status(req: HttpRequest) -> Result { favicon: "https://www.google.com/s2/favicons?sz=64&domain=pmvhaven.com".to_string(), status: "active".to_string(), categories: vec![], - options: vec![ChannelOption { - id: "category".to_string(), - title: "Category".to_string(), - description: "Category of PMV Video get".to_string(), //"Sort the videos by Date or Name.".to_string(), - systemImage: "folder".to_string(), - colorName: "yellow".to_string(), - options: vec![ - FilterOption { - id: "all".to_string(), - title: "All".to_string(), - }, - FilterOption { - id: "pmv".to_string(), - title: "PMV".to_string(), - }, - FilterOption { - id: "hmv".to_string(), - title: "HMV".to_string(), - }, - FilterOption { - id: "tiktok".to_string(), - title: "Tiktok".to_string(), - }, - FilterOption { - id: "koreanbj".to_string(), - title: "KoreanBJ".to_string(), - }, - FilterOption { - id: "hypno".to_string(), - title: "Hypno".to_string(), - }, - FilterOption { - id: "other".to_string(), - title: "Other".to_string(), - }, - ], - multiSelect: false, - }, - ChannelOption { - id: "sort".to_string(), - title: "Filter".to_string(), - description: "Filter PMV Videos".to_string(), - systemImage: "list.number".to_string(), - colorName: "blue".to_string(), - options: vec![ - FilterOption { - id: "Newest".to_string(), - title: "Newest".to_string(), - }, - FilterOption { - id: "Top Rated".to_string(), - title: "Top Rated".to_string(), - }, - FilterOption { - id: "Most Viewed".to_string(), - title: "Most Viewed".to_string(), - } - ], - multiSelect: false, - }], + options: vec![ + ChannelOption { + id: "category".to_string(), + title: "Category".to_string(), + description: "Category of PMV Video get".to_string(), //"Sort the videos by Date or Name.".to_string(), + systemImage: "folder".to_string(), + colorName: "yellow".to_string(), + options: vec![ + FilterOption { + id: "all".to_string(), + title: "All".to_string(), + }, + FilterOption { + id: "pmv".to_string(), + title: "PMV".to_string(), + }, + FilterOption { + id: "hmv".to_string(), + title: "HMV".to_string(), + }, + FilterOption { + id: "tiktok".to_string(), + title: "Tiktok".to_string(), + }, + FilterOption { + id: "koreanbj".to_string(), + title: "KoreanBJ".to_string(), + }, + FilterOption { + id: "hypno".to_string(), + title: "Hypno".to_string(), + }, + FilterOption { + id: "other".to_string(), + title: "Other".to_string(), + }, + ], + multiSelect: false, + }, + ChannelOption { + id: "sort".to_string(), + title: "Filter".to_string(), + description: "Filter PMV Videos".to_string(), + systemImage: "list.number".to_string(), + colorName: "blue".to_string(), + options: vec![ + FilterOption { + id: "Newest".to_string(), + title: "Newest".to_string(), + }, + FilterOption { + id: "Top Rated".to_string(), + title: "Top Rated".to_string(), + }, + FilterOption { + id: "Most Viewed".to_string(), + title: "Most Viewed".to_string(), + }, + ], + multiSelect: false, + }, + ], nsfw: true, + cacheDuration: 1800, }); } if clientversion >= ClientVersion::new(22, 97, "22a".to_string()) { @@ -302,6 +306,7 @@ async fn status(req: HttpRequest) -> Result { // }, ], nsfw: true, + cacheDuration: 1800, }); } @@ -364,6 +369,7 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); // status.add_channel(Channel { @@ -397,8 +403,9 @@ async fn status(req: HttpRequest) -> Result { // multiSelect: false, // }], // nsfw: true, + //cacheDuration: 1800, // }); - + status.add_channel(Channel { id: "rule34video".to_string(), name: "Rule34Video".to_string(), @@ -438,12 +445,16 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); let files = fs::read_dir("./src/providers").unwrap(); - let providers = files.map(|entry| entry.unwrap().file_name()) + let providers = files + .map(|entry| entry.unwrap().file_name()) .filter(|name| name.to_str().unwrap().ends_with(".rs")) - .filter(|name| !name.to_str().unwrap().contains("mod.rs") && !name.to_str().unwrap().contains("all.rs")) + .filter(|name| { + !name.to_str().unwrap().contains("mod.rs") && !name.to_str().unwrap().contains("all.rs") + }) .map(|name| name.to_str().unwrap().replace(".rs", "")) .collect::>(); let sites = c![FilterOption { @@ -470,6 +481,7 @@ async fn status(req: HttpRequest) -> Result { multiSelect: true, }], nsfw: true, + cacheDuration: 1800, }); // Redtube @@ -483,6 +495,7 @@ async fn status(req: HttpRequest) -> Result { categories: vec![], options: vec![], nsfw: true, + cacheDuration: 1800, }); // ok.porn @@ -517,6 +530,7 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); // pornhat @@ -551,6 +565,7 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); //perfectgirls @@ -585,8 +600,9 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); - + // okxxx status.add_channel(Channel { id: "okxxx".to_string(), @@ -619,6 +635,7 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); // homoxxx @@ -653,6 +670,7 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); // // hentaimoon @@ -687,9 +705,10 @@ async fn status(req: HttpRequest) -> Result { // multiSelect: false, // }], // nsfw: true, + // cacheDuration: 1800, // }); - // xxthots + // xxthots status.add_channel(Channel { id: "xxthots".to_string(), name: "XXTHOTS".to_string(), @@ -721,6 +740,7 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); // porn00 @@ -755,6 +775,7 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); // freshporno @@ -789,9 +810,10 @@ async fn status(req: HttpRequest) -> Result { multiSelect: false, }], nsfw: true, + cacheDuration: 1800, }); - // porn00 + // porn00 // status.add_channel(Channel { // id: "noodlemagazine".to_string(), // name: "Noodlemagazine".to_string(), @@ -802,6 +824,7 @@ async fn status(req: HttpRequest) -> Result { // categories: vec![], // options: vec![], // nsfw: true, + // cacheDuration: 1800, // }); //missav @@ -846,9 +869,9 @@ async fn status(req: HttpRequest) -> Result { title: "Total Views".to_string(), }, ], - multiSelect: false, - }, - ChannelOption { + multiSelect: false, + }, + ChannelOption { id: "filter".to_string(), title: "Filter".to_string(), description: "Filter the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(), @@ -872,9 +895,9 @@ async fn status(req: HttpRequest) -> Result { title: "English subtitle".to_string(), }, ], - multiSelect: false, - }, - ChannelOption { + multiSelect: false, + }, + ChannelOption { id: "language".to_string(), title: "Language".to_string(), description: "What Language to fetch".to_string(), //"Sort the videos by Date or Name.".to_string(), @@ -930,10 +953,11 @@ async fn status(req: HttpRequest) -> Result { title: "Português".to_string(), }, ], - multiSelect: false, - } + multiSelect: false, + }, ], nsfw: true, + cacheDuration: 1800, }); //sxyprn @@ -970,9 +994,9 @@ async fn status(req: HttpRequest) -> Result { title: "Orgasmic".to_string(), }, ], - multiSelect: false, - }, - ChannelOption { + multiSelect: false, + }, + ChannelOption { id: "filter".to_string(), title: "Filter".to_string(), description: "Filter the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(), @@ -992,10 +1016,11 @@ async fn status(req: HttpRequest) -> Result { title: "All".to_string(), }, ], - multiSelect: false, - }, + multiSelect: false, + }, ], nsfw: true, + cacheDuration: 1800, }); status.iconUrl = format!("http://{}/favicon.ico", host).to_string(); @@ -1011,8 +1036,11 @@ async fn videos_post( let requester = requester.get_ref().clone(); let mut conn = pool.get().expect("couldn't get db connection from pool"); // Ensure "videos" table exists with two string columns - if !(db::has_table(&mut conn, "videos").unwrap()){ - let _ = db::create_table(&mut conn, "CREATE TABLE videos (id TEXT NOT NULL, url TEXT NOT NULL);"); + if !(db::has_table(&mut conn, "videos").unwrap()) { + let _ = db::create_table( + &mut conn, + "CREATE TABLE videos (id TEXT NOT NULL, url TEXT NOT NULL);", + ); } let mut videos = Videos { @@ -1058,22 +1086,21 @@ async fn videos_post( .as_deref() .unwrap_or("all") .to_string(); - let sites = video_request - .sites - .as_deref() - .unwrap_or("") - .to_string(); - let filter = video_request - .filter - .as_deref() - .unwrap_or("new") - .to_string(); + let sites = video_request.sites.as_deref().unwrap_or("").to_string(); + let filter = video_request.filter.as_deref().unwrap_or("new").to_string(); let language = video_request .language .as_deref() .unwrap_or("en") .to_string(); - let options = ServerOptions { featured: Some(featured), category: Some(category), sites: Some(sites), filter: Some(filter), language: Some(language), requester: Some(requester) }; + let options = ServerOptions { + featured: Some(featured), + category: Some(category), + sites: Some(sites), + filter: Some(filter), + language: Some(language), + requester: Some(requester), + }; let video_items = provider .get_videos( cache.get_ref().clone(), @@ -1082,7 +1109,7 @@ async fn videos_post( query.clone(), page.to_string(), perPage.to_string(), - options.clone() + options.clone(), ) .await; videos.items = video_items.clone(); @@ -1114,7 +1141,7 @@ async fn videos_post( query_clone, next_page.to_string(), per_page_clone, - options_clone + options_clone, ) .await; }); @@ -1133,17 +1160,35 @@ pub fn get_provider(channel: &str) -> Option { "rule34video" => Some(AnyProvider::Rule34video(Rule34videoProvider::new())), "redtube" => Some(AnyProvider::Redtube(RedtubeProvider::new())), "okporn" => Some(AnyProvider::Okporn(OkpornProvider::new())), - "pornhat" => Some(AnyProvider::Pornhat(crate::providers::pornhat::PornhatProvider::new())), - "perfectgirls" => Some(AnyProvider::Perfectgirls(crate::providers::perfectgirls::PerfectgirlsProvider::new())), - "okxxx" => Some(AnyProvider::Okxxx(crate::providers::okxxx::OkxxxProvider::new())), - "homoxxx" => Some(AnyProvider::Homoxxx(crate::providers::homoxxx::HomoxxxProvider::new())), + "pornhat" => Some(AnyProvider::Pornhat( + crate::providers::pornhat::PornhatProvider::new(), + )), + "perfectgirls" => Some(AnyProvider::Perfectgirls( + crate::providers::perfectgirls::PerfectgirlsProvider::new(), + )), + "okxxx" => Some(AnyProvider::Okxxx( + crate::providers::okxxx::OkxxxProvider::new(), + )), + "homoxxx" => Some(AnyProvider::Homoxxx( + crate::providers::homoxxx::HomoxxxProvider::new(), + )), // "hentaimoon" => Some(AnyProvider::Hentaimoon(crate::providers::hentaimoon::HentaimoonProvider::new())), - "missav" => Some(AnyProvider::Missav(crate::providers::missav::MissavProvider::new())), - "xxthots" => Some(AnyProvider::Xxthots(crate::providers::xxthots::XxthotsProvider::new())), - "sxyprn" => Some(AnyProvider::Sxyprn(crate::providers::sxyprn::SxyprnProvider::new())), - "porn00" => Some(AnyProvider::Porn00(crate::providers::porn00::Porn00Provider::new())), + "missav" => Some(AnyProvider::Missav( + crate::providers::missav::MissavProvider::new(), + )), + "xxthots" => Some(AnyProvider::Xxthots( + crate::providers::xxthots::XxthotsProvider::new(), + )), + "sxyprn" => Some(AnyProvider::Sxyprn( + crate::providers::sxyprn::SxyprnProvider::new(), + )), + "porn00" => Some(AnyProvider::Porn00( + crate::providers::porn00::Porn00Provider::new(), + )), // "noodlemagazine" => Some(AnyProvider::Noodlemagazine(crate::providers::noodlemagazine::NoodlemagazineProvider::new())), - "freshporno" => Some(AnyProvider::Freshporno(crate::providers::freshporno::FreshpornoProvider::new())), + "freshporno" => Some(AnyProvider::Freshporno( + crate::providers::freshporno::FreshpornoProvider::new(), + )), _ => Some(AnyProvider::Perverzija(PerverzijaProvider::new())), } } diff --git a/src/status.rs b/src/status.rs index 8782933..558a6c0 100644 --- a/src/status.rs +++ b/src/status.rs @@ -18,6 +18,7 @@ pub struct Channel { pub categories: Vec, //[], pub options: Vec, pub nsfw: bool, //true + pub cacheDuration: u32, //Some(86400) } #[derive(serde::Serialize)]