all provider

This commit is contained in:
Simon
2025-08-10 14:02:09 +00:00
parent 8944646c85
commit 97066a184a
10 changed files with 37 additions and 28 deletions

View File

@@ -4,9 +4,11 @@ use futures::future::join_all;
use serde_json::error::Category;
use wreq::Client;
use wreq_util::Emulation;
use crate::api::get_provider;
use crate::db;
use crate::providers::Provider;
use crate::providers::{AnyProvider, Provider};
use crate::util::cache::VideoCache;
use crate::util::interleave;
use crate::videos::{self, ServerOptions, VideoItem};
use crate::DbPool;
@@ -34,17 +36,37 @@ impl Provider for AllProvider {
&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();
let mut sites_str = options.clone().sites.unwrap();
if sites_str.is_empty() {
sites_str = "perverzija,hanime,spankbang,pmvhaven,redtube,pornhub,rule34video".to_string();
}
let sites = sites_str
.split(',')
.map(|s| s.to_string()) // or s.to_owned()
.collect::<Vec<String>>();
let providers = sites.iter().map(|el| get_provider(el.as_str()).unwrap()).collect::<Vec<AnyProvider>>();
let futures = providers.iter().map(|provider| {
provider.get_videos(
cache.clone(),
pool.clone(),
sort.clone(),
query.clone(),
page.clone(),
per_page.clone(),
options.clone()
)
}).collect::<Vec<_>>();
let results:Vec<Vec<VideoItem>> = join_all(futures).await;
let video_items: Vec<VideoItem> = interleave(&results);
println!("Sites: {:?}", sites);
return vec![];
return video_items;
}
}

View File

@@ -259,7 +259,6 @@ impl Provider for HanimeProvider {
&self,
cache: VideoCache,
pool: DbPool,
_channel: String,
sort: String,
query: Option<String>,
page: String,

View File

@@ -18,7 +18,6 @@ pub trait Provider {
&self,
cache: VideoCache,
pool: DbPool,
channel: String,
sort: String,
query: Option<String>,
page: String,
@@ -44,7 +43,6 @@ impl Provider for AnyProvider {
&self,
cache: VideoCache,
pool: DbPool,
channel: String,
sort: String,
query: Option<String>,
page: String,
@@ -52,15 +50,14 @@ impl Provider for AnyProvider {
options: ServerOptions
) -> Vec<VideoItem> {
println!(
"/api/videos: channel={:?}, sort={:?}, query={:?}, page={:?}",
channel, sort, query, page
"/api/videos: sort={:?}, query={:?}, page={:?}, provider={:?}",
sort, query, page, self
);
match self {
AnyProvider::Perverzija(p) => {
p.get_videos(
cache.clone(),
pool.clone(),
channel.clone(),
sort.clone(),
query.clone(),
page.clone(),
@@ -70,31 +67,31 @@ impl Provider for AnyProvider {
.await
}
AnyProvider::Hanime(p) => {
p.get_videos(cache, pool, channel, sort, query, page, per_page, options,)
p.get_videos(cache, pool, sort, query, page, per_page, options,)
.await
}
AnyProvider::Spankbang(p) => {
p.get_videos(cache, pool, channel, sort, query, page, per_page, options,)
p.get_videos(cache, pool, sort, query, page, per_page, options,)
.await
}
AnyProvider::Pornhub(p) => {
p.get_videos(cache, pool, channel, sort, query, page, per_page, options,)
p.get_videos(cache, pool, sort, query, page, per_page, options,)
.await
}
AnyProvider::Pmvhaven(p) => {
p.get_videos(cache, pool, channel, sort, query, page, per_page, options,)
p.get_videos(cache, pool, sort, query, page, per_page, options,)
.await
}
AnyProvider::Rule34video(p) => {
p.get_videos(cache, pool, channel, sort, query, page, per_page, options,)
p.get_videos(cache, pool, sort, query, page, per_page, options,)
.await
}
AnyProvider::Redtube(p) => {
p.get_videos(cache, pool, channel, sort, query, page, per_page, options,)
p.get_videos(cache, pool, sort, query, page, per_page, options,)
.await
}
AnyProvider::All(p) => {
p.get_videos(cache, pool, channel, sort, query, page, per_page, options,)
p.get_videos(cache, pool, sort, query, page, per_page, options,)
.await
}
}

View File

@@ -546,7 +546,6 @@ impl Provider for PerverzijaProvider {
&self,
cache: VideoCache,
pool: DbPool,
_channel: String,
sort: String,
query: Option<String>,
page: String,

View File

@@ -419,7 +419,6 @@ impl Provider for PmvhavenProvider {
&self,
cache: VideoCache,
pool: DbPool,
_channel: String,
sort: String,
query: Option<String>,
page: String,

View File

@@ -326,7 +326,6 @@ impl Provider for PornhubProvider {
&self,
cache: VideoCache,
pool: DbPool,
_channel: String,
sort: String,
query: Option<String>,
page: String,

View File

@@ -261,7 +261,6 @@ impl Provider for RedtubeProvider {
&self,
cache: VideoCache,
pool: DbPool,
_channel: String,
sort: String,
query: Option<String>,
page: String,

View File

@@ -287,7 +287,6 @@ impl Provider for Rule34videoProvider {
&self,
cache: VideoCache,
pool: DbPool,
_channel: String,
sort: String,
query: Option<String>,
page: String,

View File

@@ -353,7 +353,6 @@ impl Provider for SpankbangProvider {
&self,
cache: VideoCache,
pool: DbPool,
_channel: String,
mut sort: String,
query: Option<String>,
page: String,