hypnotube
This commit is contained in:
@@ -208,7 +208,7 @@ impl HanimeProvider {
|
||||
.ordering(ordering);
|
||||
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let response = requester.post("https://search.htv-services.com/search", &search, vec![]).await.unwrap();
|
||||
let response = requester.post_json("https://search.htv-services.com/search", &search, vec![]).await.unwrap();
|
||||
|
||||
|
||||
|
||||
|
||||
417
src/providers/hypnotube.rs
Normal file
417
src/providers/hypnotube.rs
Normal file
@@ -0,0 +1,417 @@
|
||||
use crate::DbPool;
|
||||
use crate::api::ClientVersion;
|
||||
use crate::providers::Provider;
|
||||
use crate::status::*;
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::util::discord::send_discord_error_report;
|
||||
use crate::util::requester::Requester;
|
||||
use crate::util::time::parse_time_to_seconds;
|
||||
use crate::videos::{ServerOptions, VideoItem};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use error_chain::error_chain;
|
||||
use htmlentity::entity::{decode, ICodedDataTrait};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::{thread, vec};
|
||||
use titlecase::Titlecase;
|
||||
use wreq::Version;
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
Io(std::io::Error);
|
||||
HttpRequest(wreq::Error);
|
||||
Json(serde_json::Error);
|
||||
}
|
||||
errors {
|
||||
Parse(msg: String) {
|
||||
description("parse error")
|
||||
display("parse error: {}", msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct HypnotubeProvider {
|
||||
url: String,
|
||||
categories: Arc<RwLock<Vec<FilterOption>>>,
|
||||
}
|
||||
|
||||
impl HypnotubeProvider {
|
||||
pub fn new() -> Self {
|
||||
let provider = Self {
|
||||
url: "https://hypnotube.com".to_string(),
|
||||
categories: Arc::new(RwLock::new(vec![])),
|
||||
};
|
||||
provider.spawn_initial_load();
|
||||
provider
|
||||
}
|
||||
|
||||
fn spawn_initial_load(&self) {
|
||||
let url = self.url.clone();
|
||||
let categories = Arc::clone(&self.categories);
|
||||
|
||||
thread::spawn(move || {
|
||||
let rt = match tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
{
|
||||
Ok(rt) => rt,
|
||||
Err(e) => {
|
||||
eprintln!("tokio runtime failed: {e}");
|
||||
let _ = futures::executor::block_on(send_discord_error_report(
|
||||
&e,
|
||||
Some("HypnoTube Provider"),
|
||||
Some("Failed to create tokio runtime"),
|
||||
file!(),
|
||||
line!(),
|
||||
module_path!(),
|
||||
));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
rt.block_on(async {
|
||||
if let Err(e) = Self::load_categories(&url, Arc::clone(&categories)).await {
|
||||
eprintln!("load_categories failed: {e}");
|
||||
send_discord_error_report(
|
||||
&e,
|
||||
Some("HypnoTube Provider"),
|
||||
Some("Failed to load categories during initial load"),
|
||||
file!(),
|
||||
line!(),
|
||||
module_path!(),
|
||||
).await;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async fn load_categories(base: &str, cats: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
let mut requester = Requester::new();
|
||||
let text = requester
|
||||
.get(
|
||||
&format!("{base}/channels/"),
|
||||
Some(Version::HTTP_11),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| Error::from(format!("{}", e)))?;
|
||||
|
||||
let block = text
|
||||
.split(" title END ")
|
||||
.last()
|
||||
.ok_or_else(|| ErrorKind::Parse("categories block".into()))?
|
||||
.split(" main END ")
|
||||
.next()
|
||||
.unwrap_or("");
|
||||
|
||||
for el in block.split("<!-- item -->").skip(1) {
|
||||
let id = el
|
||||
.split("<a href=\"https://hypnotube.com/channels/")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split("/\"").next())
|
||||
.ok_or_else(|| ErrorKind::Parse(format!("category id: {el}").into()))?
|
||||
.to_string();
|
||||
|
||||
let title = el
|
||||
.split("title=\"")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split("\"").next())
|
||||
.ok_or_else(|| ErrorKind::Parse(format!("category title: {el}").into()))?
|
||||
.titlecase();
|
||||
|
||||
Self::push_unique(&cats, FilterOption { id, title });
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_channel(&self, clientversion: ClientVersion) -> Channel {
|
||||
let _ = clientversion;
|
||||
Channel {
|
||||
id: "hypnotube".to_string(),
|
||||
name: "Hypnotube".to_string(),
|
||||
description: "free video hypno tube for the sissy hypnosis porn fetish".to_string(),
|
||||
premium: false,
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=hypnotube.com".to_string(),
|
||||
status: "active".to_string(),
|
||||
categories: self
|
||||
.categories
|
||||
.read()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|c| c.title.clone())
|
||||
.collect(),
|
||||
options: vec![
|
||||
ChannelOption {
|
||||
id: "sort".to_string(),
|
||||
title: "Sort".to_string(),
|
||||
description: "Sort the Videos".to_string(),
|
||||
systemImage: "list.number".to_string(),
|
||||
colorName: "blue".to_string(),
|
||||
options: vec![
|
||||
FilterOption {
|
||||
id: "most recent".into(),
|
||||
title: "Most Recent".into(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "most viewed".into(),
|
||||
title: "Most Viewed".into(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "top rated".into(),
|
||||
title: "Top Rated".into(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "longest".into(),
|
||||
title: "Longest".into(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
}],
|
||||
nsfw: true,
|
||||
cacheDuration: Some(1800),
|
||||
}
|
||||
}
|
||||
|
||||
fn push_unique(target: &Arc<RwLock<Vec<FilterOption>>>, item: FilterOption) {
|
||||
if let Ok(mut vec) = target.write() {
|
||||
if !vec.iter().any(|x| x.id == item.id) {
|
||||
vec.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn get(
|
||||
&self,
|
||||
cache: VideoCache,
|
||||
page: u8,
|
||||
sort: &str,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let sort_string = match sort {
|
||||
"top rated" => "top-rated",
|
||||
"most viewed" => "most-viewed",
|
||||
"longest" => "longest",
|
||||
_ => "videos",
|
||||
};
|
||||
let video_url = format!(
|
||||
"{}/{}/page{}.html",
|
||||
self.url, sort_string, page
|
||||
);
|
||||
let old_items = match cache.get(&video_url) {
|
||||
Some((time, items)) => {
|
||||
if time.elapsed().unwrap_or_default().as_secs() < 60 * 5 {
|
||||
return items.clone();
|
||||
} else {
|
||||
items.clone()
|
||||
}
|
||||
}
|
||||
None => {
|
||||
vec![]
|
||||
}
|
||||
};
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let text = requester.get(&video_url, Some(Version::HTTP_11)).await.unwrap();
|
||||
if text.contains("Sorry, no results were found.") {
|
||||
eprint!("Hypnotube query returned no results for page {}", page);
|
||||
return vec![];
|
||||
}
|
||||
let video_items: Vec<VideoItem> = self
|
||||
.get_video_items_from_html(text.clone())
|
||||
.await;
|
||||
if !video_items.is_empty() {
|
||||
cache.remove(&video_url);
|
||||
cache.insert(video_url.clone(), video_items.clone());
|
||||
} else {
|
||||
return old_items;
|
||||
}
|
||||
video_items
|
||||
}
|
||||
|
||||
async fn query(
|
||||
&self,
|
||||
cache: VideoCache,
|
||||
page: u8,
|
||||
query: &str,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let sort_string = match options.sort.as_deref().unwrap_or("") {
|
||||
"top rated" => "rating",
|
||||
"most viewed" => "views",
|
||||
"longest" => "longest",
|
||||
_ => "newest",
|
||||
};
|
||||
let video_url = format!(
|
||||
"{}/search/videos/{}/{}/page{}.html",
|
||||
self.url, query.trim().replace(" ","%20"), sort_string, page
|
||||
);
|
||||
// Check our Video Cache. If the result is younger than 1 hour, we return it.
|
||||
let old_items = match cache.get(&video_url) {
|
||||
Some((time, items)) => {
|
||||
if time.elapsed().unwrap_or_default().as_secs() < 60 * 5 {
|
||||
return items.clone();
|
||||
} else {
|
||||
let _ = cache.check().await;
|
||||
return items.clone();
|
||||
}
|
||||
}
|
||||
None => {
|
||||
vec![]
|
||||
}
|
||||
};
|
||||
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let text = match requester.post(format!("{}/searchgate.php", self.url).as_str(), format!("q={}&type=videos", query.replace(" ","+")).as_str(), vec![("Content-Type", "application/x-www-form-urlencoded")]).await.unwrap().text().await {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
eprint!("Hypnotube search POST request failed: {}", e);
|
||||
return vec![];
|
||||
}
|
||||
};
|
||||
// println!("Hypnotube search POST response status: {}", p.text().await.unwrap_or_default());
|
||||
// let text = requester.get(&video_url, Some(Version::HTTP_11)).await.unwrap();
|
||||
if text.contains("Sorry, no results were found.") {
|
||||
eprint!("Hypnotube query returned no results for page {}", page);
|
||||
return vec![];
|
||||
}
|
||||
let video_items: Vec<VideoItem> = self
|
||||
.get_video_items_from_html(text.clone())
|
||||
.await;
|
||||
if !video_items.is_empty() {
|
||||
cache.remove(&video_url);
|
||||
cache.insert(video_url.clone(), video_items.clone());
|
||||
} else {
|
||||
return old_items;
|
||||
}
|
||||
video_items
|
||||
}
|
||||
|
||||
async fn get_video_items_from_html(
|
||||
&self,
|
||||
html: String
|
||||
) -> Vec<VideoItem> {
|
||||
if html.is_empty() || html.contains("404 Not Found") {
|
||||
eprint!("Hypnotube returned empty or 404 html");
|
||||
return vec![];
|
||||
}
|
||||
|
||||
let block = match html
|
||||
.split("pagination-col col pagination")
|
||||
.next()
|
||||
.and_then(|s| s.split(" title END ").last())
|
||||
{
|
||||
Some(b) => b,
|
||||
None => {
|
||||
eprint!("Hypnotube Provider: Failed to get block from html");
|
||||
let err = Error::from(ErrorKind::Parse("html".into()));
|
||||
let _ = futures::executor::block_on(send_discord_error_report(
|
||||
&err,
|
||||
Some("Hypnotube Provider"),
|
||||
Some(&format!("Failed to get block from html:\n```{html}\n```")),
|
||||
file!(),
|
||||
line!(),
|
||||
module_path!(),
|
||||
));
|
||||
return vec![];
|
||||
},
|
||||
};
|
||||
let mut items = vec![];
|
||||
for seg in block.split("<!-- item -->").skip(1){
|
||||
let video_url = match seg
|
||||
.split(" href=\"")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split('"').next()) {
|
||||
Some(url) => url.to_string(),
|
||||
None => {
|
||||
eprint!("Hypnotube Provider: Failed to parse video url from segment");
|
||||
let err = Error::from(ErrorKind::Parse("video url".into()));
|
||||
let _ = futures::executor::block_on(send_discord_error_report(
|
||||
&err,
|
||||
Some("Hypnotube Provider"),
|
||||
Some(&format!("Failed to parse video url from segment:\n```{seg}\n```")),
|
||||
file!(),
|
||||
line!(),
|
||||
module_path!(),
|
||||
));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let mut title = seg
|
||||
.split(" title=\"")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split('"').next())
|
||||
.unwrap_or_default().trim().to_string();
|
||||
|
||||
title = decode(title.clone().as_bytes()).to_string().unwrap_or(title).titlecase();
|
||||
let id = video_url
|
||||
.split('/')
|
||||
.nth(4)
|
||||
.and_then(|s| s.split('.').next())
|
||||
.ok_or_else(|| ErrorKind::Parse("video id".into()))
|
||||
.unwrap_or_else(|_| &title.as_str());
|
||||
let thumb = seg
|
||||
.split("<img ")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split("src=\"").nth(1))
|
||||
.and_then(|s| s.split("\"").next())
|
||||
.ok_or_else(|| ErrorKind::Parse("thumb block".into()))
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let raw_duration = seg
|
||||
.split("<span class=\"time\">")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split('<').next())
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let duration = parse_time_to_seconds(&raw_duration).unwrap_or(0) as u32;
|
||||
|
||||
let views = seg
|
||||
.split("<span class=\"icon i-eye\"></span>")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split("span class=\"sub-desc\">").nth(1))
|
||||
.and_then(|s| s.split("<").next())
|
||||
.unwrap_or("0")
|
||||
.replace(",", "")
|
||||
.parse::<u32>()
|
||||
.unwrap_or(0);
|
||||
let video_item = VideoItem::new(
|
||||
id.to_owned(),
|
||||
title,
|
||||
video_url,
|
||||
"hypnotube".into(),
|
||||
thumb,
|
||||
duration,
|
||||
)
|
||||
.views(views);
|
||||
items.push(video_item);
|
||||
}
|
||||
items
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Provider for HypnotubeProvider {
|
||||
async fn get_videos(
|
||||
&self,
|
||||
cache: VideoCache,
|
||||
_pool: DbPool,
|
||||
sort: String,
|
||||
query: Option<String>,
|
||||
page: String,
|
||||
_per_page: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let page = page.parse::<u8>().unwrap_or(1);
|
||||
|
||||
let res = match query {
|
||||
Some(q) => self.to_owned().query(cache, page, &q, options).await,
|
||||
None => self.get(cache, page, &sort, options).await,
|
||||
};
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
fn get_channel(&self, v: ClientVersion) -> Channel {
|
||||
self.build_channel(v)
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ pub mod hqporner;
|
||||
pub mod noodlemagazine;
|
||||
pub mod pimpbunny;
|
||||
pub mod javtiful;
|
||||
pub mod hypnotube;
|
||||
|
||||
// convenient alias
|
||||
pub type DynProvider = Arc<dyn Provider>;
|
||||
@@ -57,6 +58,7 @@ pub static ALL_PROVIDERS: Lazy<HashMap<&'static str, DynProvider>> = Lazy::new(|
|
||||
m.insert("noodlemagazine", Arc::new(noodlemagazine::NoodlemagazineProvider::new()) as DynProvider);
|
||||
m.insert("pimpbunny", Arc::new(pimpbunny::PimpbunnyProvider::new()) as DynProvider);
|
||||
m.insert("javtiful", Arc::new(javtiful::JavtifulProvider::new()) as DynProvider);
|
||||
m.insert("hypnotube", Arc::new(hypnotube::HypnotubeProvider::new()) as DynProvider);
|
||||
// add more here as you migrate them
|
||||
m
|
||||
});
|
||||
|
||||
@@ -111,7 +111,7 @@ impl Requester {
|
||||
request.send().await
|
||||
}
|
||||
|
||||
pub async fn post<S>(
|
||||
pub async fn post_json<S>(
|
||||
&mut self,
|
||||
url: &str,
|
||||
data: &S,
|
||||
@@ -137,6 +137,29 @@ impl Requester {
|
||||
request.send().await
|
||||
}
|
||||
|
||||
pub async fn post(
|
||||
&mut self,
|
||||
url: &str,
|
||||
data: &str,
|
||||
headers: Vec<(&str, &str)>,
|
||||
) -> Result<Response, wreq::Error> {
|
||||
let mut request = self.client.post(url).version(Version::HTTP_11).body(data.to_string());
|
||||
|
||||
// Set custom headers
|
||||
for (key, value) in headers.iter() {
|
||||
request = request.header(key.to_string(), value.to_string());
|
||||
}
|
||||
|
||||
if self.proxy {
|
||||
if let Ok(proxy_url) = env::var("BURP_URL") {
|
||||
let proxy = Proxy::all(&proxy_url).unwrap();
|
||||
request = request.proxy(proxy);
|
||||
}
|
||||
}
|
||||
|
||||
request.send().await
|
||||
}
|
||||
|
||||
pub async fn post_multipart(
|
||||
&mut self,
|
||||
url: &str,
|
||||
|
||||
Reference in New Issue
Block a user