now supports sites

This commit is contained in:
Simon
2025-10-04 17:40:03 +00:00
parent 43a2d09a55
commit 7c73601954
2 changed files with 65 additions and 32 deletions

View File

@@ -10,8 +10,8 @@ use async_trait::async_trait;
use error_chain::error_chain; use error_chain::error_chain;
use htmlentity::entity::{ICodedDataTrait, decode}; use htmlentity::entity::{ICodedDataTrait, decode};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use std::thread;
use std::vec; use std::vec;
use std::{env, thread};
error_chain! { error_chain! {
foreign_links { foreign_links {
@@ -30,8 +30,14 @@ impl OmgxxxProvider {
pub fn new() -> Self { pub fn new() -> Self {
let provider = OmgxxxProvider { let provider = OmgxxxProvider {
url: "https://www.omg.xxx".to_string(), url: "https://www.omg.xxx".to_string(),
sites: Arc::new(RwLock::new(vec![])), sites: Arc::new(RwLock::new(vec![FilterOption {
networks: Arc::new(RwLock::new(vec![FilterOption{id:"all".to_string(),title:"All".to_string()}])), id: "all".to_string(),
title: "All".to_string(),
}])),
networks: Arc::new(RwLock::new(vec![FilterOption {
id: "all".to_string(),
title: "All".to_string(),
}])),
}; };
// Kick off the background load but return immediately // Kick off the background load but return immediately
@@ -41,7 +47,7 @@ impl OmgxxxProvider {
fn spawn_initial_load(&self) { fn spawn_initial_load(&self) {
let url = self.url.clone(); let url = self.url.clone();
// let sites = Arc::clone(&self.sites); let sites = Arc::clone(&self.sites);
let networks = Arc::clone(&self.networks); let networks = Arc::clone(&self.networks);
thread::spawn(move || { thread::spawn(move || {
@@ -53,9 +59,9 @@ impl OmgxxxProvider {
rt.block_on(async move { rt.block_on(async move {
// If you have a streaming sites loader, call it here too // If you have a streaming sites loader, call it here too
// if let Err(e) = Self::load_sites_into(&url, sites).await { if let Err(e) = Self::load_sites(&url, sites).await {
// eprintln!("load_sites_into failed: {e}"); eprintln!("load_sites_into failed: {e}");
// } }
if let Err(e) = Self::load_networks(&url, networks).await { if let Err(e) = Self::load_networks(&url, networks).await {
eprintln!("load_networks failed: {e}"); eprintln!("load_networks failed: {e}");
@@ -64,23 +70,44 @@ impl OmgxxxProvider {
}); });
} }
/// === separate, self-contained logic === async fn load_sites(base_url: &str, networks: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
/// Replace the bodies with your real fetching/parsing code. let mut requester = util::requester::Requester::new();
// async fn load_sites(base_url: &str) -> Result<Vec<FilterOption>> { requester.set_proxy(env::var("PROXY").unwrap_or("0".to_string()) != "0".to_string());
// // Example stub: let mut page = 0;
// // let html = reqwest::blocking::get(format!("{}/sites/", base_url))?.text()?; loop {
// // Ok(parse_sites_from_html(&html)) page += 1;
// Ok(vec![ let text = requester
// FilterOption { .get(format!("{}/sites/{}/", &base_url, page).as_str())
// id: "site-a".into(), .await
// title: "Site A".into(), .unwrap();
// }, if text.contains("404 Not Found") || text.is_empty() {
// FilterOption { break;
// id: "site-b".into(), }
// title: "Site B".into(), let sites_div = text
// }, .split("id=\"list_content_sources_sponsors_list_items\"").collect::<Vec<&str>>()[1]
// ]) .split("class=\"pagination\"").collect::<Vec<&str>>()[0];
// } for sites_element in
sites_div.split("class=\"headline\"").collect::<Vec<&str>>()[1..].to_vec()
{
let site_url = sites_element.split("href=\"").collect::<Vec<&str>>()[1]
.split("\"")
.collect::<Vec<&str>>()[0];
let site_id = site_url.split("/").collect::<Vec<&str>>()[4].to_string();
let site_name = sites_element.split("<h2>").collect::<Vec<&str>>()[1]
.split("<")
.collect::<Vec<&str>>()[0]
.to_string();
Self::push_unique(
&networks,
FilterOption {
id: site_id,
title: site_name,
},
);
}
}
return Ok(());
}
async fn load_networks(base_url: &str, networks: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> { async fn load_networks(base_url: &str, networks: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
let mut requester = util::requester::Requester::new(); let mut requester = util::requester::Requester::new();
@@ -88,8 +115,12 @@ impl OmgxxxProvider {
let networks_div = text.split("class=\"sites__list\"").collect::<Vec<&str>>()[1] let networks_div = text.split("class=\"sites__list\"").collect::<Vec<&str>>()[1]
.split("</div>") .split("</div>")
.collect::<Vec<&str>>()[0]; .collect::<Vec<&str>>()[0];
for network_element in networks_div.split("sites__item").collect::<Vec<&str>>()[1..].to_vec() { for network_element in
if network_element.contains("sites__all"){continue;} networks_div.split("sites__item").collect::<Vec<&str>>()[1..].to_vec()
{
if network_element.contains("sites__all") {
continue;
}
let network_url = network_element.split("href=\"").collect::<Vec<&str>>()[1] let network_url = network_element.split("href=\"").collect::<Vec<&str>>()[1]
.split("\"") .split("\"")
.collect::<Vec<&str>>()[0]; .collect::<Vec<&str>>()[0];
@@ -137,7 +168,7 @@ impl OmgxxxProvider {
Channel { Channel {
id: "omgxxx".to_string(), id: "omgxxx".to_string(),
name: "OMG XXX".to_string(), name: "OMG XXX".to_string(),
description: "Free Porn Site".to_string(), description: "OMG look at that Collection!".to_string(),
premium: false, premium: false,
favicon: "https://www.google.com/s2/favicons?sz=64&domain=www.omg.xxx".to_string(), favicon: "https://www.google.com/s2/favicons?sz=64&domain=www.omg.xxx".to_string(),
status: "active".to_string(), status: "active".to_string(),
@@ -201,7 +232,10 @@ impl OmgxxxProvider {
"most-popular" => "most-popular".to_string(), "most-popular" => "most-popular".to_string(),
_ => "latest-updates".to_string(), _ => "latest-updates".to_string(),
}; };
if options.network.is_some() && !options.network.as_ref().unwrap().is_empty() && options.network.as_ref().unwrap() != "all" { if options.network.is_some()
&& !options.network.as_ref().unwrap().is_empty()
&& options.network.as_ref().unwrap() != "all"
{
sort_string = format!("networks/{}", options.network.as_ref().unwrap()); sort_string = format!("networks/{}", options.network.as_ref().unwrap());
} }
let video_url = format!("{}/{}/{}/", self.url, sort_string, page); let video_url = format!("{}/{}/{}/", self.url, sort_string, page);
@@ -219,7 +253,6 @@ impl OmgxxxProvider {
} }
}; };
let mut requester = options.requester.clone().unwrap(); let mut requester = options.requester.clone().unwrap();
let text = requester.get(&video_url).await.unwrap(); let text = requester.get(&video_url).await.unwrap();
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone()); let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone());

View File

@@ -118,7 +118,7 @@ impl Requester {
let response = request.send().await?; let response = request.send().await?;
if response.status().is_success() { if response.status().is_success() || response.status().as_u16() == 404 {
return Ok(response.text().await?); return Ok(response.text().await?);
} }