pmvhaven
This commit is contained in:
255
src/api.rs
255
src/api.rs
@@ -1,31 +1,30 @@
|
||||
use std::cmp::Ordering;
|
||||
use ntex::http::header;
|
||||
use ntex::web;
|
||||
use ntex::web::HttpRequest;
|
||||
use tokio::{task};
|
||||
use std::cmp::Ordering;
|
||||
use tokio::task;
|
||||
|
||||
use crate::providers::hanime::HanimeProvider;
|
||||
use crate::providers::perverzija::PerverzijaProvider;
|
||||
use crate::providers::pmvhaven::PmvhavenProvider;
|
||||
use crate::providers::pornhub::PornhubProvider;
|
||||
use crate::providers::spankbang::SpankbangProvider;
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::{providers::*, status::*, videos::*, DbPool};
|
||||
use crate::{DbPool, providers::*, status::*, videos::*};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ClientVersion{
|
||||
struct ClientVersion {
|
||||
version: u32,
|
||||
subversion: u32,
|
||||
name: String,
|
||||
}
|
||||
|
||||
|
||||
impl ClientVersion {
|
||||
|
||||
pub fn new(version: u32, subversion: u32, name: String) -> ClientVersion{
|
||||
ClientVersion{
|
||||
pub fn new(version: u32, subversion: u32, name: String) -> ClientVersion {
|
||||
ClientVersion {
|
||||
version,
|
||||
subversion,
|
||||
name
|
||||
name,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,20 +36,21 @@ impl ClientVersion {
|
||||
let name = name_version[1];
|
||||
|
||||
// Extract version and optional subversion
|
||||
let (version, subversion) = if let Some((v, c)) = name.split_at(name.len().saturating_sub(1)).into() {
|
||||
match v.parse::<u32>() {
|
||||
Ok(ver) => (ver, c.chars().next().map(|ch| ch as u32).unwrap_or(0)),
|
||||
Err(_) => {
|
||||
// Try parsing whole string if no subversion exists
|
||||
match name.parse::<u32>() {
|
||||
Ok(ver) => (ver, 0),
|
||||
Err(_) => return None,
|
||||
let (version, subversion) =
|
||||
if let Some((v, c)) = name.split_at(name.len().saturating_sub(1)).into() {
|
||||
match v.parse::<u32>() {
|
||||
Ok(ver) => (ver, c.chars().next().map(|ch| ch as u32).unwrap_or(0)),
|
||||
Err(_) => {
|
||||
// Try parsing whole string if no subversion exists
|
||||
match name.parse::<u32>() {
|
||||
Ok(ver) => (ver, 0),
|
||||
Err(_) => return None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
|
||||
return Some(ClientVersion {
|
||||
version: version,
|
||||
@@ -99,16 +99,15 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
}
|
||||
|
||||
async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
|
||||
let clientversion: ClientVersion = match req.headers().get("User-Agent"){
|
||||
Some(v) => match v.to_str(){
|
||||
Ok(useragent) => ClientVersion::parse(useragent).unwrap_or_else(|| ClientVersion::new(999, 0, "999".to_string())),
|
||||
Err(_) => ClientVersion::new(999, 0, "999".to_string())
|
||||
let clientversion: ClientVersion = match req.headers().get("User-Agent") {
|
||||
Some(v) => match v.to_str() {
|
||||
Ok(useragent) => ClientVersion::parse(useragent)
|
||||
.unwrap_or_else(|| ClientVersion::new(999, 0, "999".to_string())),
|
||||
Err(_) => ClientVersion::new(999, 0, "999".to_string()),
|
||||
},
|
||||
_=> ClientVersion::new(999, 0, "999".to_string())
|
||||
_ => ClientVersion::new(999, 0, "999".to_string()),
|
||||
};
|
||||
|
||||
|
||||
let host = req
|
||||
.headers()
|
||||
.get(header::HOST)
|
||||
@@ -116,7 +115,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
.unwrap_or_default()
|
||||
.to_string();
|
||||
let mut status = Status::new();
|
||||
status.add_channel(Channel {
|
||||
status.add_channel(Channel {
|
||||
id: "pornhub".to_string(),
|
||||
name: "Pornhub".to_string(),
|
||||
description: "Pornhub Free Videos".to_string(),
|
||||
@@ -127,14 +126,26 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
options: vec![],
|
||||
nsfw: true,
|
||||
});
|
||||
if clientversion >= ClientVersion::new(22,97,"22a".to_string()){
|
||||
status.add_channel(Channel {
|
||||
id: "pmvhaven".to_string(),
|
||||
name: "Pmvhaven".to_string(),
|
||||
description: "Explore a curated collection of captivating PMV".to_string(),
|
||||
premium: false,
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=pmvhaven.com".to_string(),
|
||||
status: "active".to_string(),
|
||||
categories: vec![],
|
||||
options: vec![],
|
||||
nsfw: true,
|
||||
});
|
||||
if clientversion >= ClientVersion::new(22, 97, "22a".to_string()) {
|
||||
//add perverzija
|
||||
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(),
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=tube.perverzija.com"
|
||||
.to_string(),
|
||||
status: "active".to_string(),
|
||||
categories: vec![],
|
||||
options: vec![
|
||||
@@ -204,58 +215,56 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=hanime.tv".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: "created_at_unix.desc".to_string(),
|
||||
title: "Recent Upload".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "created_at_unix.asc".to_string(),
|
||||
title: "Old Upload".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "views.desc".to_string(),
|
||||
title: "Most Views".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "views.asc".to_string(),
|
||||
title: "Least Views".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "likes.desc".to_string(),
|
||||
title: "Most Likes".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "likes.asc".to_string(),
|
||||
title: "Least Likes".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "released_at_unix.desc".to_string(),
|
||||
title: "New".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "released_at_unix.asc".to_string(),
|
||||
title: "Old".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "title_sortable.asc".to_string(),
|
||||
title: "A - Z".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "title_sortable.desc".to_string(),
|
||||
title: "Z - A".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
}
|
||||
],
|
||||
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: "created_at_unix.desc".to_string(),
|
||||
title: "Recent Upload".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "created_at_unix.asc".to_string(),
|
||||
title: "Old Upload".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "views.desc".to_string(),
|
||||
title: "Most Views".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "views.asc".to_string(),
|
||||
title: "Least Views".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "likes.desc".to_string(),
|
||||
title: "Most Likes".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "likes.asc".to_string(),
|
||||
title: "Least Likes".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "released_at_unix.desc".to_string(),
|
||||
title: "New".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "released_at_unix.asc".to_string(),
|
||||
title: "Old".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "title_sortable.asc".to_string(),
|
||||
title: "A - Z".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "title_sortable.desc".to_string(),
|
||||
title: "Z - A".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
}],
|
||||
nsfw: true,
|
||||
});
|
||||
status.add_channel(Channel {
|
||||
@@ -266,29 +275,28 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
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,
|
||||
}
|
||||
],
|
||||
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.iconUrl = format!("http://{}/favicon.ico", host).to_string();
|
||||
@@ -331,11 +339,31 @@ async fn videos_post(
|
||||
.to_string()
|
||||
.parse()
|
||||
.unwrap();
|
||||
let featured = video_request.featured.as_deref().unwrap_or("all").to_string();
|
||||
let featured = video_request
|
||||
.featured
|
||||
.as_deref()
|
||||
.unwrap_or("all")
|
||||
.to_string();
|
||||
let provider = get_provider(channel.as_str())
|
||||
.ok_or_else(|| web::error::ErrorBadRequest("Invalid channel".to_string()))?;
|
||||
let category = video_request
|
||||
.category
|
||||
.as_deref()
|
||||
.unwrap_or("all")
|
||||
.to_string();
|
||||
|
||||
let video_items = provider
|
||||
.get_videos(cache.get_ref().clone(), pool.get_ref().clone(), channel.clone(), sort.clone(), query.clone(), page.to_string(), perPage.to_string(), featured.clone())
|
||||
.get_videos(
|
||||
cache.get_ref().clone(),
|
||||
pool.get_ref().clone(),
|
||||
channel.clone(),
|
||||
sort.clone(),
|
||||
query.clone(),
|
||||
page.to_string(),
|
||||
perPage.to_string(),
|
||||
featured.clone(),
|
||||
category.clone()
|
||||
)
|
||||
.await;
|
||||
videos.items = video_items.clone();
|
||||
if video_items.len() == 0 {
|
||||
@@ -344,7 +372,7 @@ async fn videos_post(
|
||||
resultsPerPage: 10,
|
||||
}
|
||||
}
|
||||
//###
|
||||
//###
|
||||
let next_page = page.to_string().parse::<i32>().unwrap_or(1) + 1;
|
||||
let provider_clone = provider.clone();
|
||||
let cache_clone = cache.get_ref().clone();
|
||||
@@ -354,10 +382,11 @@ async fn videos_post(
|
||||
let query_clone = query.clone();
|
||||
let per_page_clone = perPage.to_string();
|
||||
let featured_clone = featured.clone();
|
||||
let category_clone = category.clone();
|
||||
task::spawn_local(async move {
|
||||
// if let AnyProvider::Spankbang(_) = provider_clone {
|
||||
// // Spankbang has a delay for the next page
|
||||
// ntex::time::sleep(ntex::time::Seconds(80)).await;
|
||||
// ntex::time::sleep(ntex::time::Seconds(80)).await;
|
||||
// }
|
||||
let _ = provider_clone
|
||||
.get_videos(
|
||||
@@ -369,10 +398,11 @@ async fn videos_post(
|
||||
next_page.to_string(),
|
||||
per_page_clone,
|
||||
featured_clone,
|
||||
category_clone,
|
||||
)
|
||||
.await;
|
||||
});
|
||||
//###
|
||||
//###
|
||||
Ok(web::HttpResponse::Ok().json(&videos))
|
||||
}
|
||||
|
||||
@@ -382,6 +412,7 @@ pub fn get_provider(channel: &str) -> Option<AnyProvider> {
|
||||
"hanime" => Some(AnyProvider::Hanime(HanimeProvider::new())),
|
||||
"spankbang" => Some(AnyProvider::Spankbang(SpankbangProvider::new())),
|
||||
"pornhub" => Some(AnyProvider::Pornhub(PornhubProvider::new())),
|
||||
"pmvhaven" => Some(AnyProvider::Pmvhaven(PmvhavenProvider::new())),
|
||||
_ => Some(AnyProvider::Perverzija(PerverzijaProvider::new())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user