provider refactors and fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::DbPool;
|
||||
use crate::api::ClientVersion;
|
||||
use crate::providers::Provider;
|
||||
use crate::providers::{Provider, report_provider_error_background};
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::util::parse_abbreviated_number;
|
||||
use crate::videos::{ServerOptions, VideoItem};
|
||||
@@ -203,23 +203,20 @@ impl BeegProvider {
|
||||
options: ServerOptions,
|
||||
) -> Result<Vec<VideoItem>> {
|
||||
let mut slug = "";
|
||||
if options.categories.is_some()
|
||||
&& !options.categories.as_ref().unwrap().is_empty()
|
||||
&& options.categories.as_ref().unwrap() != "all"
|
||||
{
|
||||
slug = options.categories.as_ref().unwrap();
|
||||
if let Some(categories) = options.categories.as_ref() {
|
||||
if !categories.is_empty() && categories != "all" {
|
||||
slug = categories;
|
||||
}
|
||||
}
|
||||
if options.sites.is_some()
|
||||
&& !options.sites.as_ref().unwrap().is_empty()
|
||||
&& options.sites.as_ref().unwrap() != "all"
|
||||
{
|
||||
slug = options.sites.as_ref().unwrap();
|
||||
if let Some(sites) = options.sites.as_ref() {
|
||||
if !sites.is_empty() && sites != "all" {
|
||||
slug = sites;
|
||||
}
|
||||
}
|
||||
if options.stars.is_some()
|
||||
&& !options.stars.as_ref().unwrap().is_empty()
|
||||
&& options.stars.as_ref().unwrap() != "all"
|
||||
{
|
||||
slug = options.stars.as_ref().unwrap();
|
||||
if let Some(stars) = options.stars.as_ref() {
|
||||
if !stars.is_empty() && stars != "all" {
|
||||
slug = stars;
|
||||
}
|
||||
}
|
||||
let video_url = format!(
|
||||
"https://store.externulls.com/facts/tag?limit=100&offset={}{}",
|
||||
@@ -240,9 +237,21 @@ impl BeegProvider {
|
||||
vec![]
|
||||
}
|
||||
};
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let text = requester.get(&video_url, None).await.unwrap();
|
||||
let json: serde_json::Value = serde_json::from_str::<serde_json::Value>(&text).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) => {
|
||||
report_provider_error_background("beeg", "get.request", &e.to_string());
|
||||
return Ok(old_items);
|
||||
}
|
||||
};
|
||||
let json: serde_json::Value = match serde_json::from_str::<serde_json::Value>(&text) {
|
||||
Ok(json) => json,
|
||||
Err(e) => {
|
||||
report_provider_error_background("beeg", "get.parse_json", &e.to_string());
|
||||
return Ok(old_items);
|
||||
}
|
||||
};
|
||||
let video_items: Vec<VideoItem> = self.get_video_items_from_html(json.clone());
|
||||
if !video_items.is_empty() {
|
||||
cache.remove(&video_url);
|
||||
@@ -280,10 +289,22 @@ impl BeegProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let mut requester = crate::providers::requester_or_default(&options, module_path!(), "missing_requester");
|
||||
|
||||
let text = requester.get(&video_url, None).await.unwrap();
|
||||
let json: serde_json::Value = serde_json::from_str::<serde_json::Value>(&text).unwrap();
|
||||
let text = match requester.get(&video_url, None).await {
|
||||
Ok(text) => text,
|
||||
Err(e) => {
|
||||
report_provider_error_background("beeg", "query.request", &e.to_string());
|
||||
return Ok(old_items);
|
||||
}
|
||||
};
|
||||
let json: serde_json::Value = match serde_json::from_str::<serde_json::Value>(&text) {
|
||||
Ok(json) => json,
|
||||
Err(e) => {
|
||||
report_provider_error_background("beeg", "query.parse_json", &e.to_string());
|
||||
return Ok(old_items);
|
||||
}
|
||||
};
|
||||
let video_items: Vec<VideoItem> = self.get_video_items_from_html(json.clone());
|
||||
if !video_items.is_empty() {
|
||||
cache.remove(&video_url);
|
||||
|
||||
Reference in New Issue
Block a user