Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

fix(bilibili): stop treating cheese episodes as playlists; respect page selection in collections

Antonio Leandroac181b51c25c
diff --git a/src-tauri/omniget-core/src/platforms/bilibili/legacy.rs b/src-tauri/omniget-core/src/platforms/bilibili/legacy.rs
index 67f97629..4e000527 100644
--- a/src-tauri/omniget-core/src/platforms/bilibili/legacy.rs
+++ b/src-tauri/omniget-core/src/platforms/bilibili/legacy.rs
@@ -12,7 +12,12 @@ use crate::models::media::{
pub fn is_playlist_or_series(url: &str) -> bool {
if let Ok(parsed) = url::Url::parse(url) {
let path = parsed.path();
- if path.starts_with("/bangumi/") || path.starts_with("/cheese/") {
+ // Note: /cheese/ URLs are intentionally NOT classified as playlists.
+ // Single-episode cheese URLs (/cheese/play/epNNN) must go through
+ // get_video_info with --no-playlist; yt-dlp's cheese season extractor
+ // emits flat-playlist entries without a top-level "url" key, which
+ // breaks the playlist path (issue #157).
+ if path.starts_with("/bangumi/") {
return true;
}
if path.contains("/channel/") || path.contains("/favlist/") || path.contains("/medialist/")
@@ -228,6 +233,8 @@ async fn download_playlist(
duration_seconds: 0.0,
torrent_id: None,
};
+ let mut success_count: usize = 0;
+ let mut first_error: Option<anyhow::Error> = None;
for (i, quality) in info.available_qualities.iter().enumerate() {
if opts.cancel_token.is_cancelled() {
@@ -270,16 +277,71 @@ async fn download_playlist(
.await
{
Ok(result) => {
+ success_count += 1;
last_result.file_size_bytes += result.file_size_bytes;
last_result.duration_seconds += result.duration_seconds;
last_result.file_path = result.file_path;
}
Err(e) => {
tracing::error!("[bilibili] playlist item {} failed: {}", i + 1, e);
+ if first_error.is_none() {
+ first_error = Some(e);
+ }
}
}
}
+ if success_count == 0 {
+ let detail = first_error
+ .map(|e| e.to_string())
+ .unwrap_or_else(|| "unknown error".to_string());
+ return Err(anyhow!(
+ "All {} playlist item(s) failed to download. First error: {}",
+ total,
+ detail
+ ));
+ }
+
let _ = progress.send(ProgressUpdate::percent(100.0)).await;
Ok(last_result)
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn cheese_episode_is_not_playlist() {
+ assert!(!is_playlist_or_series(
+ "https://www.bilibili.com/cheese/play/ep2143"
+ ));
+ }
+
+ #[test]
+ fn cheese_season_is_not_playlist() {
+ assert!(!is_playlist_or_series(
+ "https://www.bilibili.com/cheese/play/ss123"
+ ));
+ }
+
+ #[test]
+ fn bangumi_is_playlist() {
+ assert!(is_playlist_or_series(
+ "https://www.bilibili.com/bangumi/play/ss12345"
+ ));
+ }
+
+ #[test]
+ fn medialist_is_playlist() {
+ assert!(is_playlist_or_series(
+ "https://www.bilibili.com/medialist/detail/ml123"
+ ));
+ }
+
+ #[test]
+ fn plain_video_is_not_playlist() {
+ assert!(!is_playlist_or_series(
+ "https://www.bilibili.com/video/BV1xx411c7mu"
+ ));
+ }
+}
diff --git a/src-tauri/omniget-core/src/platforms/bilibili/parser/video.rs b/src-tauri/omniget-core/src/platforms/bilibili/parser/video.rs
index af67a00e..1d233c44 100644
--- a/src-tauri/omniget-core/src/platforms/bilibili/parser/video.rs
+++ b/src-tauri/omniget-core/src/platforms/bilibili/parser/video.rs
@@ -78,48 +78,68 @@ pub async fn parse(
// Try to match the requested bvid against ugc_season episodes.
// If found, return only that single episode (preserving user intent).
// If not found, fall through to normal single-video handling below.
- if let Some(sections) = season.get("sections").and_then(Value::as_array) {
- for sec in sections {
- if let Some(eps) = sec.get("episodes").and_then(Value::as_array) {
- for ep in eps {
- let ep_bvid = ep.get("bvid").and_then(Value::as_str).unwrap_or("");
- if ep_bvid == bvid {
- let ep_aid = ep.get("aid").and_then(Value::as_u64);
- let ep_cid = ep.get("cid").and_then(Value::as_u64);
- let ep_title = ep
- .get("title")
- .and_then(Value::as_str)
- .unwrap_or("")
- .to_string();
- let arc = ep.get("arc");
- let dur = arc.and_then(|a| a.get("duration")).and_then(Value::as_f64);
- let cover_ep = arc
- .and_then(|a| a.get("pic"))
- .and_then(Value::as_str)
- .map(String::from);
- let pub_ep = arc.and_then(|a| a.get("pubdate")).and_then(Value::as_u64);
- let item = EpisodeItem {
- episode_id: format!("ugc:{}", ep_bvid),
- title: ep_title,
- aid: ep_aid,
- bvid: Some(ep_bvid.to_string()),
- cid: ep_cid,
- duration_seconds: dur,
- cover_url: cover_ep,
- pub_time_secs: pub_ep,
- section_title: sec
+ //
+ // Skip this shortcut when the caller requested a specific page (?p=N)
+ // or when the video itself has multiple pages: a multi-page video
+ // inside a collection must be handled by the pages branch below,
+ // otherwise only page 1 gets downloaded (issue #146).
+ let has_multiple_pages = data
+ .get("pages")
+ .and_then(Value::as_array)
+ .map(|p| p.len() > 1)
+ .unwrap_or(false);
+ if page_filter.is_none() && !has_multiple_pages {
+ if let Some(sections) = season.get("sections").and_then(Value::as_array) {
+ let mut ep_index: u32 = 0;
+ for sec in sections {
+ if let Some(eps) = sec.get("episodes").and_then(Value::as_array) {
+ for ep in eps {
+ ep_index += 1;
+ let ep_bvid = ep.get("bvid").and_then(Value::as_str).unwrap_or("");
+ if ep_bvid == bvid {
+ let ep_aid = ep.get("aid").and_then(Value::as_u64);
+ let ep_cid = ep.get("cid").and_then(Value::as_u64);
+ let ep_title = ep
.get("title")
.and_then(Value::as_str)
- .map(String::from),
- url: Some(format!("https://www.bilibili.com/video/{}", ep_bvid)),
- ..EpisodeItem::default()
- };
- return Ok(ParsedContent {
- title,
- items: vec![item],
- metadata,
- pagination: None,
- });
+ .unwrap_or("")
+ .to_string();
+ let arc = ep.get("arc");
+ let dur =
+ arc.and_then(|a| a.get("duration")).and_then(Value::as_f64);
+ let cover_ep = arc
+ .and_then(|a| a.get("pic"))
+ .and_then(Value::as_str)
+ .map(String::from);
+ let pub_ep =
+ arc.and_then(|a| a.get("pubdate")).and_then(Value::as_u64);
+ let item = EpisodeItem {
+ episode_id: format!("ugc:{}", ep_bvid),
+ title: ep_title,
+ aid: ep_aid,
+ bvid: Some(ep_bvid.to_string()),
+ cid: ep_cid,
+ duration_seconds: dur,
+ cover_url: cover_ep,
+ pub_time_secs: pub_ep,
+ section_title: sec
+ .get("title")
+ .and_then(Value::as_str)
+ .map(String::from),
+ episode_number: Some(ep_index),
+ url: Some(format!(
+ "https://www.bilibili.com/video/{}",
+ ep_bvid
+ )),
+ ..EpisodeItem::default()
+ };
+ return Ok(ParsedContent {
+ title,
+ items: vec![item],
+ metadata,
+ pagination: None,
+ });
+ }
}
}
}