fix: douyin segment with params

This commit is contained in:
Xinrea
2025-10-29 00:28:00 +08:00
parent b4fb2d058a
commit ed0bd88e3b
2 changed files with 13 additions and 3 deletions

View File

@@ -412,6 +412,7 @@ mod tests {
).await.unwrap();
assert_eq!(stream.index(), "https://hs.hls.huya.com/huyalive/156976698-156976698-674209784144068608-314076852-10057-A-0-1.m3u8?ratio=2000&wsSecret=7abc7dec8809146f31f92046eb044e3b&wsTime=68fa41ba&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&t=103");
assert_eq!(stream.ts_url("1.ts"), "https://hs.hls.huya.com/huyalive/1.ts?ratio=2000&wsSecret=7abc7dec8809146f31f92046eb044e3b&wsTime=68fa41ba&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&t=103");
assert_eq!(stream.ts_url("1.ts?expires=1760808243"), "https://hs.hls.huya.com/huyalive/1.ts?expires=1760808243&ratio=2000&wsSecret=7abc7dec8809146f31f92046eb044e3b&wsTime=68fa41ba&fm=RFdxOEJjSjNoNkRKdDZUWV8kMF8kMV8kMl8kMw%3D%3D&ctype=tars_mobile&fs=bgct&t=103");
assert_eq!(stream.host, "https://hs.hls.huya.com");
assert_eq!(
stream.base,

View File

@@ -80,9 +80,18 @@ impl HlsStream {
if self.extra.is_empty() {
format!("{}{}", self.host, base_url)
} else {
// Remove the trailing '?' from base_url and add it properly
let base_without_query = base_url.trim_end_matches('?');
format!("{}{}?{}", self.host, base_without_query, self.extra)
// Check if base_url already contains query parameters
if base_url.contains('?') {
// If seg_name already has query params, append extra with '&'
// Remove trailing '?' or '&' before appending
let base_trimmed = base_url.trim_end_matches('?').trim_end_matches('&');
format!("{}{}&{}", self.host, base_trimmed, self.extra)
} else {
// If no query params, add them with '?'
// Remove trailing '?' from base_url if present
let base_without_query = base_url.trim_end_matches('?');
format!("{}{}?{}", self.host, base_without_query, self.extra)
}
}
}
}