From 3feeb022516f41d00e6ef71804eacdc88ee12ff2 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 9 Aug 2025 12:21:43 +0000 Subject: [PATCH] testing and fixing --- src/api.rs | 127 ++++++++++++++++++++++++----------- src/providers/all.rs | 44 ++++++++++++ src/providers/hanime.rs | 8 +-- src/providers/mod.rs | 42 ++++++------ src/providers/perverzija.rs | 7 +- src/providers/pmvhaven.rs | 8 +-- src/providers/pornhub.rs | 8 +-- src/providers/redtube.rs | 10 ++- src/providers/rule34video.rs | 8 +-- src/providers/spankbang.rs | 7 +- src/util/mod.rs | 22 ++++++ src/videos.rs | 9 +++ 12 files changed, 204 insertions(+), 96 deletions(-) create mode 100644 src/providers/all.rs diff --git a/src/api.rs b/src/api.rs index 7d94339..a0f768c 100644 --- a/src/api.rs +++ b/src/api.rs @@ -357,40 +357,39 @@ async fn status(req: HttpRequest) -> Result { }], nsfw: true, }); - status.add_channel(Channel { - id: "spankbang".to_string(), - name: "SpankBang".to_string(), - description: "Popular Porn Videos - SpankBang".to_string(), - premium: false, - favicon: "https://www.google.com/s2/favicons?sz=64&domain=spankbang.com".to_string(), - status: "active".to_string(), - categories: vec![], - options: vec![ChannelOption { - 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![ - FilterOption { - id: "trending_videos".to_string(), - title: "Trending".to_string(), - }, - FilterOption { - id: "new_videos".to_string(), - title: "New".to_string(), - }, - FilterOption { - id: "most_popular".to_string(), - title: "Popular".to_string(), - }, - ], - multiSelect: false, - }], - nsfw: true, - }); + // status.add_channel(Channel { + // id: "spankbang".to_string(), + // name: "SpankBang".to_string(), + // description: "Popular Porn Videos - SpankBang".to_string(), + // premium: false, + // favicon: "https://www.google.com/s2/favicons?sz=64&domain=spankbang.com".to_string(), + // status: "active".to_string(), + // categories: vec![], + // options: vec![ChannelOption { + // 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![ + // FilterOption { + // id: "trending_videos".to_string(), + // title: "Trending".to_string(), + // }, + // FilterOption { + // id: "new_videos".to_string(), + // title: "New".to_string(), + // }, + // FilterOption { + // id: "most_popular".to_string(), + // title: "Popular".to_string(), + // }, + // ], + // multiSelect: false, + // }], + // nsfw: true, + // }); - // pronhub status.add_channel(Channel { id: "rule34video".to_string(), name: "Rule34Video".to_string(), @@ -431,6 +430,52 @@ async fn status(req: HttpRequest) -> Result { }], nsfw: true, }); + +status.add_channel(Channel { + id: "all".to_string(), + name: "All".to_string(), + description: "Query from all sites of this Server".to_string(), + premium: false, + favicon: "https://hottub.spacemoehre.de/favicon".to_string(), + status: "active".to_string(), + categories: vec![], + options: vec![ChannelOption { + id: "sites".to_string(), + title: "Sites".to_string(), + description: "What Sites to use".to_string(), //"Sort the videos by Date or Name.".to_string(), + systemImage: "list.number".to_string(), + colorName: "green".to_string(), + options: vec![ + FilterOption { + id: "hanime".to_string(), + title: "Hanime".to_string(), + }, + FilterOption { + id: "perverzija".to_string(), + title: "Perverzija".to_string(), + }, + FilterOption { + id: "pmvhaven".to_string(), + title: "PMVHaven".to_string(), + }, + FilterOption { + id: "pornhub".to_string(), + title: "Pornhub".to_string(), + }, + FilterOption { + id: "redtube".to_string(), + title: "Redtube".to_string(), + }, + FilterOption { + id: "rule34video".to_string(), + title: "Rule34Video".to_string(), + }, + ], + multiSelect: true, + }], + nsfw: true, + }); + status.add_channel(Channel { id: "redtube".to_string(), name: "Redtube".to_string(), @@ -494,7 +539,12 @@ async fn videos_post( .as_deref() .unwrap_or("all") .to_string(); - + let sites = video_request + .sites + .as_deref() + .unwrap_or("") + .to_string(); + let options = ServerOptions { featured: Some(featured), category: Some(category), sites: Some(sites) }; let video_items = provider .get_videos( cache.get_ref().clone(), @@ -504,8 +554,7 @@ async fn videos_post( query.clone(), page.to_string(), perPage.to_string(), - featured.clone(), - category.clone(), + options.clone() ) .await; videos.items = video_items.clone(); @@ -524,8 +573,7 @@ async fn videos_post( let sort_clone = sort.clone(); let query_clone = query.clone(); let per_page_clone = perPage.to_string(); - let featured_clone = featured.clone(); - let category_clone = category.clone(); + let options_clone = options.clone(); task::spawn_local(async move { // if let AnyProvider::Spankbang(_) = provider_clone { // // Spankbang has a delay for the next page @@ -540,8 +588,7 @@ async fn videos_post( query_clone, next_page.to_string(), per_page_clone, - featured_clone, - category_clone, + options_clone ) .await; }); diff --git a/src/providers/all.rs b/src/providers/all.rs new file mode 100644 index 0000000..a31eb2d --- /dev/null +++ b/src/providers/all.rs @@ -0,0 +1,44 @@ +use std::vec; +use error_chain::error_chain; +use futures::future::join_all; +use serde_json::error::Category; +use wreq::Client; +use wreq_util::Emulation; +use crate::db; +use crate::providers::Provider; +use crate::util::cache::VideoCache; +use crate::videos::{self, ServerOptions, VideoItem}; +use crate::DbPool; + +error_chain! { + foreign_links { + Io(std::io::Error); + HttpRequest(wreq::Error); + } +} + + +#[derive(Debug, Clone)] +#[allow(dead_code)] +pub struct AllProvider { +} + +impl Provider for AllProvider { + async fn get_videos( + &self, + cache: VideoCache, + pool: DbPool, + _channel: String, + sort: String, + query: Option, + page: String, + per_page: String, + options: ServerOptions, + ) -> Vec { + let sites = options.sites.unwrap(); + + println!("{:?}", sites); + + return vec![]; + } +} diff --git a/src/providers/hanime.rs b/src/providers/hanime.rs index ee5fa89..a62ced2 100644 --- a/src/providers/hanime.rs +++ b/src/providers/hanime.rs @@ -7,7 +7,7 @@ use wreq_util::Emulation; use crate::db; use crate::providers::Provider; use crate::util::cache::VideoCache; -use crate::videos::{self, VideoItem}; +use crate::videos::{self, ServerOptions, VideoItem}; use crate::DbPool; error_chain! { @@ -264,11 +264,9 @@ impl Provider for HanimeProvider { query: Option, page: String, per_page: String, - featured: String, - category: String, + options: ServerOptions, ) -> Vec { - let _ = category; - let _ = featured; + let _ = options; let _ = per_page; let _ = sort; let videos: std::result::Result, Error> = match query { diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 57cf624..96d7112 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -1,9 +1,10 @@ use crate::{ providers::{ - hanime::HanimeProvider, perverzija::PerverzijaProvider, pmvhaven::PmvhavenProvider, pornhub::PornhubProvider, rule34video::Rule34videoProvider, spankbang::SpankbangProvider, redtube::RedtubeProvider, - }, util::cache::VideoCache, videos::VideoItem, DbPool + all::AllProvider, hanime::HanimeProvider, perverzija::PerverzijaProvider, pmvhaven::PmvhavenProvider, pornhub::PornhubProvider, redtube::RedtubeProvider, rule34video::Rule34videoProvider, spankbang::SpankbangProvider + }, util::cache::VideoCache, videos::{ServerOptions, VideoItem}, DbPool }; +pub mod all; pub mod hanime; pub mod perverzija; pub mod pmvhaven; @@ -22,13 +23,13 @@ pub trait Provider { query: Option, page: String, per_page: String, - featured: String, - category: String, + options: ServerOptions, ) -> Vec; } #[derive(Debug, Clone)] pub enum AnyProvider { + All(AllProvider), Perverzija(PerverzijaProvider), Hanime(HanimeProvider), Spankbang(SpankbangProvider), @@ -37,6 +38,7 @@ pub enum AnyProvider { Rule34video(Rule34videoProvider), Redtube(RedtubeProvider), // Assuming Redtube is similar to Rule34video } + impl Provider for AnyProvider { async fn get_videos( &self, @@ -47,12 +49,11 @@ impl Provider for AnyProvider { query: Option, page: String, per_page: String, - featured: String, - category: String, + options: ServerOptions ) -> Vec { println!( - "/api/videos: channel={:?}, sort={:?}, query={:?}, page={:?}, per_page={:?}, featured={:?}", - channel, sort, query, page, per_page, featured + "/api/videos: channel={:?}, sort={:?}, query={:?}, page={:?}", + channel, sort, query, page ); match self { AnyProvider::Perverzija(p) => { @@ -64,39 +65,36 @@ impl Provider for AnyProvider { query.clone(), page.clone(), per_page.clone(), - featured.clone(), - category.clone(), + options, ) .await } AnyProvider::Hanime(p) => { - p.get_videos(cache, pool, channel, sort, query, page, per_page, featured, - category.clone(),) + p.get_videos(cache, pool, channel, sort, query, page, per_page, options,) .await } AnyProvider::Spankbang(p) => { - p.get_videos(cache, pool, channel, sort, query, page, per_page, featured, - category.clone(),) + p.get_videos(cache, pool, channel, sort, query, page, per_page, options,) .await } AnyProvider::Pornhub(p) => { - p.get_videos(cache, pool, channel, sort, query, page, per_page, featured, - category.clone(),) + p.get_videos(cache, pool, channel, sort, query, page, per_page, options,) .await } AnyProvider::Pmvhaven(p) => { - p.get_videos(cache, pool, channel, sort, query, page, per_page, featured, - category.clone(),) + p.get_videos(cache, pool, channel, sort, query, page, per_page, options,) .await } AnyProvider::Rule34video(p) => { - p.get_videos(cache, pool, channel, sort, query, page, per_page, featured, - category.clone(),) + p.get_videos(cache, pool, channel, sort, query, page, per_page, options,) .await } AnyProvider::Redtube(p) => { - p.get_videos(cache, pool, channel, sort, query, page, per_page, featured, - category.clone(),) + p.get_videos(cache, pool, channel, sort, query, page, per_page, options,) + .await + } + AnyProvider::All(p) => { + p.get_videos(cache, pool, channel, sort, query, page, per_page, options,) .await } } diff --git a/src/providers/perverzija.rs b/src/providers/perverzija.rs index 17bed06..1b61ee2 100644 --- a/src/providers/perverzija.rs +++ b/src/providers/perverzija.rs @@ -14,6 +14,7 @@ use crate::schema::videos::url; use crate::util::cache::VideoCache; use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr}; use crate::util::time::parse_time_to_seconds; +use crate::videos::ServerOptions; use crate::videos::{self, VideoEmbed, VideoItem}; use crate::DbPool; @@ -550,15 +551,13 @@ impl Provider for PerverzijaProvider { query: Option, page: String, per_page: String, - featured: String, - category: String, + options: ServerOptions, ) -> Vec { - let _ = category; let _ = per_page; let _ = sort; let videos: std::result::Result, Error> = match query { Some(q) => self.query(cache, pool, page.parse::().unwrap_or(1), &q).await, - None => self.get(cache, pool, page.parse::().unwrap_or(1), featured).await, + None => self.get(cache, pool, page.parse::().unwrap_or(1), options.featured.unwrap()).await, }; match videos { Ok(v) => v, diff --git a/src/providers/pmvhaven.rs b/src/providers/pmvhaven.rs index 3354ff0..c61eaab 100644 --- a/src/providers/pmvhaven.rs +++ b/src/providers/pmvhaven.rs @@ -5,7 +5,7 @@ use crate::util::cache::VideoCache; use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr}; use crate::util::parse_abbreviated_number; use crate::util::time::parse_time_to_seconds; -use crate::videos::{VideoFormat, VideoItem}; +use crate::videos::{ServerOptions, VideoFormat, VideoItem}; use cute::c; use error_chain::error_chain; use htmlentity::entity::{ICodedDataTrait, decode}; @@ -424,16 +424,14 @@ impl Provider for PmvhavenProvider { query: Option, page: String, per_page: String, - featured: String, - category: String, + options: ServerOptions, ) -> Vec { let _ = per_page; - let _ = featured; // Ignored in this implementation let _ = pool; // Ignored in this implementation let videos: std::result::Result, Error> = match query { Some(q) => self.query(cache, page.parse::().unwrap_or(1), &q).await, None => { - self.get(cache, page.parse::().unwrap_or(1), category, sort) + self.get(cache, page.parse::().unwrap_or(1), options.category.unwrap(), sort) .await } }; diff --git a/src/providers/pornhub.rs b/src/providers/pornhub.rs index e805368..fecea48 100644 --- a/src/providers/pornhub.rs +++ b/src/providers/pornhub.rs @@ -5,7 +5,7 @@ use crate::providers::Provider; use crate::util::cache::VideoCache; use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr}; use crate::util::time::parse_time_to_seconds; -use crate::videos::{VideoItem}; +use crate::videos::{ServerOptions, VideoItem}; use error_chain::error_chain; use futures::stream::SplitSink; use htmlentity::entity::{ICodedDataTrait, decode}; @@ -331,12 +331,10 @@ impl Provider for PornhubProvider { query: Option, page: String, per_page: String, - featured: String, - category: String, + options: ServerOptions, ) -> Vec { - let _ = category; + let _ = options; let _ = per_page; - let _ = featured; // Ignored in this implementation let _ = pool; // Ignored in this implementation let mut sort = sort.to_lowercase(); if sort.contains("date"){ diff --git a/src/providers/redtube.rs b/src/providers/redtube.rs index c74850b..624ae8f 100644 --- a/src/providers/redtube.rs +++ b/src/providers/redtube.rs @@ -5,7 +5,7 @@ use crate::providers::Provider; use crate::util::cache::VideoCache; use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr}; use crate::util::time::parse_time_to_seconds; -use crate::videos::{VideoItem}; +use crate::videos::{ServerOptions, VideoItem}; use error_chain::error_chain; use futures::stream::SplitSink; use htmlentity::entity::{ICodedDataTrait, decode}; @@ -266,13 +266,11 @@ impl Provider for RedtubeProvider { query: Option, page: String, per_page: String, - featured: String, - category: String, + options: ServerOptions, ) -> Vec { - let _ = category; + let _ = options; let _ = per_page; - let _ = featured; // Ignored in this implementation - let _ = pool; // Ignored in this implementation + let _ = pool; let mut sort = sort.to_lowercase(); if sort.contains("date"){ sort = "mr".to_string(); diff --git a/src/providers/rule34video.rs b/src/providers/rule34video.rs index f77bddc..abc9470 100644 --- a/src/providers/rule34video.rs +++ b/src/providers/rule34video.rs @@ -4,7 +4,7 @@ use crate::providers::Provider; use crate::util::cache::VideoCache; use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr}; use crate::util::time::parse_time_to_seconds; -use crate::videos::{VideoItem}; +use crate::videos::{ServerOptions, VideoItem}; use error_chain::error_chain; use futures::stream::SplitSink; use htmlentity::entity::{ICodedDataTrait, decode}; @@ -292,12 +292,10 @@ impl Provider for Rule34videoProvider { query: Option, page: String, per_page: String, - featured: String, - category: String, + options: ServerOptions, ) -> Vec { - let _ = category; + let _ = options; let _ = per_page; - let _ = featured; // Ignored in this implementation let _ = pool; // Ignored in this implementation let videos: std::result::Result, Error> = match query { Some(q) => { diff --git a/src/providers/spankbang.rs b/src/providers/spankbang.rs index 212f20a..c72e91f 100644 --- a/src/providers/spankbang.rs +++ b/src/providers/spankbang.rs @@ -7,6 +7,7 @@ use crate::db; use crate::providers::Provider; use crate::util::cache::VideoCache; use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr}; +use crate::videos::ServerOptions; use crate::videos::{VideoItem}; use crate::DbPool; use std::collections::HashMap; @@ -357,12 +358,10 @@ impl Provider for SpankbangProvider { query: Option, page: String, per_page: String, - featured: String, - category: String, + options: ServerOptions, ) -> Vec { - let _ = category; + let _ = options; let _ = per_page; - let _ = featured; let _ = pool; if sort == "date"{ diff --git a/src/util/mod.rs b/src/util/mod.rs index 8684934..1a01180 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -18,4 +18,26 @@ pub fn parse_abbreviated_number(s: &str) -> Option { _ => return None, }; num_part.parse::().ok().map(|n| (n * multiplier) as u32) +} + +pub fn interleave(lists: &[Vec]) -> Vec { + let mut result = Vec::new(); + + if lists.is_empty() { + return result; + } + + // Find the maximum length among the lists + let max_len = lists.iter().map(|l| l.len()).max().unwrap_or(0); + + // Interleave elements + for i in 0..max_len { + for list in lists { + if let Some(item) = list.get(i) { + result.push(item.clone()); + } + } + } + + result } \ No newline at end of file diff --git a/src/videos.rs b/src/videos.rs index c80bd16..f7faa78 100644 --- a/src/videos.rs +++ b/src/videos.rs @@ -27,7 +27,16 @@ pub struct VideosRequest { // pub flavor: "mint chocolate chip" pub featured: Option, // "featured", pub category: Option, // "pmv" + pub sites: Option, // } + +#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +pub struct ServerOptions{ + pub featured: Option, // "featured", + pub category: Option, // "pmv" + pub sites: Option, // +} + #[derive(serde::Serialize, Debug)] pub struct PageInfo { pub hasNextPage: bool, // true,