more fixes
This commit is contained in:
@@ -58,20 +58,39 @@ impl Provider for AllProvider {
|
||||
.collect();
|
||||
|
||||
let futures = providers.iter().map(|provider| {
|
||||
provider.get_videos(
|
||||
cache.clone(),
|
||||
pool.clone(),
|
||||
sort.clone(),
|
||||
query.clone(),
|
||||
page.clone(),
|
||||
per_page.clone(),
|
||||
options.clone()
|
||||
let provider = provider.clone();
|
||||
let cache = cache.clone();
|
||||
let pool = pool.clone();
|
||||
let sort = sort.clone();
|
||||
let query = query.clone();
|
||||
let page = page.clone();
|
||||
let per_page = per_page.clone();
|
||||
let options = options.clone();
|
||||
async move {
|
||||
match tokio::time::timeout(
|
||||
std::time::Duration::from_secs(55),
|
||||
provider.get_videos(
|
||||
cache,
|
||||
pool,
|
||||
sort,
|
||||
query,
|
||||
page,
|
||||
per_page,
|
||||
options,
|
||||
),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
// timed out -> return empty result for this provider
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
}).collect::<Vec<_>>();
|
||||
let results:Vec<Vec<VideoItem>> = join_all(futures).await;
|
||||
let video_items: Vec<VideoItem> = interleave(&results);
|
||||
|
||||
|
||||
return video_items;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,13 @@ error_chain! {
|
||||
foreign_links {
|
||||
Io(std::io::Error);
|
||||
HttpRequest(wreq::Error);
|
||||
Json(serde_json::Error);
|
||||
}
|
||||
errors {
|
||||
Parse(msg: String) {
|
||||
description("parse error")
|
||||
display("parse error: {}", msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,24 +34,15 @@ pub struct BeegProvider {
|
||||
stars: Arc<RwLock<Vec<FilterOption>>>,
|
||||
categories: Arc<RwLock<Vec<FilterOption>>>,
|
||||
}
|
||||
|
||||
impl BeegProvider {
|
||||
pub fn new() -> Self {
|
||||
let provider = BeegProvider {
|
||||
sites: Arc::new(RwLock::new(vec![FilterOption {
|
||||
id: "all".to_string(),
|
||||
title: "All".to_string(),
|
||||
}])),
|
||||
stars: Arc::new(RwLock::new(vec![FilterOption {
|
||||
id: "all".to_string(),
|
||||
title: "All".to_string(),
|
||||
}])),
|
||||
categories: Arc::new(RwLock::new(vec![FilterOption {
|
||||
id: "all".to_string(),
|
||||
title: "All".to_string(),
|
||||
}])),
|
||||
sites: Arc::new(RwLock::new(vec![FilterOption { id: "all".into(), title: "All".into() }])),
|
||||
stars: Arc::new(RwLock::new(vec![FilterOption { id: "all".into(), title: "All".into() }])),
|
||||
categories: Arc::new(RwLock::new(vec![FilterOption { id: "all".into(), title: "All".into() }])),
|
||||
};
|
||||
|
||||
// Kick off the background load but return immediately
|
||||
provider.spawn_initial_load();
|
||||
provider
|
||||
}
|
||||
@@ -55,160 +53,142 @@ impl BeegProvider {
|
||||
let stars = Arc::clone(&self.stars);
|
||||
|
||||
thread::spawn(move || {
|
||||
// Create a tiny runtime just for these async tasks
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("build tokio runtime");
|
||||
let rt = match tokio::runtime::Builder::new_current_thread().enable_all().build() {
|
||||
Ok(rt) => rt,
|
||||
Err(e) => {
|
||||
eprintln!("beeg runtime init failed: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
rt.block_on(async move {
|
||||
// If you have a streaming sites loader, call it here too
|
||||
if let Err(e) = Self::load_sites(sites).await {
|
||||
eprintln!("beeg load_sites_into failed: {e}");
|
||||
eprintln!("beeg load_sites failed: {}", e);
|
||||
}
|
||||
|
||||
if let Err(e) = Self::load_categories(categories).await {
|
||||
eprintln!("beeg load_categories failed: {e}");
|
||||
eprintln!("beeg load_categories failed: {}", e);
|
||||
}
|
||||
|
||||
if let Err(e) = Self::load_stars(stars).await {
|
||||
eprintln!("beeg load_stars failed: {e}");
|
||||
eprintln!("beeg load_stars failed: {}", e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async fn load_stars(stars: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
async fn fetch_tags() -> Result<Value> {
|
||||
let mut requester = util::requester::Requester::new();
|
||||
let text = requester
|
||||
let text = match requester
|
||||
.get("https://store.externulls.com/tag/facts/tags?get_original=true&slug=index", None)
|
||||
.await
|
||||
.unwrap();
|
||||
let json: serde_json::Value = serde_json::from_str::<serde_json::Value>(&text).unwrap();
|
||||
let stars_array = json.get("human").unwrap().as_array().unwrap();
|
||||
for s in stars_array {
|
||||
let star_name = s.get("tg_name").unwrap().as_str().unwrap().to_string();
|
||||
let star_id = s.get("tg_slug").unwrap().as_str().unwrap().to_string();
|
||||
Self::push_unique(
|
||||
&stars,
|
||||
FilterOption {
|
||||
id: star_id,
|
||||
title: star_name,
|
||||
},
|
||||
);
|
||||
.await {
|
||||
Ok(text) => text,
|
||||
Err(e) => {
|
||||
eprintln!("beeg fetch_tags failed: {}", e);
|
||||
return Err(ErrorKind::Parse("failed to fetch tags".into()).into());
|
||||
}
|
||||
};
|
||||
Ok(serde_json::from_str(&text)?)
|
||||
}
|
||||
|
||||
async fn load_stars(stars: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
let json = Self::fetch_tags().await?;
|
||||
let arr = json
|
||||
.get("human")
|
||||
.and_then(|v| v.as_array().map(|v| v.as_slice()))
|
||||
.unwrap_or(&[]);
|
||||
for s in arr {
|
||||
if let (Some(name), Some(id)) = (
|
||||
s.get("tg_name").and_then(|v| v.as_str()),
|
||||
s.get("tg_slug").and_then(|v| v.as_str()),
|
||||
) {
|
||||
Self::push_unique(&stars, FilterOption { id: id.into(), title: name.into() });
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_categories(categories: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
let mut requester = util::requester::Requester::new();
|
||||
let text = requester
|
||||
.get("https://store.externulls.com/tag/facts/tags?get_original=true&slug=index", None)
|
||||
.await
|
||||
.unwrap();
|
||||
let json: serde_json::Value = serde_json::from_str::<serde_json::Value>(&text).unwrap();
|
||||
let stars_array = json.get("other").unwrap().as_array().unwrap();
|
||||
for s in stars_array {
|
||||
let star_name = s.get("tg_name").unwrap().as_str().unwrap().to_string();
|
||||
let star_id = s.get("tg_slug").unwrap().as_str().unwrap().to_string();
|
||||
Self::push_unique(
|
||||
&categories,
|
||||
FilterOption {
|
||||
id: star_id.replace("{","").replace("}",""),
|
||||
title: star_name.replace("{","").replace("}",""),
|
||||
},
|
||||
);
|
||||
let json = Self::fetch_tags().await?;
|
||||
let arr = json
|
||||
.get("other")
|
||||
.and_then(|v| v.as_array().map(|v| v.as_slice()))
|
||||
.unwrap_or(&[]);
|
||||
for s in arr {
|
||||
if let (Some(name), Some(id)) = (
|
||||
s.get("tg_name").and_then(|v| v.as_str()),
|
||||
s.get("tg_slug").and_then(|v| v.as_str()),
|
||||
) {
|
||||
Self::push_unique(
|
||||
&categories,
|
||||
FilterOption {
|
||||
id: id.replace('{', "").replace('}', ""),
|
||||
title: name.replace('{', "").replace('}', ""),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_sites(sites: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
let mut requester = util::requester::Requester::new();
|
||||
let text = requester
|
||||
.get("https://store.externulls.com/tag/facts/tags?get_original=true&slug=index", None)
|
||||
.await
|
||||
.unwrap();
|
||||
let json: serde_json::Value = serde_json::from_str::<serde_json::Value>(&text).unwrap();
|
||||
let stars_array = json.get("productions").unwrap().as_array().unwrap();
|
||||
for s in stars_array {
|
||||
let star_name = s.get("tg_name").unwrap().as_str().unwrap().to_string();
|
||||
let star_id = s.get("tg_slug").unwrap().as_str().unwrap().to_string();
|
||||
Self::push_unique(
|
||||
&sites,
|
||||
FilterOption {
|
||||
id: star_id,
|
||||
title: star_name,
|
||||
},
|
||||
);
|
||||
let json = Self::fetch_tags().await?;
|
||||
let arr = json
|
||||
.get("productions")
|
||||
.and_then(|v| v.as_array().map(|v| v.as_slice()))
|
||||
.unwrap_or(&[]);
|
||||
for s in arr {
|
||||
if let (Some(name), Some(id)) = (
|
||||
s.get("tg_name").and_then(|v| v.as_str()),
|
||||
s.get("tg_slug").and_then(|v| v.as_str()),
|
||||
) {
|
||||
Self::push_unique(&sites, FilterOption { id: id.into(), title: name.into() });
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Push one item with minimal lock time and dedup by id
|
||||
fn push_unique(target: &Arc<RwLock<Vec<FilterOption>>>, item: FilterOption) {
|
||||
if let Ok(mut vec) = target.write() {
|
||||
if !vec.iter().any(|x| x.id == item.id) {
|
||||
vec.push(item);
|
||||
// Optional: keep it sorted for nicer UX
|
||||
// vec.sort_by(|a,b| a.title.cmp(&b.title));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn build_channel(&self, clientversion: ClientVersion) -> Channel {
|
||||
let _ = clientversion;
|
||||
let sites: Vec<FilterOption> = self
|
||||
.sites
|
||||
.read()
|
||||
.map(|g| g.clone()) // or: .map(|g| g.to_vec())
|
||||
.unwrap_or_default(); // or: .unwrap_or_else(|_| Vec::new())
|
||||
|
||||
let categories: Vec<FilterOption> = self
|
||||
.categories
|
||||
.read()
|
||||
.map(|g| g.clone()) // or: .map(|g| g.to_vec())
|
||||
.unwrap_or_default(); // or: .unwrap_or_else(|_| Vec::new())
|
||||
|
||||
let stars: Vec<FilterOption> = self
|
||||
.stars
|
||||
.read()
|
||||
.map(|g| g.clone()) // or: .map(|g| g.to_vec())
|
||||
.unwrap_or_default(); // or: .unwrap_or_else(|_| Vec::new())
|
||||
|
||||
fn build_channel(&self, _: ClientVersion) -> Channel {
|
||||
Channel {
|
||||
id: "beeg".to_string(),
|
||||
name: "Beeg".to_string(),
|
||||
description: "Watch your favorite Porn on Beeg.com".to_string(),
|
||||
id: "beeg".into(),
|
||||
name: "Beeg".into(),
|
||||
description: "Watch your favorite Porn on Beeg.com".into(),
|
||||
premium: false,
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=beeg.com".to_string(),
|
||||
status: "active".to_string(),
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=beeg.com".into(),
|
||||
status: "active".into(),
|
||||
categories: vec![],
|
||||
options: vec![
|
||||
ChannelOption {
|
||||
id: "sites".to_string(),
|
||||
title: "Sites".to_string(),
|
||||
description: "Filter for different Sites".to_string(),
|
||||
systemImage: "rectangle.stack".to_string(),
|
||||
colorName: "green".to_string(),
|
||||
options: sites,
|
||||
id: "sites".into(),
|
||||
title: "Sites".into(),
|
||||
description: "Filter for different Sites".into(),
|
||||
systemImage: "rectangle.stack".into(),
|
||||
colorName: "green".into(),
|
||||
options: self.sites.read().map(|v| v.clone()).unwrap_or_default(),
|
||||
multiSelect: false,
|
||||
},
|
||||
ChannelOption {
|
||||
id: "categories".to_string(),
|
||||
title: "Categories".to_string(),
|
||||
description: "Filter for different Networks".to_string(),
|
||||
systemImage: "list.dash".to_string(),
|
||||
colorName: "purple".to_string(),
|
||||
options: categories,
|
||||
id: "categories".into(),
|
||||
title: "Categories".into(),
|
||||
description: "Filter for different Networks".into(),
|
||||
systemImage: "list.dash".into(),
|
||||
colorName: "purple".into(),
|
||||
options: self.categories.read().map(|v| v.clone()).unwrap_or_default(),
|
||||
multiSelect: false,
|
||||
},
|
||||
ChannelOption {
|
||||
id: "stars".to_string(),
|
||||
title: "Stars".to_string(),
|
||||
description: "Filter for different Pornstars".to_string(),
|
||||
systemImage: "star.fill".to_string(),
|
||||
colorName: "yellow".to_string(),
|
||||
options: stars,
|
||||
id: "stars".into(),
|
||||
title: "Stars".into(),
|
||||
description: "Filter for different Pornstars".into(),
|
||||
systemImage: "star.fill".into(),
|
||||
colorName: "yellow".into(),
|
||||
options: self.stars.read().map(|v| v.clone()).unwrap_or_default(),
|
||||
multiSelect: false,
|
||||
},
|
||||
],
|
||||
@@ -316,89 +296,61 @@ impl BeegProvider {
|
||||
}
|
||||
|
||||
fn get_video_items_from_html(&self, json: Value) -> Vec<VideoItem> {
|
||||
let mut items: Vec<VideoItem> = Vec::new();
|
||||
let video_items = match json.as_array(){
|
||||
Some(array) => array,
|
||||
let mut items = Vec::new();
|
||||
let array = match json.as_array() {
|
||||
Some(a) => a,
|
||||
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"){
|
||||
|
||||
for video in array {
|
||||
let file = match video.get("file") { Some(v) => v, None => continue };
|
||||
let hls = match file.get("hls_resources") { Some(v) => v, None => continue };
|
||||
let key = match hls.get("fl_cdn_multi").and_then(|v| v.as_str()) {
|
||||
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::<Vec<String>>()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
None => Vec::new(),
|
||||
};
|
||||
|
||||
let id = file.get("id").and_then(|v| v.as_i64()).unwrap_or(0).to_string();
|
||||
let title = video
|
||||
.get("data")
|
||||
.and_then(|v| v.get(0))
|
||||
.and_then(|v| v.get("cd_value"))
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| decode(s.as_bytes()).to_string().unwrap_or_default())
|
||||
.unwrap_or_default();
|
||||
|
||||
let duration = file
|
||||
.get("fl_duration")
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(|s| parse_time_to_seconds(s))
|
||||
.unwrap_or(0);
|
||||
|
||||
let views = video
|
||||
.get("fc_facts")
|
||||
.and_then(|v| v.get(0))
|
||||
.and_then(|v| v.get("fc_st_views"))
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(|s| parse_abbreviated_number(s))
|
||||
.unwrap_or(0);
|
||||
|
||||
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(
|
||||
|
||||
let mut item = VideoItem::new(
|
||||
id,
|
||||
title,
|
||||
video_url.to_string(),
|
||||
"beeg".to_string(),
|
||||
format!("https://video.externulls.com/{}", key),
|
||||
"beeg".into(),
|
||||
thumb,
|
||||
duration as u32,
|
||||
);
|
||||
|
||||
if views > 0 {
|
||||
video_item = video_item.views(views);
|
||||
item = item.views(views);
|
||||
}
|
||||
if !tags.is_empty() {
|
||||
video_item = video_item.tags(tags);
|
||||
}
|
||||
items.push(video_item);
|
||||
|
||||
items.push(item);
|
||||
}
|
||||
return items;
|
||||
items
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,32 +359,26 @@ impl Provider for BeegProvider {
|
||||
async fn get_videos(
|
||||
&self,
|
||||
cache: VideoCache,
|
||||
_pool: DbPool,
|
||||
_sort: String,
|
||||
_: DbPool,
|
||||
_: String,
|
||||
query: Option<String>,
|
||||
page: String,
|
||||
_per_page: String,
|
||||
_: String,
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let videos: std::result::Result<Vec<VideoItem>, Error> = match query {
|
||||
Some(q) => {
|
||||
self.query(cache, page.parse::<u8>().unwrap_or(1), &q, options)
|
||||
.await
|
||||
}
|
||||
None => {
|
||||
self.get(cache, page.parse::<u8>().unwrap_or(1), options)
|
||||
.await
|
||||
}
|
||||
let page = page.parse::<u8>().unwrap_or(1);
|
||||
let result = match query {
|
||||
Some(q) => self.query(cache, page, &q, options).await,
|
||||
None => self.get(cache, page, options).await,
|
||||
};
|
||||
match videos {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
println!("Error fetching videos: {}", e);
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
result.unwrap_or_else(|e| {
|
||||
eprintln!("beeg provider error: {}", e);
|
||||
vec![]
|
||||
})
|
||||
}
|
||||
fn get_channel(&self, clientversion: ClientVersion) -> crate::status::Channel {
|
||||
|
||||
fn get_channel(&self, clientversion: ClientVersion) -> Channel {
|
||||
self.build_channel(clientversion)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user