provider refactors and fixes
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use crate::api::ClientVersion;
|
||||
use crate::util::parse_abbreviated_number;
|
||||
use crate::DbPool;
|
||||
use crate::providers::Provider;
|
||||
use crate::status::*;
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::util::time::parse_time_to_seconds;
|
||||
use crate::videos::{ServerOptions, VideoItem};
|
||||
@@ -26,6 +28,42 @@ impl PornhatProvider {
|
||||
url: "https://www.pornhat.com".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn build_channel(&self, _clientversion: ClientVersion) -> Channel {
|
||||
Channel {
|
||||
id: "pornhat".to_string(),
|
||||
name: "Pornhat".to_string(),
|
||||
description: "free HD porn videos".to_string(),
|
||||
premium: false,
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=pornhat.com".to_string(),
|
||||
status: "active".to_string(),
|
||||
categories: vec![],
|
||||
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: "new".to_string(),
|
||||
title: "New".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "popular".to_string(),
|
||||
title: "Popular".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "trending".to_string(),
|
||||
title: "Trending".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
}],
|
||||
nsfw: true,
|
||||
cacheDuration: Some(1800),
|
||||
}
|
||||
}
|
||||
async fn get(
|
||||
&self,
|
||||
cache: VideoCache,
|
||||
@@ -51,8 +89,20 @@ impl PornhatProvider {
|
||||
vec![]
|
||||
}
|
||||
};
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let text = requester.get(&video_url, None).await.unwrap();
|
||||
let mut requester =
|
||||
crate::providers::requester_or_default(&options, module_path!(), "missing_requester");
|
||||
let text = match requester.get(&video_url, None).await {
|
||||
Ok(text) => text,
|
||||
Err(e) => {
|
||||
crate::providers::report_provider_error(
|
||||
"pornhat",
|
||||
"get.request",
|
||||
&format!("url={video_url}; error={e}"),
|
||||
)
|
||||
.await;
|
||||
return Ok(old_items);
|
||||
}
|
||||
};
|
||||
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone());
|
||||
if !video_items.is_empty() {
|
||||
cache.remove(&video_url);
|
||||
@@ -73,7 +123,7 @@ impl PornhatProvider {
|
||||
let mut video_url = format!("{}/search/{}/{}/", self.url, search_string, page);
|
||||
|
||||
if search_string.starts_with("@"){
|
||||
let url_part = search_string.split("@").collect::<Vec<&str>>()[1].replace(":", "/");
|
||||
let url_part = search_string.split("@").collect::<Vec<&str>>().get(1).copied().unwrap_or_default().replace(":", "/");
|
||||
video_url = format!("{}/{}/", self.url, url_part);
|
||||
}
|
||||
// Check our Video Cache. If the result is younger than 1 hour, we return it.
|
||||
@@ -90,16 +140,28 @@ impl PornhatProvider {
|
||||
vec![]
|
||||
}
|
||||
};
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let text = requester.get(&video_url, None).await.unwrap();
|
||||
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone());
|
||||
if !video_items.is_empty() {
|
||||
cache.remove(&video_url);
|
||||
cache.insert(video_url.clone(), video_items.clone());
|
||||
} else {
|
||||
let mut requester =
|
||||
crate::providers::requester_or_default(&options, module_path!(), "missing_requester");
|
||||
let text = match requester.get(&video_url, None).await {
|
||||
Ok(text) => text,
|
||||
Err(e) => {
|
||||
crate::providers::report_provider_error(
|
||||
"pornhat",
|
||||
"query.request",
|
||||
&format!("url={video_url}; error={e}"),
|
||||
)
|
||||
.await;
|
||||
return Ok(old_items);
|
||||
}
|
||||
Ok(video_items)
|
||||
};
|
||||
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone());
|
||||
if !video_items.is_empty() {
|
||||
cache.remove(&video_url);
|
||||
cache.insert(video_url.clone(), video_items.clone());
|
||||
} else {
|
||||
return Ok(old_items);
|
||||
}
|
||||
Ok(video_items)
|
||||
}
|
||||
|
||||
fn get_video_items_from_html(&self, html: String) -> Vec<VideoItem> {
|
||||
@@ -108,7 +170,7 @@ impl PornhatProvider {
|
||||
return vec![];
|
||||
}
|
||||
let mut items: Vec<VideoItem> = Vec::new();
|
||||
let raw_videos = html.split("<div class=\"pagination\"").collect::<Vec<&str>>()[0]
|
||||
let raw_videos = html.split("<div class=\"pagination\"").collect::<Vec<&str>>().get(0).copied().unwrap_or_default()
|
||||
.split("item thumb-bl thumb-bl-video video_")
|
||||
.collect::<Vec<&str>>()[1..]
|
||||
.to_vec();
|
||||
@@ -117,38 +179,38 @@ impl PornhatProvider {
|
||||
// for (index, line) in vid.iter().enumerate() {
|
||||
// println!("Line {}: {}", index, line);
|
||||
// }
|
||||
let video_url: String = format!("{}{}", self.url, video_segment.split("<a href=\"").collect::<Vec<&str>>()[1]
|
||||
let video_url: String = format!("{}{}", self.url, video_segment.split("<a href=\"").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0]);
|
||||
let preview_url = video_segment.split("data-preview-custom=\"").collect::<Vec<&str>>()[1]
|
||||
.collect::<Vec<&str>>().get(0).copied().unwrap_or_default());
|
||||
let preview_url = video_segment.split("data-preview-custom=\"").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 title = video_segment.split("\" title=\"").collect::<Vec<&str>>()[1]
|
||||
let mut title = video_segment.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();
|
||||
// html decode
|
||||
title = decode(title.as_bytes()).to_string().unwrap_or(title);
|
||||
let id = video_url.split("/").collect::<Vec<&str>>()[4].to_string();
|
||||
let raw_duration = video_segment.split("fa fa-clock-o").collect::<Vec<&str>>()[1]
|
||||
.split("<span>").collect::<Vec<&str>>()[1]
|
||||
let id = video_url.split("/").collect::<Vec<&str>>().get(4).copied().unwrap_or_default().to_string();
|
||||
let raw_duration = video_segment.split("fa fa-clock-o").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("<span>").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 = parse_time_to_seconds(&raw_duration).unwrap_or(0) as u32;
|
||||
|
||||
let thumb = video_segment.split("<img class=\"thumb lazy-load\"").collect::<Vec<&str>>()[1]
|
||||
.split("data-original=\"").collect::<Vec<&str>>()[1]
|
||||
let thumb = video_segment.split("<img class=\"thumb lazy-load\"").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("data-original=\"").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 tags = vec![];
|
||||
if video_segment.contains("href=\"/sites/"){
|
||||
let raw_tags = video_segment.split("href=\"/sites/").collect::<Vec<&str>>()[1..]
|
||||
.iter()
|
||||
.map(|s| s.split("/\"").collect::<Vec<&str>>()[0].to_string())
|
||||
.map(|s| s.split("/\"").collect::<Vec<&str>>().get(0).copied().unwrap_or_default().to_string())
|
||||
.collect::<Vec<String>>();
|
||||
for tag in raw_tags {
|
||||
if !tag.is_empty() {
|
||||
@@ -159,7 +221,7 @@ impl PornhatProvider {
|
||||
if video_segment.contains("href=\"/models/"){
|
||||
let raw_tags = video_segment.split("href=\"/models/").collect::<Vec<&str>>()[1..]
|
||||
.iter()
|
||||
.map(|s| s.split("/\"").collect::<Vec<&str>>()[0].to_string())
|
||||
.map(|s| s.split("/\"").collect::<Vec<&str>>().get(0).copied().unwrap_or_default().to_string())
|
||||
.collect::<Vec<String>>();
|
||||
for tag in raw_tags {
|
||||
if !tag.is_empty() {
|
||||
@@ -168,10 +230,10 @@ impl PornhatProvider {
|
||||
}
|
||||
}
|
||||
|
||||
let views_part = video_segment.split("fa fa-eye").collect::<Vec<&str>>()[1]
|
||||
.split("<span>").collect::<Vec<&str>>()[1]
|
||||
let views_part = video_segment.split("fa fa-eye").collect::<Vec<&str>>().get(1).copied().unwrap_or_default()
|
||||
.split("<span>").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 views = parse_abbreviated_number(&views_part).unwrap_or(0) as u32;
|
||||
|
||||
@@ -227,4 +289,8 @@ impl Provider for PornhatProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_channel(&self, clientversion: ClientVersion) -> Option<Channel> {
|
||||
Some(self.build_channel(clientversion))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user