xfree and beeg bug fix
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::DbPool;
|
||||
use crate::api::ClientVersion;
|
||||
use crate::providers::{Provider, report_provider_error_background};
|
||||
use crate::providers::{Provider, report_provider_error, report_provider_error_background};
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::util::parse_abbreviated_number;
|
||||
use crate::videos::{ServerOptions, VideoItem};
|
||||
@@ -11,6 +11,7 @@ use htmlentity::entity::{ICodedDataTrait, decode};
|
||||
use serde_json::Value;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::vec;
|
||||
|
||||
error_chain! {
|
||||
@@ -73,14 +74,15 @@ impl BeegProvider {
|
||||
};
|
||||
|
||||
rt.block_on(async move {
|
||||
if let Err(e) = Self::load_sites(sites).await {
|
||||
eprintln!("beeg load_sites failed: {}", e);
|
||||
}
|
||||
if let Err(e) = Self::load_categories(categories).await {
|
||||
eprintln!("beeg load_categories failed: {}", e);
|
||||
}
|
||||
if let Err(e) = Self::load_stars(stars).await {
|
||||
eprintln!("beeg load_stars failed: {}", e);
|
||||
match Self::fetch_tags().await {
|
||||
Ok(json) => {
|
||||
Self::load_sites(&json, sites);
|
||||
Self::load_categories(&json, categories);
|
||||
Self::load_stars(&json, stars);
|
||||
}
|
||||
Err(e) => {
|
||||
report_provider_error("beeg", "init.fetch_tags", &e.to_string()).await;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -88,24 +90,36 @@ impl BeegProvider {
|
||||
|
||||
async fn fetch_tags() -> Result<Value> {
|
||||
let mut requester = util::requester::Requester::new();
|
||||
let text = match requester
|
||||
.get(
|
||||
"https://store.externulls.com/tag/facts/tags?get_original=true&slug=index",
|
||||
None,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(text) => text,
|
||||
Err(e) => {
|
||||
eprintln!("beeg fetch_tags failed: {}", e);
|
||||
return Err(ErrorKind::Parse("failed to fetch tags".into()).into());
|
||||
let endpoints = [
|
||||
"https://store.externulls.com/tag/facts/tags?get_original=true&slug=index",
|
||||
"https://store.externulls.com/tag/facts/tags?slug=index",
|
||||
];
|
||||
let mut errors: Vec<String> = vec![];
|
||||
|
||||
for endpoint in endpoints {
|
||||
for attempt in 1..=3 {
|
||||
match requester.get(endpoint, None).await {
|
||||
Ok(text) => match serde_json::from_str::<Value>(&text) {
|
||||
Ok(json) => return Ok(json),
|
||||
Err(e) => {
|
||||
errors
|
||||
.push(format!("endpoint={endpoint}; attempt={attempt}; parse={e}"));
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
errors.push(format!(
|
||||
"endpoint={endpoint}; attempt={attempt}; request={e}"
|
||||
));
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(250 * attempt as u64)).await;
|
||||
}
|
||||
};
|
||||
Ok(serde_json::from_str(&text)?)
|
||||
}
|
||||
|
||||
Err(ErrorKind::Parse(format!("failed to fetch tags; {}", errors.join(" | "))).into())
|
||||
}
|
||||
|
||||
async fn load_stars(stars: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
let json = Self::fetch_tags().await?;
|
||||
fn load_stars(json: &Value, stars: Arc<RwLock<Vec<FilterOption>>>) {
|
||||
let arr = json
|
||||
.get("human")
|
||||
.and_then(|v| v.as_array().map(|v| v.as_slice()))
|
||||
@@ -124,11 +138,9 @@ impl BeegProvider {
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_categories(categories: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
let json = Self::fetch_tags().await?;
|
||||
fn load_categories(json: &Value, categories: Arc<RwLock<Vec<FilterOption>>>) {
|
||||
let arr = json
|
||||
.get("other")
|
||||
.and_then(|v| v.as_array().map(|v| v.as_slice()))
|
||||
@@ -147,11 +159,9 @@ impl BeegProvider {
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_sites(sites: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
let json = Self::fetch_tags().await?;
|
||||
fn load_sites(json: &Value, sites: Arc<RwLock<Vec<FilterOption>>>) {
|
||||
let arr = json
|
||||
.get("productions")
|
||||
.and_then(|v| v.as_array().map(|v| v.as_slice()))
|
||||
@@ -170,7 +180,6 @@ impl BeegProvider {
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn push_unique(target: &Arc<RwLock<Vec<FilterOption>>>, item: FilterOption) {
|
||||
|
||||
Reference in New Issue
Block a user