clean cache, handled warnings etc
This commit is contained in:
@@ -18,4 +18,5 @@ once_cell = "1.21.3"
|
|||||||
reqwest = { version = "0.12.18", features = ["blocking", "json", "rustls-tls"] }
|
reqwest = { version = "0.12.18", features = ["blocking", "json", "rustls-tls"] }
|
||||||
serde = "1.0.219"
|
serde = "1.0.219"
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
|
tokio = { version = "1.45.1", features = ["full"] }
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
-- Your SQL goes here
|
-- Your SQL goes here
|
||||||
CREATE TABLE videos (
|
CREATE TABLE videos (
|
||||||
id TEXT NOT NULL PRIMARY KEY, -- like url parts to uniquely identify a video
|
id TEXT NOT NULL PRIMARY KEY, -- like url parts to uniquely identify a video
|
||||||
url TEXT NOT NULL--,
|
url TEXT NOT NULL UNIQUE--,
|
||||||
--views INTEGER,
|
--views INTEGER,
|
||||||
--rating INTEGER,
|
--rating INTEGER,
|
||||||
--uploader TEXT
|
--uploader TEXT
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use futures::channel;
|
|
||||||
use ntex::http::header;
|
use ntex::http::header;
|
||||||
use ntex::web;
|
use ntex::web;
|
||||||
use ntex::web::HttpRequest;
|
use ntex::web::HttpRequest;
|
||||||
@@ -237,7 +236,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn videos_post(
|
async fn videos_post(
|
||||||
video_request: web::types::Json<Videos_Request>,
|
video_request: web::types::Json<VideosRequest>,
|
||||||
cache: web::types::State<VideoCache>,
|
cache: web::types::State<VideoCache>,
|
||||||
pool: web::types::State<DbPool>,
|
pool: web::types::State<DbPool>,
|
||||||
) -> Result<impl web::Responder, web::Error> {
|
) -> Result<impl web::Responder, web::Error> {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
#[macro_use]
|
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
|
||||||
use diesel::{r2d2::{self, ConnectionManager}, SqliteConnection};
|
use diesel::{r2d2::{self, ConnectionManager}, SqliteConnection};
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
use std::time::Duration;
|
|
||||||
use std::vec;
|
use std::vec;
|
||||||
use std::env;
|
use std::env;
|
||||||
use error_chain::error_chain;
|
use error_chain::error_chain;
|
||||||
use htmlentity::entity::{decode, ICodedDataTrait};
|
|
||||||
use reqwest::{Proxy};
|
use reqwest::{Proxy};
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
|
|
||||||
use crate::db;
|
use crate::db;
|
||||||
use crate::providers::Provider;
|
use crate::providers::Provider;
|
||||||
use crate::util::cache::VideoCache;
|
use crate::util::cache::VideoCache;
|
||||||
use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr};
|
use crate::videos::{self, VideoItem};
|
||||||
use crate::util::time::parse_time_to_seconds;
|
|
||||||
use crate::videos::{self, Video_Embed, Video_Item};
|
|
||||||
use crate::DbPool; // Make sure Provider trait is imported
|
use crate::DbPool; // Make sure Provider trait is imported
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
@@ -33,6 +29,7 @@ struct HanimeSearchRequest{
|
|||||||
page: u8
|
page: u8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
impl HanimeSearchRequest {
|
impl HanimeSearchRequest {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
HanimeSearchRequest {
|
HanimeSearchRequest {
|
||||||
@@ -116,6 +113,7 @@ struct HanimeSearchResult{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct HanimeProvider {
|
pub struct HanimeProvider {
|
||||||
url: String,
|
url: String,
|
||||||
}
|
}
|
||||||
@@ -127,7 +125,7 @@ impl HanimeProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_video_item(&self, hit: HanimeSearchResult, pool: DbPool) -> Result<Video_Item> {
|
async fn get_video_item(&self, hit: HanimeSearchResult, pool: DbPool) -> Result<VideoItem> {
|
||||||
let mut conn = pool.get().expect("couldn't get db connection from pool");
|
let mut conn = pool.get().expect("couldn't get db connection from pool");
|
||||||
let db_result = db::get_video(&mut conn,format!("https://h.freeanimehentai.net/api/v8/video?id={}&", hit.slug.clone()));
|
let db_result = db::get_video(&mut conn,format!("https://h.freeanimehentai.net/api/v8/video?id={}&", hit.slug.clone()));
|
||||||
drop(conn);
|
drop(conn);
|
||||||
@@ -138,12 +136,12 @@ impl HanimeProvider {
|
|||||||
let channel = "hanime".to_string(); // Placeholder, adjust as needed
|
let channel = "hanime".to_string(); // Placeholder, adjust as needed
|
||||||
match db_result {
|
match db_result {
|
||||||
Ok(Some(video_url)) => {
|
Ok(Some(video_url)) => {
|
||||||
return Ok(Video_Item::new(id, title, video_url.clone(), channel, thumb, duration)
|
return Ok(VideoItem::new(id, title, video_url.clone(), channel, thumb, duration)
|
||||||
.tags(hit.tags)
|
.tags(hit.tags)
|
||||||
.uploader(hit.brand)
|
.uploader(hit.brand)
|
||||||
.views(hit.views as u32)
|
.views(hit.views as u32)
|
||||||
.rating((hit.likes as f32 / (hit.likes + hit.dislikes)as f32) * 100 as f32)
|
.rating((hit.likes as f32 / (hit.likes + hit.dislikes)as f32) * 100 as f32)
|
||||||
.formats(vec![videos::Video_Format::new(video_url.clone(), "1080".to_string(), "m3u8".to_string())]));
|
.formats(vec![videos::VideoFormat::new(video_url.clone(), "1080".to_string(), "m3u8".to_string())]));
|
||||||
}
|
}
|
||||||
Ok(None) => (),
|
Ok(None) => (),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -189,16 +187,16 @@ impl HanimeProvider {
|
|||||||
let mut conn = pool.get().expect("couldn't get db connection from pool");
|
let mut conn = pool.get().expect("couldn't get db connection from pool");
|
||||||
let _ = db::insert_video(&mut conn, &format!("https://h.freeanimehentai.net/api/v8/video?id={}&", hit.slug.clone()), &url_vec[0].clone());
|
let _ = db::insert_video(&mut conn, &format!("https://h.freeanimehentai.net/api/v8/video?id={}&", hit.slug.clone()), &url_vec[0].clone());
|
||||||
drop(conn);
|
drop(conn);
|
||||||
Ok(Video_Item::new(id, title, url_vec[0].clone(), channel, thumb, duration)
|
Ok(VideoItem::new(id, title, url_vec[0].clone(), channel, thumb, duration)
|
||||||
.tags(hit.tags)
|
.tags(hit.tags)
|
||||||
.uploader(hit.brand)
|
.uploader(hit.brand)
|
||||||
.views(hit.views as u32)
|
.views(hit.views as u32)
|
||||||
.rating((hit.likes as f32 / (hit.likes + hit.dislikes)as f32) * 100 as f32)
|
.rating((hit.likes as f32 / (hit.likes + hit.dislikes)as f32) * 100 as f32)
|
||||||
.formats(vec![videos::Video_Format::new(url_vec[0].clone(), "1080".to_string(), "m3u8".to_string())]))
|
.formats(vec![videos::VideoFormat::new(url_vec[0].clone(), "1080".to_string(), "m3u8".to_string())]))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get(&self, cache: VideoCache, pool: DbPool, page: u8, query: String, sort:String) -> Result<Vec<Video_Item>> {
|
async fn get(&self, cache: VideoCache, pool: DbPool, page: u8, query: String, sort:String) -> Result<Vec<VideoItem>> {
|
||||||
let index = format!("{}:{}:{}", query, page, sort);
|
let index = format!("{}:{}:{}", query, page, sort);
|
||||||
let order_by = sort.split(".").collect::<Vec<&str>>()[0].to_string();
|
let order_by = sort.split(".").collect::<Vec<&str>>()[0].to_string();
|
||||||
let ordering = sort.split(".").collect::<Vec<&str>>()[1].to_string();
|
let ordering = sort.split(".").collect::<Vec<&str>>()[1].to_string();
|
||||||
@@ -251,8 +249,8 @@ impl HanimeProvider {
|
|||||||
.map_err(|e| format!("Failed to parse hits JSON: {}", e))?;
|
.map_err(|e| format!("Failed to parse hits JSON: {}", e))?;
|
||||||
// let timeout_duration = Duration::from_secs(120);
|
// let timeout_duration = Duration::from_secs(120);
|
||||||
let futures = hits_json.into_iter().map(|el| self.get_video_item(el.clone(), pool.clone()));
|
let futures = hits_json.into_iter().map(|el| self.get_video_item(el.clone(), pool.clone()));
|
||||||
let results: Vec<Result<Video_Item>> = join_all(futures).await;
|
let results: Vec<Result<VideoItem>> = join_all(futures).await;
|
||||||
let video_items: Vec<Video_Item> = results
|
let video_items: Vec<VideoItem> = results
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.collect();
|
.collect();
|
||||||
@@ -278,12 +276,12 @@ impl Provider for HanimeProvider {
|
|||||||
page: String,
|
page: String,
|
||||||
per_page: String,
|
per_page: String,
|
||||||
featured: String,
|
featured: String,
|
||||||
) -> Vec<Video_Item> {
|
) -> Vec<VideoItem> {
|
||||||
let _ = featured;
|
let _ = featured;
|
||||||
let _ = per_page;
|
let _ = per_page;
|
||||||
let _ = sort;
|
let _ = sort;
|
||||||
println!("Sort: {:?}", sort);
|
println!("Sort: {:?}", sort);
|
||||||
let videos: std::result::Result<Vec<Video_Item>, Error> = match query {
|
let videos: std::result::Result<Vec<VideoItem>, Error> = match query {
|
||||||
Some(q) => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), q, sort).await,
|
Some(q) => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), q, sort).await,
|
||||||
None => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), "".to_string(), sort).await,
|
None => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), "".to_string(), sort).await,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::{providers::{hanime::HanimeProvider, perverzija::PerverzijaProvider}, util::cache::VideoCache, videos::Video_Item, DbPool};
|
use crate::{providers::{hanime::HanimeProvider, perverzija::PerverzijaProvider}, util::cache::VideoCache, videos::VideoItem, DbPool};
|
||||||
|
|
||||||
pub mod perverzija;
|
pub mod perverzija;
|
||||||
pub mod hanime;
|
pub mod hanime;
|
||||||
|
|
||||||
pub trait Provider{
|
pub trait Provider{
|
||||||
async fn get_videos(&self, cache: VideoCache, pool: DbPool, channel: String, sort: String, query: Option<String>, page: String, per_page: String, featured: String) -> Vec<Video_Item>;
|
async fn get_videos(&self, cache: VideoCache, pool: DbPool, channel: String, sort: String, query: Option<String>, page: String, per_page: String, featured: String) -> Vec<VideoItem>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum AnyProvider {
|
pub enum AnyProvider {
|
||||||
@@ -12,7 +12,7 @@ pub enum AnyProvider {
|
|||||||
Hanime(HanimeProvider),
|
Hanime(HanimeProvider),
|
||||||
}
|
}
|
||||||
impl Provider for AnyProvider {
|
impl Provider for AnyProvider {
|
||||||
async fn get_videos(&self, cache: VideoCache, pool:DbPool, channel: String, sort: String, query: Option<String>, page: String, per_page: String, featured: String) -> Vec<Video_Item> {
|
async fn get_videos(&self, cache: VideoCache, pool:DbPool, channel: String, sort: String, query: Option<String>, page: String, per_page: String, featured: String) -> Vec<VideoItem> {
|
||||||
match self {
|
match self {
|
||||||
AnyProvider::Perverzija(p) => p.get_videos(cache, pool, channel, sort, query, page, per_page, featured).await,
|
AnyProvider::Perverzija(p) => p.get_videos(cache, pool, channel, sort, query, page, per_page, featured).await,
|
||||||
AnyProvider::Hanime(p) => p.get_videos(cache, pool, channel, sort, query, page, per_page, featured).await,
|
AnyProvider::Hanime(p) => p.get_videos(cache, pool, channel, sort, query, page, per_page, featured).await,
|
||||||
|
|||||||
@@ -4,14 +4,13 @@ use error_chain::error_chain;
|
|||||||
use htmlentity::entity::{decode, ICodedDataTrait};
|
use htmlentity::entity::{decode, ICodedDataTrait};
|
||||||
use reqwest::{Proxy};
|
use reqwest::{Proxy};
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use ntex::web;
|
|
||||||
|
|
||||||
use crate::db;
|
use crate::db;
|
||||||
use crate::providers::Provider;
|
use crate::providers::Provider;
|
||||||
use crate::util::cache::VideoCache;
|
use crate::util::cache::VideoCache;
|
||||||
use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr};
|
use crate::util::flaresolverr::{FlareSolverrRequest, Flaresolverr};
|
||||||
use crate::util::time::parse_time_to_seconds;
|
use crate::util::time::parse_time_to_seconds;
|
||||||
use crate::videos::{self, Video_Embed, Video_Item};
|
use crate::videos::{self, VideoEmbed, VideoItem};
|
||||||
use crate::DbPool; // Make sure Provider trait is imported
|
use crate::DbPool; // Make sure Provider trait is imported
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
@@ -30,7 +29,7 @@ impl PerverzijaProvider {
|
|||||||
url: "https://tube.perverzija.com/".to_string(),
|
url: "https://tube.perverzija.com/".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async fn get(&self, cache:VideoCache, pool:DbPool, page: u8, featured: String) -> Result<Vec<Video_Item>> {
|
async fn get(&self, cache:VideoCache, pool:DbPool, page: u8, featured: String) -> Result<Vec<VideoItem>> {
|
||||||
//TODO
|
//TODO
|
||||||
// let mut url = Url::parse("https://example.net")?;
|
// let mut url = Url::parse("https://example.net")?;
|
||||||
// url.query_pairs_mut().append_pair("foo", "bar");
|
// url.query_pairs_mut().append_pair("foo", "bar");
|
||||||
@@ -80,7 +79,7 @@ impl PerverzijaProvider {
|
|||||||
// print!("Response: {:?}\n", response);
|
// print!("Response: {:?}\n", response);
|
||||||
if response.status().is_success() {
|
if response.status().is_success() {
|
||||||
let text = response.text().await?;
|
let text = response.text().await?;
|
||||||
let video_items: Vec<Video_Item> = self.get_video_items_from_html(text.clone(), pool);
|
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone(), pool);
|
||||||
if !video_items.is_empty() {
|
if !video_items.is_empty() {
|
||||||
cache.remove(&url);
|
cache.remove(&url);
|
||||||
cache.insert(url.clone(), video_items.clone());
|
cache.insert(url.clone(), video_items.clone());
|
||||||
@@ -117,7 +116,7 @@ impl PerverzijaProvider {
|
|||||||
Ok(video_items)
|
Ok(video_items)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async fn query(&self, cache: VideoCache, pool:DbPool, page: u8, query: &str) -> Result<Vec<Video_Item>> {
|
async fn query(&self, cache: VideoCache, pool:DbPool, page: u8, query: &str) -> Result<Vec<VideoItem>> {
|
||||||
let search_string = query.replace(" ", "+");
|
let search_string = query.replace(" ", "+");
|
||||||
let mut url = format!(
|
let mut url = format!(
|
||||||
"{}page/{}/?s={}",
|
"{}page/{}/?s={}",
|
||||||
@@ -134,7 +133,8 @@ impl PerverzijaProvider {
|
|||||||
return Ok(items.clone());
|
return Ok(items.clone());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
items.clone()
|
let _ = cache.check().await;
|
||||||
|
return Ok(items.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
@@ -157,7 +157,7 @@ impl PerverzijaProvider {
|
|||||||
let response = client.get(url.clone()).send().await?;
|
let response = client.get(url.clone()).send().await?;
|
||||||
if response.status().is_success() {
|
if response.status().is_success() {
|
||||||
let text = response.text().await?;
|
let text = response.text().await?;
|
||||||
let video_items: Vec<Video_Item> = self.get_video_items_from_html_query(text.clone(), pool).await;
|
let video_items: Vec<VideoItem> = self.get_video_items_from_html_query(text.clone(), pool).await;
|
||||||
if !video_items.is_empty() {
|
if !video_items.is_empty() {
|
||||||
cache.remove(&url);
|
cache.remove(&url);
|
||||||
cache.insert(url.clone(), video_items.clone());
|
cache.insert(url.clone(), video_items.clone());
|
||||||
@@ -194,12 +194,12 @@ impl PerverzijaProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_video_items_from_html(&self, html: String, pool: DbPool) -> Vec<Video_Item> {
|
fn get_video_items_from_html(&self, html: String, pool: DbPool) -> Vec<VideoItem> {
|
||||||
if html.is_empty() {
|
if html.is_empty() {
|
||||||
println!("HTML is empty");
|
println!("HTML is empty");
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
let mut items: Vec<Video_Item> = Vec::new();
|
let mut items: Vec<VideoItem> = Vec::new();
|
||||||
let video_listing_content = html.split("video-listing-content").collect::<Vec<&str>>()[1];
|
let video_listing_content = html.split("video-listing-content").collect::<Vec<&str>>()[1];
|
||||||
let raw_videos = video_listing_content
|
let raw_videos = video_listing_content
|
||||||
.split("video-item post")
|
.split("video-item post")
|
||||||
@@ -261,7 +261,7 @@ impl PerverzijaProvider {
|
|||||||
let _ = db::insert_video(&mut conn, &id_url, &url);
|
let _ = db::insert_video(&mut conn, &id_url, &url);
|
||||||
drop(conn);
|
drop(conn);
|
||||||
let referer_url = "https://xtremestream.xyz/".to_string();
|
let referer_url = "https://xtremestream.xyz/".to_string();
|
||||||
let embed = Video_Embed::new(embed_html, url.clone());
|
let embed = VideoEmbed::new(embed_html, url.clone());
|
||||||
|
|
||||||
let mut tags: Vec<String> = Vec::new(); // Placeholder for tags, adjust as needed
|
let mut tags: Vec<String> = Vec::new(); // Placeholder for tags, adjust as needed
|
||||||
for tag in vid[0].split(" ").collect::<Vec<&str>>(){
|
for tag in vid[0].split(" ").collect::<Vec<&str>>(){
|
||||||
@@ -273,7 +273,7 @@ impl PerverzijaProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut video_item = Video_Item::new(
|
let mut video_item = VideoItem::new(
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
embed.source.clone(),
|
embed.source.clone(),
|
||||||
@@ -283,7 +283,7 @@ impl PerverzijaProvider {
|
|||||||
).tags(tags);
|
).tags(tags);
|
||||||
// .embed(embed.clone());
|
// .embed(embed.clone());
|
||||||
let mut format =
|
let mut format =
|
||||||
videos::Video_Format::new(url.clone(), "1080".to_string(), "m3u8".to_string());
|
videos::VideoFormat::new(url.clone(), "1080".to_string(), "m3u8".to_string());
|
||||||
format.add_http_header("Referer".to_string(), referer_url.clone());
|
format.add_http_header("Referer".to_string(), referer_url.clone());
|
||||||
if let Some(formats) = video_item.formats.as_mut() {
|
if let Some(formats) = video_item.formats.as_mut() {
|
||||||
formats.push(format);
|
formats.push(format);
|
||||||
@@ -296,21 +296,21 @@ impl PerverzijaProvider {
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_video_items_from_html_query(&self, html: String, pool:DbPool) -> Vec<Video_Item> {
|
async fn get_video_items_from_html_query(&self, html: String, pool:DbPool) -> Vec<VideoItem> {
|
||||||
let raw_videos = html
|
let raw_videos = html
|
||||||
.split("video-item post")
|
.split("video-item post")
|
||||||
.collect::<Vec<&str>>()[1..]
|
.collect::<Vec<&str>>()[1..]
|
||||||
.to_vec();
|
.to_vec();
|
||||||
let futures = raw_videos.into_iter().map(|el| self.get_video_item(el, pool.clone()));
|
let futures = raw_videos.into_iter().map(|el| self.get_video_item(el, pool.clone()));
|
||||||
let results: Vec<Result<Video_Item>> = join_all(futures).await;
|
let results: Vec<Result<VideoItem>> = join_all(futures).await;
|
||||||
let items: Vec<Video_Item> = results
|
let items: Vec<VideoItem> = results
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.collect();
|
.collect();
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_video_item(&self, snippet: &str, pool: DbPool) -> Result<Video_Item> {
|
async fn get_video_item(&self, snippet: &str, pool: DbPool) -> Result<VideoItem> {
|
||||||
let vid = snippet.split("\n").collect::<Vec<&str>>();
|
let vid = snippet.split("\n").collect::<Vec<&str>>();
|
||||||
if vid.len() > 30 {
|
if vid.len() > 30 {
|
||||||
return Err("Unexpected video snippet length".into());
|
return Err("Unexpected video snippet length".into());
|
||||||
@@ -355,7 +355,7 @@ impl PerverzijaProvider {
|
|||||||
if id.contains("&"){
|
if id.contains("&"){
|
||||||
id = id.split("&").collect::<Vec<&str>>()[0].to_string()
|
id = id.split("&").collect::<Vec<&str>>()[0].to_string()
|
||||||
}
|
}
|
||||||
let mut video_item = Video_Item::new(
|
let mut video_item = VideoItem::new(
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
url.clone(),
|
url.clone(),
|
||||||
@@ -364,7 +364,7 @@ impl PerverzijaProvider {
|
|||||||
duration,
|
duration,
|
||||||
);
|
);
|
||||||
let mut format =
|
let mut format =
|
||||||
videos::Video_Format::new(url.clone(), "1080".to_string(), "m3u8".to_string());
|
videos::VideoFormat::new(url.clone(), "1080".to_string(), "m3u8".to_string());
|
||||||
format.add_http_header("Referer".to_string(), referer_url.clone());
|
format.add_http_header("Referer".to_string(), referer_url.clone());
|
||||||
if let Some(formats) = video_item.formats.as_mut() {
|
if let Some(formats) = video_item.formats.as_mut() {
|
||||||
formats.push(format);
|
formats.push(format);
|
||||||
@@ -438,7 +438,7 @@ impl PerverzijaProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut video_item = Video_Item::new(
|
let mut video_item = VideoItem::new(
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
url.clone(),
|
url.clone(),
|
||||||
@@ -449,7 +449,7 @@ impl PerverzijaProvider {
|
|||||||
.tags(tags);
|
.tags(tags);
|
||||||
// .embed(embed.clone());
|
// .embed(embed.clone());
|
||||||
let mut format =
|
let mut format =
|
||||||
videos::Video_Format::new(url.clone(), "1080".to_string(), "m3u8".to_string());
|
videos::VideoFormat::new(url.clone(), "1080".to_string(), "m3u8".to_string());
|
||||||
format.add_http_header("Referer".to_string(), referer_url.clone());
|
format.add_http_header("Referer".to_string(), referer_url.clone());
|
||||||
if let Some(formats) = video_item.formats.as_mut() {
|
if let Some(formats) = video_item.formats.as_mut() {
|
||||||
formats.push(format);
|
formats.push(format);
|
||||||
@@ -471,10 +471,10 @@ impl Provider for PerverzijaProvider {
|
|||||||
page: String,
|
page: String,
|
||||||
per_page: String,
|
per_page: String,
|
||||||
featured: String,
|
featured: String,
|
||||||
) -> Vec<Video_Item> {
|
) -> Vec<VideoItem> {
|
||||||
let _ = per_page;
|
let _ = per_page;
|
||||||
let _ = sort;
|
let _ = sort;
|
||||||
let videos: std::result::Result<Vec<Video_Item>, Error> = match query {
|
let videos: std::result::Result<Vec<VideoItem>, Error> = match query {
|
||||||
Some(q) => self.query(cache, pool, page.parse::<u8>().unwrap_or(1), &q).await,
|
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), featured).await,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ pub struct Options {
|
|||||||
pub description: String, //"Sort the videos by new or old.",
|
pub description: String, //"Sort the videos by new or old.",
|
||||||
pub systemImage: String, //"sort.image",
|
pub systemImage: String, //"sort.image",
|
||||||
pub colorName: String, //"blue",
|
pub colorName: String, //"blue",
|
||||||
pub options: Vec<Option_Value>,
|
pub options: Vec<OptionValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
pub struct Option_Value {
|
pub struct OptionValue {
|
||||||
pub id: String, //"new",
|
pub id: String, //"new",
|
||||||
pub title: String, //"New",
|
pub title: String, //"New",
|
||||||
pub description: Option<String>, //"Sort the videos by new or old."
|
pub description: Option<String>, //"Sort the videos by new or old."
|
||||||
@@ -107,15 +107,19 @@ impl Status {
|
|||||||
.to_string(),
|
.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn add_notice(&mut self, notice: Notice) {
|
pub fn add_notice(&mut self, notice: Notice) {
|
||||||
self.notices.push(notice);
|
self.notices.push(notice);
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn add_channel(&mut self, channel: Channel) {
|
pub fn add_channel(&mut self, channel: Channel) {
|
||||||
self.channels.push(channel);
|
self.channels.push(channel);
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn add_option(&mut self, option: Options) {
|
pub fn add_option(&mut self, option: Options) {
|
||||||
self.options.push(option);
|
self.options.push(option);
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn add_category(&mut self, category: String) {
|
pub fn add_category(&mut self, category: String) {
|
||||||
self.categories.push(category);
|
self.categories.push(category);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
use std::time::SystemTime;
|
use std::time::{SystemTime};
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use crate::videos::Video_Item;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
|
||||||
|
use crate::videos::VideoItem;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct VideoCache{
|
pub struct VideoCache{
|
||||||
cache: Arc<Mutex<std::collections::HashMap<String, (SystemTime, Vec<Video_Item>)>>>, // url -> time+Items
|
cache: Arc<Mutex<std::collections::HashMap<String, (SystemTime, Vec<VideoItem>)>>>, // url -> time+Items
|
||||||
}
|
}
|
||||||
impl VideoCache {
|
impl VideoCache {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
@@ -14,21 +17,44 @@ impl VideoCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, key: &str) -> Option<(SystemTime, Vec<Video_Item>)> {
|
pub fn get(&self, key: &str) -> Option<(SystemTime, Vec<VideoItem>)> {
|
||||||
let cache = self.cache.lock().ok()?;
|
let cache = self.cache.lock().ok()?;
|
||||||
cache.get(key).cloned()
|
cache.get(key).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&self, key: String, value: Vec<Video_Item>) {
|
pub fn insert(&self, key: String, value: Vec<VideoItem>) {
|
||||||
if let Ok(mut cache) = self.cache.lock() {
|
if let Ok(mut cache) = self.cache.lock() {
|
||||||
cache.insert(key.clone(), (SystemTime::now(), value.clone()));
|
cache.insert(key.clone(), (SystemTime::now(), value.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&self, key: &str) {
|
pub fn remove(&self, key: &str) {
|
||||||
if let Ok(mut cache) = self.cache.lock() {
|
if let Ok(mut cache) = self.cache.lock() {
|
||||||
cache.remove(key);
|
cache.remove(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn entries(&self) -> Option<Vec<(String, (SystemTime, Vec<VideoItem>))>> {
|
||||||
|
if let Ok(cache) = self.cache.lock() {
|
||||||
|
// Return a cloned vector of the cache entries
|
||||||
|
return Some(cache.iter().map(|(k, v)| (k.clone(), v.clone())).collect());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn check(&self) -> Result<(), Box<dyn std::error::Error>>{
|
||||||
|
let iter = match self.entries(){
|
||||||
|
Some(iter) => iter,
|
||||||
|
None => return Err(Box::new(std::io::Error::new(std::io::ErrorKind::Other, "Could not get entries")))
|
||||||
|
};
|
||||||
|
|
||||||
|
for (key, (time, _items)) in iter {
|
||||||
|
if let Ok(elapsed) = time.elapsed() {
|
||||||
|
if elapsed > Duration::from_secs(60*60){
|
||||||
|
println!("Key: {}, elapsed: {:?}", key, elapsed);
|
||||||
|
self.remove(&key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
|
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Debug)]
|
#[derive(serde::Serialize, serde::Deserialize, Debug)]
|
||||||
pub struct Videos_Request {
|
pub struct VideosRequest {
|
||||||
//"versionInstallDate":"2025-06-03T18:20:20Z","languageCode":"en","appInstallDate":"2025-06-03T18:20:20Z","server":"spacemoehre","sexu
|
//"versionInstallDate":"2025-06-03T18:20:20Z","languageCode":"en","appInstallDate":"2025-06-03T18:20:20Z","server":"spacemoehre","sexu
|
||||||
pub clientHash: Option<String>, // "a07b23c9b07813c65050e2a4041ca777",
|
pub clientHash: Option<String>, // "a07b23c9b07813c65050e2a4041ca777",
|
||||||
pub blockedKeywords: Option<String>, // "kittens",
|
pub blockedKeywords: Option<String>, // "kittens",
|
||||||
@@ -35,20 +35,20 @@ pub struct PageInfo {
|
|||||||
|
|
||||||
|
|
||||||
#[derive(serde::Serialize, Debug, Clone)]
|
#[derive(serde::Serialize, Debug, Clone)]
|
||||||
pub struct Video_Embed{
|
pub struct VideoEmbed{
|
||||||
pub html: String,
|
pub html: String,
|
||||||
pub source: String,
|
pub source: String,
|
||||||
}
|
}
|
||||||
impl Video_Embed {
|
impl VideoEmbed {
|
||||||
pub fn new(html: String, source: String) -> Self {
|
pub fn new(html: String, source: String) -> Self {
|
||||||
Video_Embed {
|
VideoEmbed {
|
||||||
html,
|
html,
|
||||||
source,
|
source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(serde::Serialize, Debug, Clone)]
|
#[derive(serde::Serialize, Debug, Clone)]
|
||||||
pub struct Video_Item {
|
pub struct VideoItem {
|
||||||
pub duration: u32, // 110,
|
pub duration: u32, // 110,
|
||||||
pub views: Option<u32>, // 14622653,
|
pub views: Option<u32>, // 14622653,
|
||||||
pub rating: Option<f32>, // 0.0,
|
pub rating: Option<f32>, // 0.0,
|
||||||
@@ -62,10 +62,11 @@ pub struct Video_Item {
|
|||||||
pub verified: Option<bool>, // false,
|
pub verified: Option<bool>, // false,
|
||||||
pub tags: Option<Vec<String>>, // [],
|
pub tags: Option<Vec<String>>, // [],
|
||||||
pub uploadedAt: Option<u64>, // 1741142954
|
pub uploadedAt: Option<u64>, // 1741142954
|
||||||
pub formats: Option<Vec<Video_Format>>, // Additional HTTP headers if needed
|
pub formats: Option<Vec<VideoFormat>>, // Additional HTTP headers if needed
|
||||||
pub embed: Option<Video_Embed>, // Optional embed information
|
pub embed: Option<VideoEmbed>, // Optional embed information
|
||||||
}
|
}
|
||||||
impl Video_Item {
|
#[allow(dead_code)]
|
||||||
|
impl VideoItem {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
id: String,
|
id: String,
|
||||||
title: String,
|
title: String,
|
||||||
@@ -74,7 +75,7 @@ impl Video_Item {
|
|||||||
thumb: String,
|
thumb: String,
|
||||||
duration: u32,
|
duration: u32,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Video_Item {
|
VideoItem {
|
||||||
duration: duration, // Placeholder, adjust as needed
|
duration: duration, // Placeholder, adjust as needed
|
||||||
views: None, // Placeholder, adjust as needed
|
views: None, // Placeholder, adjust as needed
|
||||||
rating: None, // Placeholder, adjust as needed
|
rating: None, // Placeholder, adjust as needed
|
||||||
@@ -120,18 +121,18 @@ impl Video_Item {
|
|||||||
self.uploadedAt = Some(uploaded_at);
|
self.uploadedAt = Some(uploaded_at);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub fn formats(mut self, formats: Vec<Video_Format>) -> Self {
|
pub fn formats(mut self, formats: Vec<VideoFormat>) -> Self {
|
||||||
self.formats = Some(formats);
|
self.formats = Some(formats);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub fn embed(mut self, embed: Video_Embed) -> Self {
|
pub fn embed(mut self, embed: VideoEmbed) -> Self {
|
||||||
self.embed = Some(embed);
|
self.embed = Some(embed);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Serialize, Debug, Clone)]
|
#[derive(serde::Serialize, Debug, Clone)]
|
||||||
pub struct Video_Format {
|
pub struct VideoFormat {
|
||||||
url: String,
|
url: String,
|
||||||
quality: String,
|
quality: String,
|
||||||
format: String,
|
format: String,
|
||||||
@@ -159,9 +160,10 @@ pub struct Video_Format {
|
|||||||
http_headers: Option<HashMap<String, String>>,
|
http_headers: Option<HashMap<String, String>>,
|
||||||
|
|
||||||
}
|
}
|
||||||
impl Video_Format {
|
impl VideoFormat {
|
||||||
pub fn new(url: String, quality: String, format: String) -> Self {
|
pub fn new(url: String, quality: String, format: String) -> Self {
|
||||||
Video_Format {
|
let _ = format;
|
||||||
|
VideoFormat {
|
||||||
url,
|
url,
|
||||||
quality,
|
quality,
|
||||||
format: "mp4".to_string(), // Default format
|
format: "mp4".to_string(), // Default format
|
||||||
@@ -201,5 +203,5 @@ impl Video_Format {
|
|||||||
#[derive(serde::Serialize, Debug)]
|
#[derive(serde::Serialize, Debug)]
|
||||||
pub struct Videos {
|
pub struct Videos {
|
||||||
pub pageInfo: PageInfo,
|
pub pageInfo: PageInfo,
|
||||||
pub items: Vec<Video_Item>,
|
pub items: Vec<VideoItem>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user