provider refactors and fixes
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use crate::DbPool;
|
||||
use crate::api::ClientVersion;
|
||||
use crate::db;
|
||||
use crate::providers::Provider;
|
||||
use crate::providers::{Provider, report_provider_error, report_provider_error_background};
|
||||
use crate::status::*;
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::util::time::parse_time_to_seconds;
|
||||
use crate::videos::ServerOptions;
|
||||
@@ -40,6 +42,42 @@ impl PerverzijaProvider {
|
||||
url: "https://tube.perverzija.com/".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn build_channel(&self, clientversion: ClientVersion) -> Channel {
|
||||
let _ = clientversion;
|
||||
|
||||
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(),
|
||||
status: "active".to_string(),
|
||||
categories: vec![],
|
||||
options: vec![ChannelOption {
|
||||
id: "featured".to_string(),
|
||||
title: "Featured".to_string(),
|
||||
description: "Filter Featured Videos.".to_string(),
|
||||
systemImage: "star".to_string(),
|
||||
colorName: "red".to_string(),
|
||||
options: vec![
|
||||
FilterOption {
|
||||
id: "all".to_string(),
|
||||
title: "No".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "featured".to_string(),
|
||||
title: "Yes".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
}],
|
||||
nsfw: true,
|
||||
cacheDuration: None,
|
||||
}
|
||||
}
|
||||
|
||||
async fn get(
|
||||
&self,
|
||||
cache: VideoCache,
|
||||
@@ -47,7 +85,7 @@ impl PerverzijaProvider {
|
||||
page: u8,
|
||||
options: ServerOptions,
|
||||
) -> Result<Vec<VideoItem>> {
|
||||
let featured = options.featured.unwrap_or("".to_string());
|
||||
let featured = options.featured.clone().unwrap_or("".to_string());
|
||||
let mut prefix_uri = "".to_string();
|
||||
if featured == "featured" {
|
||||
prefix_uri = "featured-scenes/".to_string();
|
||||
@@ -71,8 +109,20 @@ impl PerverzijaProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let text = requester.get(&url_str, Some(Version::HTTP_2)).await.unwrap();
|
||||
let mut requester =
|
||||
crate::providers::requester_or_default(&options, module_path!(), "missing_requester");
|
||||
let text = match requester.get(&url_str, Some(Version::HTTP_2)).await {
|
||||
Ok(text) => text,
|
||||
Err(e) => {
|
||||
report_provider_error(
|
||||
"perverzija",
|
||||
"get.request",
|
||||
&format!("url={url_str}; error={e}"),
|
||||
)
|
||||
.await;
|
||||
return Ok(old_items);
|
||||
}
|
||||
};
|
||||
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone(), pool);
|
||||
if !video_items.is_empty() {
|
||||
cache.remove(&url_str);
|
||||
@@ -122,8 +172,20 @@ impl PerverzijaProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let text = requester.get(&url_str, Some(Version::HTTP_2)).await.unwrap();
|
||||
let mut requester =
|
||||
crate::providers::requester_or_default(&options, module_path!(), "missing_requester");
|
||||
let text = match requester.get(&url_str, Some(Version::HTTP_2)).await {
|
||||
Ok(text) => text,
|
||||
Err(e) => {
|
||||
report_provider_error(
|
||||
"perverzija",
|
||||
"query.request",
|
||||
&format!("url={url_str}; error={e}"),
|
||||
)
|
||||
.await;
|
||||
return Ok(old_items);
|
||||
}
|
||||
};
|
||||
let video_items: Vec<VideoItem> = match query_parse {
|
||||
true => {
|
||||
self.get_video_items_from_html_query(text.clone(), pool)
|
||||
@@ -146,51 +208,61 @@ impl PerverzijaProvider {
|
||||
return vec![];
|
||||
}
|
||||
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>>().get(1).copied().unwrap_or_default();
|
||||
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>>();
|
||||
if vid.len() > 20 {
|
||||
if vid.len() > 20 || vid.len() < 8 {
|
||||
report_provider_error_background(
|
||||
"perverzija",
|
||||
"get_video_items_from_html.snippet_shape",
|
||||
&format!("unexpected snippet length={}", vid.len()),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
let line0 = vid.get(0).copied().unwrap_or_default();
|
||||
let line1 = vid.get(1).copied().unwrap_or_default();
|
||||
let line4 = vid.get(4).copied().unwrap_or_default();
|
||||
let line6 = vid.get(6).copied().unwrap_or_default();
|
||||
let line7 = vid.get(7).copied().unwrap_or_default();
|
||||
// for (index, line) in vid.iter().enumerate() {
|
||||
// println!("Line {}: {}", index, line.to_string().trim());
|
||||
// }
|
||||
let mut title = vid[1].split(">").collect::<Vec<&str>>()[1]
|
||||
let mut title = line1.split(">").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("<")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string();
|
||||
// html decode
|
||||
title = decode(title.as_bytes()).to_string().unwrap_or(title);
|
||||
if !vid[1].contains("iframe src="") {
|
||||
if !line1.contains("iframe src="") {
|
||||
continue;
|
||||
}
|
||||
let url_str = vid[1].split("iframe src="").collect::<Vec<&str>>()[1]
|
||||
let url_str = line1.split("iframe src="").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split(""")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string()
|
||||
.replace("index.php", "xs1.php");
|
||||
if url_str.starts_with("https://streamtape.com/") {
|
||||
continue; // Skip Streamtape links
|
||||
}
|
||||
let id = url_str.split("data=").collect::<Vec<&str>>()[1]
|
||||
let id = url_str.split("data=").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("&")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string();
|
||||
let raw_duration = match vid.len() {
|
||||
10 => vid[6].split("time_dur\">").collect::<Vec<&str>>()[1]
|
||||
10 => line6.split("time_dur\">").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("<")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string(),
|
||||
_ => "00:00".to_string(),
|
||||
};
|
||||
let duration = parse_time_to_seconds(&raw_duration).unwrap_or(0) as u32;
|
||||
|
||||
if !vid[4].contains("srcset=")
|
||||
&& vid[4].split("src=\"").collect::<Vec<&str>>().len() == 1
|
||||
if !line4.contains("srcset=")
|
||||
&& line4.split("src=\"").collect::<Vec<&str>>().len() == 1
|
||||
{
|
||||
for (index, line) in vid.iter().enumerate() {
|
||||
println!("Line {}: {}\n\n", index, line);
|
||||
@@ -201,45 +273,54 @@ impl PerverzijaProvider {
|
||||
for v in vid.clone() {
|
||||
let line = v.trim();
|
||||
if line.starts_with("<img ") {
|
||||
thumb = line.split(" src=\"").collect::<Vec<&str>>()[1]
|
||||
thumb = line.split(" src=\"").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string();
|
||||
}
|
||||
}
|
||||
let embed_html = vid[1].split("data-embed='").collect::<Vec<&str>>()[1]
|
||||
let embed_html = line1.split("data-embed='").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("'")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string();
|
||||
let id_url = vid[1].split("data-url='").collect::<Vec<&str>>()[1]
|
||||
let id_url = line1.split("data-url='").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("'")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string();
|
||||
|
||||
let mut conn = pool.get().expect("couldn't get db connection from pool");
|
||||
let _ = db::insert_video(&mut conn, &id_url, &url_str);
|
||||
drop(conn);
|
||||
match pool.get() {
|
||||
Ok(mut conn) => {
|
||||
let _ = db::insert_video(&mut conn, &id_url, &url_str);
|
||||
}
|
||||
Err(e) => {
|
||||
report_provider_error_background(
|
||||
"perverzija",
|
||||
"get_video_items_from_html.insert_video.pool_get",
|
||||
&e.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
let referer_url = "https://xtremestream.xyz/".to_string();
|
||||
let embed = VideoEmbed::new(embed_html, url_str.clone());
|
||||
|
||||
let mut tags: Vec<String> = Vec::new(); // Placeholder for tags, adjust as needed
|
||||
|
||||
let studios_parts = vid[7].split("a href=\"").collect::<Vec<&str>>();
|
||||
let studios_parts = line7.split("a href=\"").collect::<Vec<&str>>();
|
||||
for studio in studios_parts.iter().skip(1) {
|
||||
if studio.starts_with("https://tube.perverzija.com/studio/") {
|
||||
tags.push(
|
||||
studio.split("/\"").collect::<Vec<&str>>()[0]
|
||||
studio.split("/\"").collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.replace("https://tube.perverzija.com/studio/", "@studio:")
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for tag in vid[0].split(" ").collect::<Vec<&str>>() {
|
||||
for tag in line0.split(" ").collect::<Vec<&str>>() {
|
||||
if tag.starts_with("stars-") {
|
||||
let tag_name = tag.split("stars-").collect::<Vec<&str>>()[1]
|
||||
let tag_name = tag.split("stars-").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string();
|
||||
if !tag_name.is_empty() {
|
||||
tags.push(format!("@stars:{}", tag_name));
|
||||
@@ -247,9 +328,9 @@ impl PerverzijaProvider {
|
||||
}
|
||||
}
|
||||
|
||||
for tag in vid[0].split(" ").collect::<Vec<&str>>() {
|
||||
for tag in line0.split(" ").collect::<Vec<&str>>() {
|
||||
if tag.starts_with("tag-") {
|
||||
let tag_name = tag.split("tag-").collect::<Vec<&str>>()[1].to_string();
|
||||
let tag_name = tag.split("tag-").collect::<Vec<&str>>().get(1).copied().unwrap_or_default().to_string();
|
||||
if !tag_name.is_empty() {
|
||||
tags.push(tag_name.replace("-", " ").to_string());
|
||||
}
|
||||
@@ -292,37 +373,55 @@ impl PerverzijaProvider {
|
||||
|
||||
async fn get_video_item(&self, snippet: &str, pool: DbPool) -> Result<VideoItem> {
|
||||
let vid = snippet.split("\n").collect::<Vec<&str>>();
|
||||
if vid.len() > 30 {
|
||||
if vid.len() > 30 || vid.len() < 7 {
|
||||
report_provider_error_background(
|
||||
"perverzija",
|
||||
"get_video_item.snippet_shape",
|
||||
&format!("unexpected snippet length={}", vid.len()),
|
||||
);
|
||||
return Err("Unexpected video snippet length".into());
|
||||
}
|
||||
let line5 = vid.get(5).copied().unwrap_or_default();
|
||||
let line6 = vid.get(6).copied().unwrap_or_default();
|
||||
|
||||
let mut title = vid[5].split(" title=\"").collect::<Vec<&str>>()[1]
|
||||
let mut title = line5.split(" title=\"").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string();
|
||||
title = decode(title.as_bytes()).to_string().unwrap_or(title);
|
||||
|
||||
let thumb = match vid[6].split(" src=\"").collect::<Vec<&str>>().len() {
|
||||
let thumb = match line6.split(" src=\"").collect::<Vec<&str>>().len() {
|
||||
1 => {
|
||||
for (index, line) in vid.iter().enumerate() {
|
||||
println!("Line {}: {}", index, line.to_string().trim());
|
||||
}
|
||||
return Err("Failed to parse thumbnail URL".into());
|
||||
}
|
||||
_ => vid[6].split(" src=\"").collect::<Vec<&str>>()[1]
|
||||
_ => line6.split(" src=\"").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string(),
|
||||
};
|
||||
let duration = 0;
|
||||
|
||||
let lookup_url = vid[5].split(" href=\"").collect::<Vec<&str>>()[1]
|
||||
let lookup_url = line5.split(" href=\"").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string();
|
||||
let referer_url = "https://xtremestream.xyz/".to_string();
|
||||
|
||||
let mut conn = pool.get().expect("couldn't get db connection from pool");
|
||||
let mut conn = match pool.get() {
|
||||
Ok(conn) => conn,
|
||||
Err(e) => {
|
||||
report_provider_error(
|
||||
"perverzija",
|
||||
"get_video_item.pool_get",
|
||||
&e.to_string(),
|
||||
)
|
||||
.await;
|
||||
return Err("couldn't get db connection from pool".into());
|
||||
}
|
||||
};
|
||||
let db_result = db::get_video(&mut conn, lookup_url.clone());
|
||||
match db_result {
|
||||
Ok(Some(entry)) => {
|
||||
@@ -334,9 +433,9 @@ impl PerverzijaProvider {
|
||||
if url_str.starts_with("!") {
|
||||
return Err("Video was removed".into());
|
||||
}
|
||||
let mut id = url_str.split("data=").collect::<Vec<&str>>()[1].to_string();
|
||||
let mut id = url_str.split("data=").collect::<Vec<&str>>().get(1).copied().unwrap_or_default().to_string();
|
||||
if id.contains("&") {
|
||||
id = id.split("&").collect::<Vec<&str>>()[0].to_string()
|
||||
id = id.split("&").collect::<Vec<&str>>().get(0).copied().unwrap_or_default().to_string()
|
||||
}
|
||||
let mut video_item = VideoItem::new(
|
||||
id,
|
||||
@@ -382,9 +481,9 @@ impl PerverzijaProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let mut url_str = text.split("<iframe src=\"").collect::<Vec<&str>>()[1]
|
||||
let mut url_str = text.split("<iframe src=\"").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.to_string()
|
||||
.replace("index.php", "xs1.php");
|
||||
if !url_str.contains("xtremestream.xyz") {
|
||||
@@ -395,15 +494,15 @@ impl PerverzijaProvider {
|
||||
|
||||
let studios_parts = text
|
||||
.split("<strong>Studio: </strong>")
|
||||
.collect::<Vec<&str>>()[1]
|
||||
.collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("</div>")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.split("<a href=\"")
|
||||
.collect::<Vec<&str>>();
|
||||
for studio in studios_parts.iter().skip(1) {
|
||||
if studio.starts_with("https://tube.perverzija.com/studio/") {
|
||||
tags.push(
|
||||
studio.split("/\"").collect::<Vec<&str>>()[0]
|
||||
studio.split("/\"").collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.replace("https://tube.perverzija.com/studio/", "@studio:")
|
||||
.to_string(),
|
||||
);
|
||||
@@ -412,15 +511,15 @@ impl PerverzijaProvider {
|
||||
if text.contains("<strong>Stars: </strong>") {
|
||||
let stars_parts: Vec<&str> = text
|
||||
.split("<strong>Stars: </strong>")
|
||||
.collect::<Vec<&str>>()[1]
|
||||
.collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("</div>")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.split("<a href=\"")
|
||||
.collect::<Vec<&str>>();
|
||||
for star in stars_parts.iter().skip(1) {
|
||||
if star.starts_with("https://tube.perverzija.com/stars/") {
|
||||
tags.push(
|
||||
star.split("/\"").collect::<Vec<&str>>()[0]
|
||||
star.split("/\"").collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.replace("https://tube.perverzija.com/stars/", "@stars:")
|
||||
.to_string(),
|
||||
);
|
||||
@@ -428,15 +527,15 @@ impl PerverzijaProvider {
|
||||
}
|
||||
}
|
||||
|
||||
let tags_parts: Vec<&str> = text.split("<strong>Tags: </strong>").collect::<Vec<&str>>()[1]
|
||||
let tags_parts: Vec<&str> = text.split("<strong>Tags: </strong>").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("</div>")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.split("<a href=\"")
|
||||
.collect::<Vec<&str>>();
|
||||
for star in tags_parts.iter().skip(1) {
|
||||
if star.starts_with("https://tube.perverzija.com/stars/") {
|
||||
tags.push(
|
||||
star.split("/\"").collect::<Vec<&str>>()[0]
|
||||
star.split("/\"").collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.replace("https://tube.perverzija.com/stars/", "@stars:")
|
||||
.to_string(),
|
||||
);
|
||||
@@ -447,25 +546,37 @@ impl PerverzijaProvider {
|
||||
url_string: url_str.clone(),
|
||||
tags_strings: tags.clone(),
|
||||
};
|
||||
let mut conn = pool.get().expect("couldn't get db connection from pool");
|
||||
let insert_result = db::insert_video(
|
||||
&mut conn,
|
||||
&lookup_url,
|
||||
&serde_json::to_string(&perverzija_db_entry)?,
|
||||
);
|
||||
match insert_result {
|
||||
Ok(_) => (),
|
||||
match pool.get() {
|
||||
Ok(mut conn) => {
|
||||
let insert_result = db::insert_video(
|
||||
&mut conn,
|
||||
&lookup_url,
|
||||
&serde_json::to_string(&perverzija_db_entry)?,
|
||||
);
|
||||
if let Err(e) = insert_result {
|
||||
report_provider_error(
|
||||
"perverzija",
|
||||
"get_video_item.insert_video",
|
||||
&e.to_string(),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{:?}", e);
|
||||
report_provider_error(
|
||||
"perverzija",
|
||||
"get_video_item.insert_video.pool_get",
|
||||
&e.to_string(),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
drop(conn);
|
||||
if !url_str.contains("xtremestream.xyz") {
|
||||
return Err("Video URL does not contain xtremestream.xyz".into());
|
||||
}
|
||||
let mut id = url_str.split("data=").collect::<Vec<&str>>()[1].to_string();
|
||||
let mut id = url_str.split("data=").collect::<Vec<&str>>().get(1).copied().unwrap_or_default().to_string();
|
||||
if id.contains("&") {
|
||||
id = id.split("&").collect::<Vec<&str>>()[0].to_string()
|
||||
id = id.split("&").collect::<Vec<&str>>().get(0).copied().unwrap_or_default().to_string()
|
||||
}
|
||||
// if !vid[6].contains(" src=\""){
|
||||
// for (index,line) in vid.iter().enumerate() {
|
||||
@@ -530,4 +641,8 @@ impl Provider for PerverzijaProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_channel(&self, clientversion: ClientVersion) -> Option<Channel> {
|
||||
Some(self.build_channel(clientversion))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user