diff --git a/src/providers/beeg.rs b/src/providers/beeg.rs index 387f022..24299ef 100644 --- a/src/providers/beeg.rs +++ b/src/providers/beeg.rs @@ -1,7 +1,6 @@ use crate::DbPool; use crate::api::ClientVersion; use crate::providers::Provider; -use crate::schema::videos::star; use crate::util::cache::VideoCache; use crate::util::parse_abbreviated_number; use crate::util::time::parse_time_to_seconds; @@ -24,7 +23,6 @@ error_chain! { #[derive(Debug, Clone)] pub struct BeegProvider { - url: String, sites: Arc>>, stars: Arc>>, categories: Arc>>, @@ -32,7 +30,6 @@ pub struct BeegProvider { impl BeegProvider { pub fn new() -> Self { let provider = BeegProvider { - url: "https://beeg.com".to_string(), sites: Arc::new(RwLock::new(vec![FilterOption { id: "all".to_string(), title: "All".to_string(), @@ -53,7 +50,6 @@ impl BeegProvider { } fn spawn_initial_load(&self) { - let url = self.url.clone(); let sites = Arc::clone(&self.sites); let categories = Arc::clone(&self.categories); let stars = Arc::clone(&self.stars); @@ -227,28 +223,31 @@ impl BeegProvider { page: u8, options: ServerOptions, ) -> Result> { - let mut url = ""; + let mut slug = ""; if options.categories.is_some() && !options.categories.as_ref().unwrap().is_empty() && options.categories.as_ref().unwrap() != "all" { - url = options.categories.as_ref().unwrap(); + slug = options.categories.as_ref().unwrap(); } if options.sites.is_some() && !options.sites.as_ref().unwrap().is_empty() && options.sites.as_ref().unwrap() != "all" { - url = options.sites.as_ref().unwrap(); + slug = options.sites.as_ref().unwrap(); } if options.stars.is_some() && !options.stars.as_ref().unwrap().is_empty() && options.stars.as_ref().unwrap() != "all" { - url = options.stars.as_ref().unwrap(); + slug = options.stars.as_ref().unwrap(); } let video_url = format!( - "https://store.externulls.com/facts/tag?id=27173&limit=100&offset={}", - page - 1 + "https://store.externulls.com/facts/tag?id=27173&limit=100&offset={}{}", + page - 1, match slug { + "" => "".to_string(), + _ => format!("&slug={}", slug.replace(" ", "")), + } ); let old_items = match cache.get(&video_url) { Some((time, items)) => { @@ -320,9 +319,86 @@ impl BeegProvider { fn get_video_items_from_html(&self, json: Value) -> Vec { let mut items: Vec = Vec::new(); - while let Some(video_items) = json.as_array() { - println!("video_items: {:?}\n\n\n", video_items); - break; + let video_items = match json.as_array(){ + Some(array) => array, + None => return items, + }; + for video in video_items { + // println!("video: {}\n\n\n", serde_json::to_string_pretty(&video).unwrap()); + let file = match video.get("file"){ + Some(v) => v, + None => continue, + }; + let hls_resources = match file.get("hls_resources"){ + Some(v) => v, + None => continue, + }; + let video_key = match hls_resources.get("fl_cdn_multi"){ + Some(v) => v, + None => continue, + }; + let video_url = format!( + "https://video.externulls.com/{}", + video_key.to_string().replace("\"","") + ); + let data = match file.get("data") { + Some(v) => v, + None => continue, + }; + let title = match data[0].get("cd_value") { + Some(v) => decode(v.as_str().unwrap_or("").as_bytes()).to_string().unwrap_or(v.to_string()), + None => "".to_string(), + }; + let id = match file.get("id"){ + Some(v) => v.as_i64().unwrap_or(0).to_string(), + None => title.clone(), + }; + let fc_facts = match video.get("fc_facts") { + Some(v) => v[0].clone(), + None => continue, + }; + let duration = match file.get("fl_duration") { + Some(v) => parse_time_to_seconds(v.as_str().unwrap_or("0")).unwrap_or(0), + None => 0, + }; + let tags = match video.get("tags") { + Some(v) => { + // v should be an array of tag objects + v.as_array() + .map(|arr| { + arr.iter() + .map(|tag| { + tag.get("tg_name") + .and_then(|name| name.as_str()) + .unwrap_or("") + .to_string() + }) + .collect::>() + }) + .unwrap_or_default() + } + None => Vec::new(), + }; + let thumb = format!("https://thumbs.externulls.com/videos/{}/0.webp?size=480x270", id); + let views = match fc_facts.get("fc_st_views") { + Some(v) => parse_abbreviated_number(v.as_str().unwrap_or("0")).unwrap_or(0), + None => 0, + }; + let mut video_item = VideoItem::new( + id, + title, + video_url.to_string(), + "beeg".to_string(), + thumb, + duration as u32, + ); + if views > 0 { + video_item = video_item.views(views); + } + if !tags.is_empty() { + video_item = video_item.tags(tags); + } + items.push(video_item); } return items; }