sites applied
This commit is contained in:
@@ -11,7 +11,7 @@ use error_chain::error_chain;
|
||||
use htmlentity::entity::{ICodedDataTrait, decode};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::vec;
|
||||
use std::{env, thread};
|
||||
use std::{thread};
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
@@ -25,6 +25,7 @@ pub struct OmgxxxProvider {
|
||||
url: String,
|
||||
sites: Arc<RwLock<Vec<FilterOption>>>,
|
||||
networks: Arc<RwLock<Vec<FilterOption>>>,
|
||||
stars: Arc<RwLock<Vec<FilterOption>>>,
|
||||
}
|
||||
impl OmgxxxProvider {
|
||||
pub fn new() -> Self {
|
||||
@@ -38,6 +39,10 @@ impl OmgxxxProvider {
|
||||
id: "all".to_string(),
|
||||
title: "All".to_string(),
|
||||
}])),
|
||||
stars: Arc::new(RwLock::new(vec![FilterOption {
|
||||
id: "all".to_string(),
|
||||
title: "All".to_string(),
|
||||
}])),
|
||||
};
|
||||
|
||||
// Kick off the background load but return immediately
|
||||
@@ -70,6 +75,44 @@ impl OmgxxxProvider {
|
||||
});
|
||||
}
|
||||
|
||||
async fn load_stars(base_url: &str, networks: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
let mut requester = util::requester::Requester::new();
|
||||
let mut page = 0;
|
||||
loop {
|
||||
page += 1;
|
||||
let text = requester
|
||||
.get(format!("{}/sites/{}/", &base_url, page).as_str())
|
||||
.await
|
||||
.unwrap();
|
||||
if text.contains("404 Not Found") || text.is_empty() {
|
||||
break;
|
||||
}
|
||||
let sites_div = text
|
||||
.split("id=\"list_content_sources_sponsors_list_items\"").collect::<Vec<&str>>()[1]
|
||||
.split("class=\"pagination\"").collect::<Vec<&str>>()[0];
|
||||
for sites_element in
|
||||
sites_div.split("class=\"headline\"").collect::<Vec<&str>>()[1..].to_vec()
|
||||
{
|
||||
let site_url = sites_element.split("href=\"").collect::<Vec<&str>>()[1]
|
||||
.split("\"")
|
||||
.collect::<Vec<&str>>()[0];
|
||||
let site_id = site_url.split("/").collect::<Vec<&str>>()[4].to_string();
|
||||
let site_name = sites_element.split("<h2>").collect::<Vec<&str>>()[1]
|
||||
.split("<")
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.to_string();
|
||||
Self::push_unique(
|
||||
&networks,
|
||||
FilterOption {
|
||||
id: site_id,
|
||||
title: site_name,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
async fn load_sites(base_url: &str, networks: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
let mut requester = util::requester::Requester::new();
|
||||
let mut page = 0;
|
||||
@@ -237,6 +280,12 @@ impl OmgxxxProvider {
|
||||
{
|
||||
sort_string = format!("networks/{}", options.network.as_ref().unwrap());
|
||||
}
|
||||
if options.sites.is_some()
|
||||
&& !options.sites.as_ref().unwrap().is_empty()
|
||||
&& options.sites.as_ref().unwrap() != "all"
|
||||
{
|
||||
sort_string = format!("sites/{}", options.network.as_ref().unwrap());
|
||||
}
|
||||
let video_url = format!("{}/{}/{}/", self.url, sort_string, page);
|
||||
let old_items = match cache.get(&video_url) {
|
||||
Some((time, items)) => {
|
||||
|
||||
Reference in New Issue
Block a user