fixes and cleanup
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
use crate::api::ClientVersion;
|
||||
use crate::DbPool;
|
||||
use crate::api::ClientVersion;
|
||||
use crate::providers::Provider;
|
||||
use crate::status::*;
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::util::discord::{format_error_chain, send_discord_error_report};
|
||||
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::{ICodedDataTrait, decode};
|
||||
use std::vec;
|
||||
use async_trait::async_trait;
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
@@ -112,12 +112,15 @@ impl PornzogProvider {
|
||||
// SAFE: Check if requester exists instead of unwrap()
|
||||
let mut requester = match options.requester.clone() {
|
||||
Some(r) => r,
|
||||
None => return Ok(old_items),
|
||||
None => return Ok(old_items),
|
||||
};
|
||||
|
||||
let text = requester.get(&video_url, None).await.map_err(|e| format!("{}", e))?;
|
||||
let text = requester
|
||||
.get(&video_url, None)
|
||||
.await
|
||||
.map_err(|e| format!("{}", e))?;
|
||||
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());
|
||||
@@ -131,7 +134,7 @@ impl PornzogProvider {
|
||||
if html.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
|
||||
|
||||
let mut items: Vec<VideoItem> = Vec::new();
|
||||
|
||||
// Helper for safe splitting: returns Option<&str>
|
||||
@@ -149,7 +152,7 @@ impl PornzogProvider {
|
||||
let raw_videos: Vec<&str> = body.split("class=\"thumb-video ").skip(1).collect();
|
||||
|
||||
for (idx, video_segment) in raw_videos.iter().enumerate() {
|
||||
// Attempt to parse each item. If one fails, we log it and continue to the next
|
||||
// Attempt to parse each item. If one fails, we log it and continue to the next
|
||||
// instead of crashing the whole request.
|
||||
let result: Option<VideoItem> = (|| {
|
||||
let mut video_url = get_part(video_segment, "href=\"", 1)?
|
||||
@@ -162,7 +165,9 @@ impl PornzogProvider {
|
||||
}
|
||||
|
||||
let title_raw = get_part(video_segment, "alt=\"", 1)?.split("\"").next()?;
|
||||
let title = decode(title_raw.as_bytes()).to_string().unwrap_or(title_raw.to_string());
|
||||
let title = decode(title_raw.as_bytes())
|
||||
.to_string()
|
||||
.unwrap_or(title_raw.to_string());
|
||||
|
||||
// The ID is the 5th element in a "/" split: e.g., "", "video", "123", "title"
|
||||
let id = video_url.split("/").nth(4)?.to_string();
|
||||
@@ -179,8 +184,9 @@ impl PornzogProvider {
|
||||
let tags_section = get_part(video_segment, "class=\"tags\"", 1)?
|
||||
.split("</p>")
|
||||
.next()?;
|
||||
|
||||
let tags = tags_section.split("<a href=\"")
|
||||
|
||||
let tags = tags_section
|
||||
.split("<a href=\"")
|
||||
.skip(1)
|
||||
.filter_map(|el| {
|
||||
let name = el.split(">").nth(1)?.split("<").next()?;
|
||||
@@ -188,7 +194,10 @@ impl PornzogProvider {
|
||||
})
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
Some(VideoItem::new(id, title, video_url, "pornzog".to_string(), thumb, duration).tags(tags))
|
||||
Some(
|
||||
VideoItem::new(id, title, video_url, "pornzog".to_string(), thumb, duration)
|
||||
.tags(tags),
|
||||
)
|
||||
})();
|
||||
|
||||
match result {
|
||||
@@ -214,7 +223,7 @@ impl Provider for PornzogProvider {
|
||||
) -> Vec<VideoItem> {
|
||||
let _ = per_page;
|
||||
let _ = pool;
|
||||
|
||||
|
||||
let page_num = page.parse::<u8>().unwrap_or(1);
|
||||
let query_str = query.unwrap_or_default();
|
||||
|
||||
@@ -225,13 +234,13 @@ impl Provider for PornzogProvider {
|
||||
|
||||
// 1. Create a collection of owned data so we don't hold references to `e`
|
||||
let mut error_reports = Vec::new();
|
||||
|
||||
|
||||
// Iterating through the error chain to collect data into owned Strings
|
||||
for cause in e.iter().skip(1) {
|
||||
error_reports.push((
|
||||
cause.to_string(), // Title
|
||||
format_error_chain(cause), // Description/Chain
|
||||
format!("caused by: {}", cause) // Message
|
||||
format!("caused by: {}", cause), // Message
|
||||
));
|
||||
}
|
||||
|
||||
@@ -245,9 +254,10 @@ impl Provider for PornzogProvider {
|
||||
file!(),
|
||||
line!(),
|
||||
module_path!(),
|
||||
).await;
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user