fixes and cleanup
This commit is contained in:
64
src/api.rs
64
src/api.rs
@@ -1,15 +1,18 @@
|
||||
use crate::providers::{
|
||||
ALL_PROVIDERS, DynProvider, panic_payload_to_string, report_provider_error,
|
||||
run_provider_guarded,
|
||||
};
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::util::discord::send_discord_error_report;
|
||||
use crate::util::proxy::{Proxy, all_proxies_snapshot};
|
||||
use crate::util::requester::Requester;
|
||||
use crate::{DbPool, db, status::*, videos::*};
|
||||
use ntex::http::header;
|
||||
use ntex::web;
|
||||
use ntex::web::HttpRequest;
|
||||
use std::cmp::Ordering;
|
||||
use std::io;
|
||||
use tokio::task;
|
||||
use crate::providers::{ALL_PROVIDERS, DynProvider, panic_payload_to_string, report_provider_error, run_provider_guarded};
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::util::discord::send_discord_error_report;
|
||||
use crate::util::proxy::{Proxy, all_proxies_snapshot};
|
||||
use crate::util::requester::Requester;
|
||||
use crate::{DbPool, db, status::*, videos::*};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ClientVersion {
|
||||
@@ -119,10 +122,9 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
let mut status = Status::new();
|
||||
|
||||
for (provider_name, provider) in ALL_PROVIDERS.iter() {
|
||||
let channel_result =
|
||||
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
provider.get_channel(clientversion.clone())
|
||||
}));
|
||||
let channel_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
provider.get_channel(clientversion.clone())
|
||||
}));
|
||||
match channel_result {
|
||||
Ok(Some(channel)) => status.add_channel(channel),
|
||||
Ok(None) => {}
|
||||
@@ -218,7 +220,16 @@ async fn videos_post(
|
||||
.as_deref()
|
||||
.unwrap_or("all")
|
||||
.to_string();
|
||||
let sites = video_request.sites.as_deref().unwrap_or("").to_string();
|
||||
let sites = if channel == "all" {
|
||||
video_request
|
||||
.all_provider_sites
|
||||
.as_deref()
|
||||
.or(video_request.sites.as_deref())
|
||||
.unwrap_or("")
|
||||
.to_string()
|
||||
} else {
|
||||
video_request.sites.as_deref().unwrap_or("").to_string()
|
||||
};
|
||||
let filter = video_request.filter.as_deref().unwrap_or("new").to_string();
|
||||
let language = video_request
|
||||
.language
|
||||
@@ -261,22 +272,25 @@ async fn videos_post(
|
||||
)
|
||||
.await;
|
||||
|
||||
// There is a bug in Hottub38 that makes the client error for a 403-url even though formats work fine
|
||||
// There is a bug in Hottub38 that makes the client error for a 403-url even though formats work fine
|
||||
if clientversion == ClientVersion::new(38, 0, "Hot%20Tub".to_string()) {
|
||||
// filter out videos without preview for old clients
|
||||
video_items = video_items.into_iter().filter_map(|video| {
|
||||
let last_url = video
|
||||
.formats
|
||||
.as_ref()
|
||||
.and_then(|formats| formats.last().map(|f| f.url.clone()));
|
||||
if let Some(url) = last_url {
|
||||
let mut v = video;
|
||||
v.url = url;
|
||||
return Some(v);
|
||||
}
|
||||
Some(video)
|
||||
}).collect();
|
||||
}
|
||||
video_items = video_items
|
||||
.into_iter()
|
||||
.filter_map(|video| {
|
||||
let last_url = video
|
||||
.formats
|
||||
.as_ref()
|
||||
.and_then(|formats| formats.last().map(|f| f.url.clone()));
|
||||
if let Some(url) = last_url {
|
||||
let mut v = video;
|
||||
v.url = url;
|
||||
return Some(v);
|
||||
}
|
||||
Some(video)
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
|
||||
videos.items = video_items.clone();
|
||||
if video_items.len() == 0 {
|
||||
|
||||
Reference in New Issue
Block a user