init
This commit is contained in:
6
src/providers/mod.rs
Normal file
6
src/providers/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use crate::videos::{Video_Item, Videos};
|
||||
|
||||
pub mod perverzija;
|
||||
pub trait Provider{
|
||||
async fn get_videos(&self, channel: String, sort: String, query: Option<String>, page: String, per_page: String, featured: String) -> Vec<Video_Item>;
|
||||
}
|
||||
175
src/providers/perverzija.rs
Normal file
175
src/providers/perverzija.rs
Normal file
@@ -0,0 +1,175 @@
|
||||
use std::vec;
|
||||
|
||||
use error_chain::error_chain;
|
||||
use htmlentity::entity::{decode, encode, CharacterSet, EncodeType, ICodedDataTrait};
|
||||
use htmlentity::types::{AnyhowResult, Byte};
|
||||
use reqwest::Proxy;
|
||||
|
||||
use crate::providers::Provider;
|
||||
use crate::util::time::parse_time_to_seconds;
|
||||
use crate::videos::{self, PageInfo, Video_Embed, Video_Item, Videos}; // Make sure Provider trait is imported
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
Io(std::io::Error);
|
||||
HttpRequest(reqwest::Error);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PerverzijaProvider {
|
||||
url: String,
|
||||
}
|
||||
impl PerverzijaProvider {
|
||||
pub fn new() -> Self {
|
||||
PerverzijaProvider {
|
||||
url: "https://tube.perverzija.com/".to_string(),
|
||||
}
|
||||
}
|
||||
async fn get(&self, page: &u8, featured: String) -> Result<Vec<Video_Item>> {
|
||||
let mut prefix_uri = "".to_string();
|
||||
if featured == "featured"{
|
||||
prefix_uri = "featured-scenes/".to_string();
|
||||
}
|
||||
let mut url = format!("{}{}page/{}/", self.url, prefix_uri, page);
|
||||
if page == &1 {
|
||||
url = format!("{}{}", self.url, prefix_uri);
|
||||
}
|
||||
let client = reqwest::Client::builder()
|
||||
.user_agent("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15")
|
||||
// .proxy(Proxy::https("http://192.168.0.101:8080").unwrap())
|
||||
// .danger_accept_invalid_certs(true)
|
||||
.build()?;
|
||||
let response = client.get(url).send().await?;
|
||||
|
||||
if response.status().is_success() {
|
||||
let text = response.text().await?;
|
||||
let video_items = self.get_video_items_from_html(text.clone());
|
||||
Ok(video_items)
|
||||
} else {
|
||||
Err("Failed to fetch data".into())
|
||||
}
|
||||
}
|
||||
fn query(&self, query: &str) -> Result<Vec<Video_Item>> {
|
||||
println!("Searching for query: {}", query);
|
||||
let url = format!("{}?s={}", self.url, query);
|
||||
let client = reqwest::blocking::Client::new();
|
||||
let response = client.get(&url).send()?;
|
||||
if response.status().is_success() {
|
||||
let text = response.text().unwrap_or_default();
|
||||
|
||||
println!("{}", &text);
|
||||
Ok(vec![])
|
||||
} else {
|
||||
Err("Failed to fetch data".into())
|
||||
}
|
||||
}
|
||||
|
||||
fn get_video_items_from_html(&self, html: String) -> Vec<Video_Item> {
|
||||
let mut items: Vec<Video_Item> = Vec::new();
|
||||
|
||||
let raw_html = html.split("video-listing-content").collect::<Vec<&str>>();
|
||||
|
||||
let video_listing_content = raw_html[1];
|
||||
let raw_videos = video_listing_content
|
||||
.split("video-item post")
|
||||
.collect::<Vec<&str>>()[1..]
|
||||
.to_vec();
|
||||
|
||||
for video_segment in &raw_videos {
|
||||
|
||||
let vid = video_segment.split("\n").collect::<Vec<&str>>();
|
||||
let mut index = 0;
|
||||
if vid.len() > 10 {
|
||||
|
||||
continue;
|
||||
}
|
||||
for line in vid.clone(){
|
||||
println!("{}: {}\n\n", index, line);
|
||||
index += 1;
|
||||
}
|
||||
|
||||
let mut title = vid[1].split(">").collect::<Vec<&str>>()[1]
|
||||
.split("<")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.to_string();
|
||||
// html decode
|
||||
title = decode(title.as_bytes()).to_string().unwrap_or(title);
|
||||
let url = vid[1].split("iframe src="").collect::<Vec<&str>>()[1]
|
||||
.split(""")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.to_string().replace("index.php", "xs1.php");;
|
||||
let id = url.split("data=").collect::<Vec<&str>>()[1]
|
||||
.split("&")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.to_string();
|
||||
let raw_duration = match vid.len(){
|
||||
10 => vid[6].split("time_dur\">").collect::<Vec<&str>>()[1]
|
||||
.split("<")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.to_string(),
|
||||
_ => "00:00".to_string(),
|
||||
};
|
||||
let duration = parse_time_to_seconds(&raw_duration).unwrap_or(0) as u32;
|
||||
|
||||
let thumb = match vid[4].contains("srcset=") {
|
||||
true => vid[4].split("sizes=").collect::<Vec<&str>>()[1]
|
||||
.split("w, ")
|
||||
.collect::<Vec<&str>>()
|
||||
.last()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.split(" ")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.to_string(),
|
||||
false => vid[4].split("src=\"").collect::<Vec<&str>>()[1]
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.to_string(),
|
||||
};
|
||||
let mut embed_html = vid[1].split("data-embed='").collect::<Vec<&str>>()[1].split("'").collect::<Vec<&str>>()[0]
|
||||
.to_string();
|
||||
embed_html = embed_html.replace("index.php", "xs1.php");
|
||||
|
||||
println!("Embed HTML: {}\n\n", embed_html);
|
||||
println!("Url: {}\n\n", url.clone());
|
||||
let embed = Video_Embed::new(embed_html, url.clone());
|
||||
let mut video_item =
|
||||
Video_Item::new(id, title, url.clone(), "perverzija".to_string(), thumb, duration);
|
||||
video_item.embed = Some(embed);
|
||||
let mut format = videos::Video_Format::new(url.clone(), "1080".to_string(), "m3u8".to_string());
|
||||
format.add_http_header("Referer".to_string(), url.clone().replace("xs1.php", "index.php"));
|
||||
if let Some(formats) = video_item.formats.as_mut() {
|
||||
formats.push(format);
|
||||
} else {
|
||||
video_item.formats = Some(vec![format]);
|
||||
}
|
||||
items.push(video_item);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
impl Provider for PerverzijaProvider {
|
||||
async fn get_videos(
|
||||
&self,
|
||||
_channel: String,
|
||||
sort: String,
|
||||
query: Option<String>,
|
||||
page: String,
|
||||
per_page: String,
|
||||
featured: String,
|
||||
) -> Vec<Video_Item> {
|
||||
let _ = sort;
|
||||
let videos: std::result::Result<Vec<Video_Item>, Error> = match query {
|
||||
Some(q) => self.query(&q),
|
||||
None => self.get(&page.parse::<u8>().unwrap_or(1), featured).await,
|
||||
};
|
||||
match videos {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
println!("Error fetching videos: {}", e);
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user