bug prevention with video.url for Hottub38
This commit is contained in:
31
src/api.rs
31
src/api.rs
@@ -111,10 +111,10 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
let clientversion: ClientVersion = match req.headers().get("User-Agent") {
|
||||
Some(v) => match v.to_str() {
|
||||
Ok(useragent) => ClientVersion::parse(useragent)
|
||||
.unwrap_or_else(|| ClientVersion::new(999, 0, "999".to_string())),
|
||||
Err(_) => ClientVersion::new(999, 0, "999".to_string()),
|
||||
.unwrap_or_else(|| ClientVersion::new(999, 0, "Hot%20Tub".to_string())),
|
||||
Err(_) => ClientVersion::new(999, 0, "Hot%20Tub".to_string()),
|
||||
},
|
||||
_ => ClientVersion::new(999, 0, "999".to_string()),
|
||||
_ => ClientVersion::new(999, 0, "Hot%20Tub".to_string()),
|
||||
};
|
||||
|
||||
println!(
|
||||
@@ -962,7 +962,16 @@ async fn videos_post(
|
||||
cache: web::types::State<VideoCache>,
|
||||
pool: web::types::State<DbPool>,
|
||||
requester: web::types::State<Requester>,
|
||||
req: HttpRequest,
|
||||
) -> Result<impl web::Responder, web::Error> {
|
||||
let clientversion: ClientVersion = match req.headers().get("User-Agent") {
|
||||
Some(v) => match v.to_str() {
|
||||
Ok(useragent) => ClientVersion::parse(useragent)
|
||||
.unwrap_or_else(|| ClientVersion::new(999, 0, "Hot%20Tub".to_string())),
|
||||
Err(_) => ClientVersion::new(999, 0, "Hot%20Tub".to_string()),
|
||||
},
|
||||
_ => ClientVersion::new(999, 0, "Hot%20Tub".to_string()),
|
||||
};
|
||||
match video_request.query.as_deref() {
|
||||
Some(query) if query.starts_with("#") => {
|
||||
video_request.query = Some(query.trim_start_matches("#").to_string());
|
||||
@@ -1046,7 +1055,7 @@ async fn videos_post(
|
||||
duration: Some(duration),
|
||||
sort: Some(sort.clone()),
|
||||
};
|
||||
let video_items = provider
|
||||
let mut video_items = provider
|
||||
.get_videos(
|
||||
cache.get_ref().clone(),
|
||||
pool.get_ref().clone(),
|
||||
@@ -1057,6 +1066,20 @@ async fn videos_post(
|
||||
options.clone(),
|
||||
)
|
||||
.await;
|
||||
|
||||
// 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| {
|
||||
if !video.formats.is_none() && video.formats.as_ref().unwrap().len() > 0 {
|
||||
let mut v = video;
|
||||
v.url = v.formats.as_ref().unwrap().last().unwrap().url.clone();
|
||||
return Some(v);
|
||||
}
|
||||
Some(video)
|
||||
}).collect();
|
||||
}
|
||||
|
||||
videos.items = video_items.clone();
|
||||
if video_items.len() == 0 {
|
||||
videos.pageInfo = PageInfo {
|
||||
|
||||
@@ -450,7 +450,7 @@ impl HentaihavenProvider {
|
||||
}
|
||||
|
||||
let video_item =
|
||||
VideoItem::new(id, title, formats.last().unwrap().clone().url, "hentaihaven".into(), thumb, 0)
|
||||
VideoItem::new(id, title, video_url.clone(), "hentaihaven".into(), thumb, 0)
|
||||
.formats(formats)
|
||||
.tags(tags)
|
||||
.views(views)
|
||||
|
||||
@@ -320,7 +320,7 @@ impl JavtifulProvider {
|
||||
let video_item = VideoItem::new(
|
||||
id,
|
||||
title,
|
||||
formats.first().map(|f| f.url.clone()).unwrap_or_default(),
|
||||
video_url,
|
||||
"javtiful".into(),
|
||||
thumb,
|
||||
duration,
|
||||
|
||||
Reference in New Issue
Block a user