bug prevention with video.url for Hottub38

This commit is contained in:
Simon
2026-02-26 11:05:32 +00:00
parent 4ad9453245
commit 060d8e7937
3 changed files with 29 additions and 6 deletions

View File

@@ -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 {