testing and fixing
This commit is contained in:
127
src/api.rs
127
src/api.rs
@@ -357,40 +357,39 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
}],
|
||||
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<impl web::Responder, web::Error> {
|
||||
}],
|
||||
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;
|
||||
});
|
||||
|
||||
44
src/providers/all.rs
Normal file
44
src/providers/all.rs
Normal file
@@ -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<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let sites = options.sites.unwrap();
|
||||
|
||||
println!("{:?}", sites);
|
||||
|
||||
return vec![];
|
||||
}
|
||||
}
|
||||
@@ -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<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
featured: String,
|
||||
category: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let _ = category;
|
||||
let _ = featured;
|
||||
let _ = options;
|
||||
let _ = per_page;
|
||||
let _ = sort;
|
||||
let videos: std::result::Result<Vec<VideoItem>, Error> = match query {
|
||||
|
||||
@@ -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<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
featured: String,
|
||||
category: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem>;
|
||||
}
|
||||
|
||||
#[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<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
featured: String,
|
||||
category: String,
|
||||
options: ServerOptions
|
||||
) -> Vec<VideoItem> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
featured: String,
|
||||
category: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let _ = category;
|
||||
let _ = per_page;
|
||||
let _ = sort;
|
||||
let videos: std::result::Result<Vec<VideoItem>, Error> = match query {
|
||||
Some(q) => self.query(cache, pool, page.parse::<u8>().unwrap_or(1), &q).await,
|
||||
None => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), featured).await,
|
||||
None => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), options.featured.unwrap()).await,
|
||||
};
|
||||
match videos {
|
||||
Ok(v) => v,
|
||||
|
||||
@@ -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<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
featured: String,
|
||||
category: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let _ = per_page;
|
||||
let _ = featured; // Ignored in this implementation
|
||||
let _ = pool; // Ignored in this implementation
|
||||
let videos: std::result::Result<Vec<VideoItem>, Error> = match query {
|
||||
Some(q) => self.query(cache, page.parse::<u8>().unwrap_or(1), &q).await,
|
||||
None => {
|
||||
self.get(cache, page.parse::<u8>().unwrap_or(1), category, sort)
|
||||
self.get(cache, page.parse::<u8>().unwrap_or(1), options.category.unwrap(), sort)
|
||||
.await
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
featured: String,
|
||||
category: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
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"){
|
||||
|
||||
@@ -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<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
featured: String,
|
||||
category: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
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();
|
||||
|
||||
@@ -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<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
featured: String,
|
||||
category: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let _ = category;
|
||||
let _ = options;
|
||||
let _ = per_page;
|
||||
let _ = featured; // Ignored in this implementation
|
||||
let _ = pool; // Ignored in this implementation
|
||||
let videos: std::result::Result<Vec<VideoItem>, Error> = match query {
|
||||
Some(q) => {
|
||||
|
||||
@@ -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<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
featured: String,
|
||||
category: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let _ = category;
|
||||
let _ = options;
|
||||
let _ = per_page;
|
||||
let _ = featured;
|
||||
let _ = pool;
|
||||
|
||||
if sort == "date"{
|
||||
|
||||
@@ -18,4 +18,26 @@ pub fn parse_abbreviated_number(s: &str) -> Option<u32> {
|
||||
_ => return None,
|
||||
};
|
||||
num_part.parse::<f64>().ok().map(|n| (n * multiplier) as u32)
|
||||
}
|
||||
|
||||
pub fn interleave<T: Clone>(lists: &[Vec<T>]) -> Vec<T> {
|
||||
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
|
||||
}
|
||||
@@ -27,7 +27,16 @@ pub struct VideosRequest {
|
||||
// pub flavor: "mint chocolate chip"
|
||||
pub featured: Option<String>, // "featured",
|
||||
pub category: Option<String>, // "pmv"
|
||||
pub sites: Option<String>, //
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
|
||||
pub struct ServerOptions{
|
||||
pub featured: Option<String>, // "featured",
|
||||
pub category: Option<String>, // "pmv"
|
||||
pub sites: Option<String>, //
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, Debug)]
|
||||
pub struct PageInfo {
|
||||
pub hasNextPage: bool, // true,
|
||||
|
||||
Reference in New Issue
Block a user