This commit is contained in:
Simon
2025-09-03 12:15:08 +00:00
parent c3f994ccbb
commit ff18f3eb34
8 changed files with 279 additions and 132 deletions

View File

@@ -3,6 +3,7 @@ use std::env;
use error_chain::error_chain;
use htmlentity::entity::{decode, ICodedDataTrait};
use futures::future::join_all;
use scraper::ElementRef;
use wreq::Client;
use wreq::Proxy;
use wreq_util::Emulation;
@@ -15,28 +16,7 @@ use crate::videos::ServerOptions;
use crate::videos::{VideoItem};
use crate::DbPool;
use crate::util::requester::Requester;
use base64::{engine::general_purpose, Engine as _};
/// Extracts digits from a string and sums them.
fn ssut51(arg: &str) -> u32 {
arg.chars()
.filter(|c| c.is_ascii_digit())
.map(|c| c.to_digit(10).unwrap())
.sum()
}
/// Encodes a token: "<sum1>-<host>-<sum2>" using Base64 URL-safe variant.
fn boo(sum1: u32, sum2: u32, host: &str) -> String {
let raw = format!("{}-{}-{}", sum1, host, sum2);
let encoded = general_purpose::STANDARD.encode(raw);
// Replace + → -, / → _, = → .
encoded
.replace('+', "-")
.replace('/', "_")
.replace('=', ".")
}
use scraper::{Html, Selector};
error_chain! {
foreign_links {
@@ -46,6 +26,15 @@ error_chain! {
}
}
fn has_blacklisted_class(element: &ElementRef, blacklist: &[&str]) -> bool {
element
.value()
.attr("class")
.map(|classes| classes.split_whitespace().any(|c| blacklist.contains(&c)))
.unwrap_or(false)
}
#[derive(Debug, Clone)]
pub struct SxyprnProvider {
url: String,
@@ -58,12 +47,22 @@ impl SxyprnProvider {
}
async fn get(&self, cache:VideoCache, pool:DbPool, page: u8, sort: String, options: ServerOptions) -> Result<Vec<VideoItem>> {
let sort_string = match sort.as_str() {
"views" => "views",
"rating" => "rating",
"orgasmic" => "orgasmic",
_ => "latest",
};
// Extract needed fields from options at the start
let language = options.language.clone().unwrap();
let filter = options.filter.clone().unwrap();
let filter_string = match filter.as_str() {
"other" => "other",
"all" => "all",
_ => "top",
};
let mut requester = options.requester.clone().unwrap();
let url_str = format!("{}/blog/all/{}.html", self.url, ((page as u32)-1)*20);
let url_str = format!("{}/blog/all/{}.html?fl={}&sm={}", self.url, ((page as u32)-1)*20, filter_string, sort_string);
let old_items = match cache.get(&url_str) {
Some((time, items)) => {
@@ -92,14 +91,18 @@ impl SxyprnProvider {
}
async fn query(&self, cache: VideoCache, pool:DbPool, page: u8, query: &str, sort: String, options: ServerOptions) -> Result<Vec<VideoItem>> {
let sort_string = match sort.as_str() {
"views" => "views",
"rating" => "trending",
"orgasmic" => "orgasmic",
_ => "latest",
};
// Extract needed fields from options at the start
let language = options.language.clone().unwrap();
let filter = options.filter.clone().unwrap();
let mut requester = options.requester.clone().unwrap();
let search_string = query.replace(" ", "%20");
let search_string = query.replace(" ", "-");
let url_str = format!(
"{}/{}/search/{}?page={}&sort={}",
self.url, language, search_string, page, sort
"{}/{}.html?page={}&sm={}",
self.url, search_string, page, sort_string
);
// Check our Video Cache. If the result is younger than 1 hour, we return it.
let old_items = match cache.get(&url_str) {
@@ -136,116 +139,78 @@ impl SxyprnProvider {
.split("post_el_small'")
.collect::<Vec<&str>>()[1..]
.to_vec();
let mut urls: Vec<String> = vec![];
let mut items: Vec<VideoItem> = Vec::new();
for video_segment in &raw_videos {
let vid = video_segment.split("\n").collect::<Vec<&str>>();
for (index, line) in vid.iter().enumerate() {
println!("Line {}: {}", index, line.to_string().trim());
}
let url_str = video_segment.split("data-url='").collect::<Vec<&str>>()[1]
.split("'")
.collect::<Vec<&str>>()[0]
.to_string();
urls.push(url_str.clone());
break;
// let vid = video_segment.split("\n").collect::<Vec<&str>>();
// for (index, line) in vid.iter().enumerate() {
// println!("Line {}: {}", index, line.to_string().trim());
// }
// println!("\n\n\n");
}
let futures = urls.into_iter().map(|el| self.get_video_item(el.clone(), pool.clone(), requester.clone()));
let results: Vec<Result<VideoItem>> = join_all(futures).await;
let video_items: Vec<VideoItem> = results
.into_iter()
.filter_map(Result::ok)
.collect();
let video_url = format!("https://hottub.spacemoehre.de/proxy/sxyprn/post/{}",video_segment.split("/post/").collect::<Vec<&str>>()[1]
.split("'").collect::<Vec<&str>>()[0]
.to_string());
return video_items;
}
let mut title_parts = video_segment.split("post_text").collect::<Vec<&str>>()[1].split("style=''>").collect::<Vec<&str>>()[1]
.split("</div>")
.collect::<Vec<&str>>()[0]
;
println!("Title parts: {}", title_parts);
let document = Html::parse_document(title_parts);
let selector = Selector::parse("*").unwrap();
async fn get_video_item(&self, url_str: String, pool: DbPool, mut requester: Requester) -> Result<VideoItem> {
let mut conn = pool.get().expect("couldn't get db connection from pool");
let db_result = db::get_video(&mut conn,url_str.clone());
match db_result {
Ok(Some(entry)) => {
let video_item: VideoItem = serde_json::from_str(entry.as_str()).unwrap();
return Ok(video_item)
}
Ok(None) => {
}
Err(e) => {
println!("Error fetching video from database: {}", e);
}
}
drop(conn);
let vid = requester.get(&url_str).await.unwrap().to_string();
let mut title = vid.split("<title>").collect::<Vec<&str>>()[1]
.split(" #")
.collect::<Vec<&str>>()[0].trim()
.to_string();
title = decode(title.as_bytes()).to_string().unwrap_or(title);
let thumb = format!("https:{}", vid.split("<meta property='og:image' content='").collect::<Vec<&str>>()[1]
.split("\"")
.collect::<Vec<&str>>()[0]
.to_string());
let raw_duration = vid.split("duration:<b>").collect::<Vec<&str>>()[1]
.split("</b>")
.collect::<Vec<&str>>()[0]
.to_string();
let duration = raw_duration.parse::<u32>().unwrap_or(0);
let id = url_str.split("/").collect::<Vec<&str>>().last().unwrap().replace(".html", "")
.to_string();
let mut tags = vec![];
if vid.split("splitter_block_header").collect::<Vec<&str>>()[0].contains("hash_link"){
for tag_snippet in vid.split("splitter_block_header").collect::<Vec<&str>>()[0].split("hash_link").collect::<Vec<&str>>()[1..].to_vec(){
let tag = tag_snippet.split("<").collect::<Vec<&str>>()[0].trim()
.to_string();
if !tag.is_empty(){
tags.push(tag.replace("#", ""));
let mut texts = Vec::new();
for element in document.select(&selector) {
let text = element.text().collect::<Vec<_>>().join(" ");
if !text.trim().is_empty() {
texts.push(text.trim().to_string());
}
}
}
let video_url_pre_str = vid.split("data-vnfo").collect::<Vec<&str>>()[1]
.split("\":\"").collect::<Vec<&str>>()[1]
.split("\"").collect::<Vec<&str>>()[0]
.replace("\\", "")
.to_string();
println!("Video URL pre str: {}", video_url_pre_str);
let video_request = requester.get(&url_str).await.unwrap();
let mut video_url_parts = vid.split("m3u8").collect::<Vec<&str>>()[1]
.split("https").collect::<Vec<&str>>()[0]
.split("|").collect::<Vec<&str>>();
video_url_parts.reverse();
let video_url = format!("https://{}.{}/{}-{}-{}-{}-{}/playlist.m3u8",
video_url_parts[1],
video_url_parts[2],
video_url_parts[3],
video_url_parts[4],
video_url_parts[5],
video_url_parts[6],
video_url_parts[7]
);
let video_item = VideoItem::new(
id,
title,
video_url.clone(),
"sxyprn".to_string(),
thumb,
duration,
)
.tags(tags)
;
let mut conn = pool.get().expect("couldn't get db connection from pool");
let insert_result = db::insert_video(&mut conn, &url_str, &serde_json::to_string(&video_item)?);
match insert_result{
Ok(_) => (),
Err(e) => {println!("{:?}", e); }
}
drop(conn);
println!("Texts: {:?}", texts);
let mut title = texts[0].clone();
// html decode
title = decode(title.as_bytes()).to_string().unwrap_or(title).replace(" "," ");
return Ok(video_item);
// println!("Title: {}", title);
let id = video_url.split("/").collect::<Vec<&str>>()[6].to_string();
let thumb = format!("https:{}",video_segment.split("<img class='mini_post_vid_thumb lazyload'").collect::<Vec<&str>>()[1]
.split("data-src='").collect::<Vec<&str>>()[1]
.split("'")
.collect::<Vec<&str>>()[0]
.to_string());
let preview = format!("https:{}",video_segment
.split("class='hvp_player'").collect::<Vec<&str>>()[1]
.split(" src='").collect::<Vec<&str>>()[1]
.split("'")
.collect::<Vec<&str>>()[0]
.to_string());
let views= video_segment
.split("<strong>·</strong> ").collect::<Vec<&str>>()[1]
.split(" ")
.collect::<Vec<&str>>()[0]
.to_string();
let video_item = VideoItem::new(
id,
title,
video_url.to_string(),
"sxyprn".to_string(),
thumb,
0,
)
.preview(preview)
.views(views.parse::<u32>().unwrap_or(0))
;
items.push(video_item);
}
return items;
}
}
impl Provider for SxyprnProvider {