updates, enables networks on omgxxx
This commit is contained in:
12
src/api.rs
12
src/api.rs
@@ -20,7 +20,7 @@ use crate::util::requester::Requester;
|
||||
use crate::{DbPool, db, status::*, videos::*};
|
||||
use cute::c;
|
||||
use std::sync::Arc;
|
||||
use crate::providers::{Provider, DynProvider, ALL_PROVIDERS};
|
||||
use crate::providers::{DynProvider, ALL_PROVIDERS};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ClientVersion {
|
||||
@@ -1138,10 +1138,6 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
}
|
||||
|
||||
for provider in ALL_PROVIDERS.values() {
|
||||
println!(
|
||||
"Loaded provider (dyn): {:?}",
|
||||
std::any::type_name::<&dyn Provider>()
|
||||
);
|
||||
status.add_channel(provider.get_channel(clientversion.clone()));
|
||||
}
|
||||
status.iconUrl = format!("http://{}/favicon.ico", host).to_string();
|
||||
@@ -1214,6 +1210,11 @@ async fn videos_post(
|
||||
.as_deref()
|
||||
.unwrap_or("en")
|
||||
.to_string();
|
||||
let network = video_request
|
||||
.networks
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let options = ServerOptions {
|
||||
featured: Some(featured),
|
||||
category: Some(category),
|
||||
@@ -1221,6 +1222,7 @@ async fn videos_post(
|
||||
filter: Some(filter),
|
||||
language: Some(language),
|
||||
requester: Some(requester),
|
||||
network: Some(network),
|
||||
};
|
||||
let video_items = provider
|
||||
.get_videos(
|
||||
|
||||
@@ -28,7 +28,6 @@ pub struct OmgxxxProvider {
|
||||
}
|
||||
impl OmgxxxProvider {
|
||||
pub fn new() -> Self {
|
||||
println!("new");
|
||||
let provider = OmgxxxProvider {
|
||||
url: "https://www.omg.xxx".to_string(),
|
||||
sites: Arc::new(RwLock::new(vec![])),
|
||||
@@ -41,7 +40,6 @@ impl OmgxxxProvider {
|
||||
}
|
||||
|
||||
fn spawn_initial_load(&self) {
|
||||
println!("spawn_initial_load");
|
||||
let url = self.url.clone();
|
||||
// let sites = Arc::clone(&self.sites);
|
||||
let networks = Arc::clone(&self.networks);
|
||||
@@ -85,7 +83,6 @@ impl OmgxxxProvider {
|
||||
// }
|
||||
|
||||
async fn load_networks(base_url: &str, networks: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
println!("load_networks");
|
||||
let mut requester = util::requester::Requester::new();
|
||||
let text = requester.get(&base_url).await.unwrap();
|
||||
let networks_div = text.split("class=\"sites__list\"").collect::<Vec<&str>>()[1]
|
||||
@@ -199,11 +196,14 @@ impl OmgxxxProvider {
|
||||
sort: &str,
|
||||
options: ServerOptions,
|
||||
) -> Result<Vec<VideoItem>> {
|
||||
let sort_string = match sort {
|
||||
"top-rated" => "top-rated",
|
||||
"most-popular" => "most-popular",
|
||||
_ => "latest-updates",
|
||||
let mut sort_string:String = match sort {
|
||||
"top-rated" => "top-rated".to_string(),
|
||||
"most-popular" => "most-popular".to_string(),
|
||||
_ => "latest-updates".to_string(),
|
||||
};
|
||||
if options.network.is_some() && !options.network.as_ref().unwrap().is_empty(){
|
||||
sort_string = format!("networks/{}",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)) => {
|
||||
@@ -219,6 +219,7 @@ impl OmgxxxProvider {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let text = requester.get(&video_url).await.unwrap();
|
||||
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone());
|
||||
@@ -427,10 +428,6 @@ impl Provider for OmgxxxProvider {
|
||||
}
|
||||
}
|
||||
fn get_channel(&self, clientversion: ClientVersion) -> crate::status::Channel {
|
||||
println!(
|
||||
"Getting channel for omgxxx with client version: {:?}",
|
||||
clientversion
|
||||
);
|
||||
self.build_channel(clientversion)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ pub struct VideosRequest {
|
||||
pub sites: Option<String>, //
|
||||
pub filter: Option<String>, //
|
||||
pub language: Option<String>, //
|
||||
pub networks: Option<String>, //
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
|
||||
@@ -40,6 +41,7 @@ pub struct ServerOptions {
|
||||
pub filter: Option<String>,
|
||||
pub language: Option<String>, // "en"
|
||||
pub requester: Option<Requester>,
|
||||
pub network: Option<String>, //
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user