Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
Add parsers for Bilibili content types
Tonho6ff213cd061e
diff --git a/src-tauri/src/platforms/bilibili/engine/mux.rs b/src-tauri/src/platforms/bilibili/engine/mux.rsnew file mode 100644index 00000000..bec725ac--- /dev/null+++ b/src-tauri/src/platforms/bilibili/engine/mux.rs@@ -0,0 +1,90 @@+use std::path::{Path, PathBuf};++use omniget_core::core::process;++use super::super::api::{BilibiliError, Result};++#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum Container {+ Mp4,+ Mkv,+}++impl Container {+ pub fn extension(self) -> &'static str {+ match self {+ Container::Mp4 => "mp4",+ Container::Mkv => "mkv",+ }+ }+}++pub struct MuxInputs<'a> {+ pub video: &'a Path,+ pub audio: &'a Path,+ pub cover: Option<&'a Path>,+ pub output: &'a Path,+ pub container: Container,+}++pub async fn mux(inputs: MuxInputs<'_>) -> Result<PathBuf> {+ if let Some(parent) = inputs.output.parent() {+ std::fs::create_dir_all(parent).ok();+ }++ let mut args: Vec<String> = Vec::new();+ args.push("-y".into());+ args.push("-i".into());+ args.push(inputs.video.to_string_lossy().into_owned());+ args.push("-i".into());+ args.push(inputs.audio.to_string_lossy().into_owned());++ if let Some(cover_path) = inputs.cover {+ args.push("-i".into());+ args.push(cover_path.to_string_lossy().into_owned());+ }++ args.push("-map".into());+ args.push("0:v:0".into());+ args.push("-map".into());+ args.push("1:a:0".into());++ if inputs.cover.is_some() {+ args.push("-map".into());+ args.push("2:v:0".into());+ }++ args.push("-c:v".into());+ args.push("copy".into());+ args.push("-c:a".into());+ args.push("copy".into());++ if inputs.cover.is_some() && inputs.container == Container::Mp4 {+ args.push("-c:v:1".into());+ args.push("mjpeg".into());+ args.push("-disposition:v:1".into());+ args.push("attached_pic".into());+ args.push("-pix_fmt:v:1".into());+ args.push("yuvj420p".into());+ }++ if inputs.container == Container::Mp4 {+ args.push("-movflags".into());+ args.push("+faststart".into());+ }++ args.push(inputs.output.to_string_lossy().into_owned());++ let status = process::command("ffmpeg")+ .args(args.iter().map(|s| s.as_str()))+ .stdout(std::process::Stdio::null())+ .stderr(std::process::Stdio::null())+ .status()+ .await+ .map_err(|_| BilibiliError::ContentUnavailable)?;++ if !status.success() {+ return Err(BilibiliError::ContentUnavailable);+ }+ Ok(inputs.output.to_path_buf())+}diff --git a/src-tauri/src/platforms/bilibili/engine/query.rs b/src-tauri/src/platforms/bilibili/engine/query.rsnew file mode 100644index 00000000..7e3b9fcd--- /dev/null+++ b/src-tauri/src/platforms/bilibili/engine/query.rs@@ -0,0 +1,75 @@+use super::super::api::{ApiClient, BilibiliError, Result};+use super::super::cdn;++const MIN_VALID_SIZE: u64 = 10 * 1024;++#[derive(Debug, Clone)]+pub struct ResolvedStream {+ pub url: String,+ pub size: u64,+}++#[derive(Debug, Clone, Default)]+pub struct CdnPreferences {+ pub alt_hosts: Vec<String>,+ pub prefer_alternatives: bool,+}++pub async fn resolve_best_url(+ client: &ApiClient,+ primary: &str,+ backups: &[String],+) -> Result<ResolvedStream> {+ resolve_best_url_with_cdn(client, primary, backups, &CdnPreferences::default()).await+}++pub async fn resolve_best_url_with_cdn(+ client: &ApiClient,+ primary: &str,+ backups: &[String],+ cdn_prefs: &CdnPreferences,+) -> Result<ResolvedStream> {+ let chain = if cdn_prefs.alt_hosts.is_empty() {+ let mut filtered = cdn::filter_blocked(+ &std::iter::once(primary.to_string())+ .chain(backups.iter().cloned())+ .collect::<Vec<_>>(),+ );+ if filtered.is_empty() {+ filtered.push(primary.to_string());+ }+ filtered+ } else {+ cdn::expand_with_alternatives(+ primary,+ backups,+ &cdn_prefs.alt_hosts,+ cdn_prefs.prefer_alternatives,+ )+ };++ let mut last_err: Option<BilibiliError> = None;+ for url in &chain {+ match client.head_content_length(url).await {+ Ok(Some(size)) if size >= MIN_VALID_SIZE => {+ return Ok(ResolvedStream {+ url: url.clone(),+ size,+ });+ }+ Ok(Some(_)) => {+ last_err = Some(BilibiliError::ContentUnavailable);+ }+ Ok(None) => {+ return Ok(ResolvedStream {+ url: url.clone(),+ size: 0,+ });+ }+ Err(e) => {+ last_err = Some(e);+ }+ }+ }+ Err(last_err.unwrap_or(BilibiliError::ContentUnavailable))+}diff --git a/src-tauri/src/platforms/bilibili/parser/bangumi.rs b/src-tauri/src/platforms/bilibili/parser/bangumi.rsnew file mode 100644index 00000000..b26a31c5--- /dev/null+++ b/src-tauri/src/platforms/bilibili/parser/bangumi.rs@@ -0,0 +1,246 @@+use serde_json::Value;++use super::super::api::{check_api_response, ApiClient, BilibiliError, Result};+use super::{ContentMetadata, EpisodeItem, ParsedContent};++const SEASON_URL: &str = "https://api.bilibili.com/pgc/view/web/season";+const REVIEW_USER_URL: &str = "https://api.bilibili.com/pgc/review/user";++pub async fn parse_by_ep(client: &ApiClient, ep_id: u64) -> Result<ParsedContent> {+ let url = format!("{}?ep_id={}", SEASON_URL, ep_id);+ let raw = client.get_json(&url).await?;+ let result = check_api_response(&raw)?;+ build_parsed_content(result, Some(ep_id))+}++pub async fn parse_by_season(client: &ApiClient, season_id: u64) -> Result<ParsedContent> {+ let url = format!("{}?season_id={}", SEASON_URL, season_id);+ let raw = client.get_json(&url).await?;+ let result = check_api_response(&raw)?;+ build_parsed_content(result, None)+}++pub async fn parse_by_media(client: &ApiClient, media_id: u64) -> Result<ParsedContent> {+ let lookup_url = format!("{}?media_id={}", REVIEW_USER_URL, media_id);+ let raw = client.get_json(&lookup_url).await?;+ let data = check_api_response(&raw)?;+ let season_id = data+ .get("media")+ .and_then(|m| m.get("season_id"))+ .and_then(Value::as_u64)+ .ok_or(BilibiliError::ContentUnavailable)?;+ parse_by_season(client, season_id).await+}++fn build_parsed_content(result: &Value, highlight_ep: Option<u64>) -> Result<ParsedContent> {+ let series_title = result+ .get("series")+ .and_then(|s| s.get("series_title"))+ .and_then(Value::as_str)+ .map(String::from);+ let season_title = result+ .get("season_title")+ .and_then(Value::as_str)+ .map(String::from);+ let title = series_title+ .clone()+ .or_else(|| season_title.clone())+ .unwrap_or_else(|| "Bilibili Bangumi".to_string());++ let cover = result+ .get("cover")+ .and_then(Value::as_str)+ .map(String::from);+ let poster = result+ .get("bkg_cover")+ .and_then(Value::as_str)+ .or_else(|| result.get("horizontal_cover").and_then(Value::as_str))+ .map(String::from)+ .or_else(|| cover.clone());+ let description = result+ .get("evaluate")+ .and_then(Value::as_str)+ .map(String::from);+ let media_id = result.get("media_id").and_then(Value::as_u64);+ let season_id = result.get("season_id").and_then(Value::as_u64);+ let actors = result+ .get("actors")+ .and_then(Value::as_str)+ .map(String::from);+ let rating = result+ .get("rating")+ .and_then(|r| r.get("score"))+ .and_then(Value::as_f64)+ .map(|v| v as f32);+ let premiered = result+ .get("publish")+ .and_then(|p| p.get("pub_time"))+ .and_then(Value::as_str)+ .and_then(parse_pub_time)+ .or_else(|| {+ result+ .get("publish")+ .and_then(|p| p.get("pub_time_show"))+ .and_then(Value::as_str)+ .and_then(parse_pub_time)+ });+ let areas: Vec<String> = result+ .get("areas")+ .and_then(Value::as_array)+ .map(|arr| {+ arr.iter()+ .filter_map(|a| a.get("name").and_then(Value::as_str).map(String::from))+ .collect()+ })+ .unwrap_or_default();+ let styles: Vec<String> = result+ .get("styles")+ .and_then(Value::as_array)+ .map(|arr| {+ arr.iter()+ .filter_map(|s| s.as_str().map(String::from))+ .collect()+ })+ .unwrap_or_default();+ let uploader = result+ .get("up_info")+ .and_then(|u| u.get("uname"))+ .and_then(Value::as_str)+ .map(String::from);+ let uploader_uid = result+ .get("up_info")+ .and_then(|u| u.get("mid"))+ .and_then(Value::as_u64);+ let uploader_avatar = result+ .get("up_info")+ .and_then(|u| u.get("avatar"))+ .and_then(Value::as_str)+ .map(String::from);++ let metadata = ContentMetadata {+ series_title: series_title.clone().or_else(|| Some(title.clone())),+ season_title,+ season_id,+ media_id,+ uploader,+ uploader_uid,+ uploader_avatar,+ description,+ cover: cover.clone(),+ poster,+ areas,+ styles,+ actors,+ rating,+ premiered_secs: premiered,+ ..ContentMetadata::default()+ };++ let mut items: Vec<EpisodeItem> = Vec::new();+ let mut counter: u32 = 0;+ if let Some(eps) = result.get("episodes").and_then(Value::as_array) {+ for ep in eps {+ if let Some(item) = build_episode_item(ep, None, &mut counter, false) {+ items.push(item);+ }+ }+ }+ if let Some(secs) = result.get("section").and_then(Value::as_array) {+ for sec in secs {+ let section_title = sec+ .get("title")+ .and_then(Value::as_str)+ .map(String::from);+ let is_preview = section_title+ .as_deref()+ .map(|t| t.contains("预告") || t.contains("PV"))+ .unwrap_or(false);+ if let Some(eps) = sec.get("episodes").and_then(Value::as_array) {+ for ep in eps {+ if let Some(item) =+ build_episode_item(ep, section_title.clone(), &mut counter, is_preview)+ {+ items.push(item);+ }+ }+ }+ }+ }+ let _ = highlight_ep;+ if items.is_empty() {+ return Err(BilibiliError::ContentUnavailable);+ }+ Ok(ParsedContent {+ title,+ items,+ metadata,+ pagination: None,+ })+}++fn build_episode_item(+ ep: &Value,+ section_title: Option<String>,+ counter: &mut u32,+ is_preview_section: bool,+) -> Option<EpisodeItem> {+ let bvid = ep.get("bvid").and_then(Value::as_str)?;+ let cid = ep.get("cid").and_then(Value::as_u64);+ let aid = ep.get("aid").and_then(Value::as_u64);+ let ep_id = ep.get("id").and_then(Value::as_u64).or_else(|| ep.get("ep_id").and_then(Value::as_u64));+ let title = ep+ .get("long_title")+ .and_then(Value::as_str)+ .filter(|s| !s.is_empty())+ .or_else(|| ep.get("show_title").and_then(Value::as_str))+ .or_else(|| ep.get("title").and_then(Value::as_str))+ .unwrap_or("")+ .to_string();+ let duration_ms = ep.get("duration").and_then(Value::as_f64);+ let duration_seconds = duration_ms.map(|ms| ms / 1000.0);+ let cover = ep+ .get("cover")+ .and_then(Value::as_str)+ .map(String::from);+ let pub_time = ep.get("pub_time").and_then(Value::as_u64);+ let badge_raw = ep.get("badge").and_then(Value::as_str).unwrap_or("");+ let is_preview =+ is_preview_section || badge_raw.contains("预告") || badge_raw.contains("PV");+ let badge = if is_preview {+ Some("badge.bilibili.preview".to_string())+ } else if badge_raw.contains("充电") {+ Some("badge.bilibili.charging_exclusive".to_string())+ } else if !badge_raw.is_empty() {+ Some(badge_raw.to_string())+ } else {+ None+ };+ let episode_number = if is_preview {+ None+ } else {+ *counter += 1;+ Some(*counter)+ };+ Some(EpisodeItem {+ episode_id: format!("ep:{}", ep_id.unwrap_or(0)),+ title,+ aid,+ bvid: Some(bvid.to_string()),+ cid,+ ep_id,+ duration_seconds,+ cover_url: cover,+ pub_time_secs: pub_time,+ badge,+ section_title,+ episode_number,+ url: ep_id.map(|id| format!("https://www.bilibili.com/bangumi/play/ep{}", id)),+ ..EpisodeItem::default()+ })+}++fn parse_pub_time(s: &str) -> Option<u64> {+ chrono::NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S")+ .ok()+ .map(|dt| dt.and_utc().timestamp().max(0) as u64)+}diff --git a/src-tauri/src/platforms/bilibili/parser/cheese.rs b/src-tauri/src/platforms/bilibili/parser/cheese.rsnew file mode 100644index 00000000..4d827374--- /dev/null+++ b/src-tauri/src/platforms/bilibili/parser/cheese.rs@@ -0,0 +1,137 @@+use serde_json::Value;++use super::super::api::{check_api_response, ApiClient, BilibiliError, Result};+use super::{ContentMetadata, EpisodeItem, ParsedContent};++const SEASON_URL: &str = "https://api.bilibili.com/pugv/view/web/season/v2";++pub async fn parse_by_ep(client: &ApiClient, ep_id: u64) -> Result<ParsedContent> {+ let url = format!("{}?ep_id={}", SEASON_URL, ep_id);+ let raw = client.get_json(&url).await?;+ let data = check_api_response(&raw)?;+ build_parsed_content(data)+}++pub async fn parse_by_season(client: &ApiClient, season_id: u64) -> Result<ParsedContent> {+ let url = format!("{}?season_id={}", SEASON_URL, season_id);+ let raw = client.get_json(&url).await?;+ let data = check_api_response(&raw)?;+ build_parsed_content(data)+}++fn build_parsed_content(data: &Value) -> Result<ParsedContent> {+ let title = data+ .get("title")+ .and_then(Value::as_str)+ .unwrap_or("Bilibili Course")+ .to_string();+ let cover = data+ .get("cover")+ .and_then(Value::as_str)+ .map(String::from);+ let description = data+ .get("subtitle")+ .and_then(Value::as_str)+ .map(String::from);+ let season_id = data.get("season_id").and_then(Value::as_u64);+ let uploader = data+ .get("up_info")+ .and_then(|u| u.get("uname"))+ .and_then(Value::as_str)+ .map(String::from);+ let uploader_uid = data+ .get("up_info")+ .and_then(|u| u.get("mid"))+ .and_then(Value::as_u64);+ let uploader_avatar = data+ .get("up_info")+ .and_then(|u| u.get("avatar"))+ .and_then(Value::as_str)+ .map(String::from);++ let mut items: Vec<EpisodeItem> = Vec::new();+ let mut counter: u32 = 0;+ let mut first_release: Option<u64> = None;+ if let Some(secs) = data.get("sections").and_then(Value::as_array) {+ for sec in secs {+ let section_title = sec+ .get("title")+ .and_then(Value::as_str)+ .map(String::from);+ if let Some(eps) = sec.get("episodes").and_then(Value::as_array) {+ for ep in eps {+ let aid = ep.get("aid").and_then(Value::as_u64);+ let cid = ep.get("cid").and_then(Value::as_u64);+ let ep_id = ep+ .get("id")+ .and_then(Value::as_u64)+ .or_else(|| ep.get("ep_id").and_then(Value::as_u64));+ let title_ep = ep+ .get("title")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let dur = ep.get("duration").and_then(Value::as_f64);+ let cover_ep = ep+ .get("cover")+ .and_then(Value::as_str)+ .map(String::from);+ let release = ep.get("release_date").and_then(Value::as_u64);+ if first_release.is_none() && release.is_some() {+ first_release = release;+ }+ let status = ep.get("status").and_then(Value::as_u64).unwrap_or(0);+ let badge = match status {+ 2 => Some("badge.bilibili.paid_locked".to_string()),+ 3 => Some("badge.bilibili.partial_preview".to_string()),+ _ => None,+ };+ counter += 1;+ items.push(EpisodeItem {+ episode_id: format!("cheese:{}", ep_id.unwrap_or(0)),+ title: title_ep,+ aid,+ cid,+ ep_id,+ season_id,+ duration_seconds: dur,+ cover_url: cover_ep,+ pub_time_secs: release,+ episode_number: Some(counter),+ section_title: section_title.clone(),+ badge,+ url: ep_id.map(|id| {+ format!("https://www.bilibili.com/cheese/play/ep{}", id)+ }),+ ..EpisodeItem::default()+ });+ }+ }+ }+ }++ if items.is_empty() {+ return Err(BilibiliError::ContentUnavailable);+ }++ let metadata = ContentMetadata {+ series_title: Some(title.clone()),+ season_id,+ uploader,+ uploader_uid,+ uploader_avatar,+ description,+ cover: cover.clone(),+ poster: cover,+ styles: vec!["Bilibili Cheese".to_string()],+ premiered_secs: first_release,+ ..ContentMetadata::default()+ };++ Ok(ParsedContent {+ title,+ items,+ metadata,+ pagination: None,+ })+}diff --git a/src-tauri/src/platforms/bilibili/parser/favlist.rs b/src-tauri/src/platforms/bilibili/parser/favlist.rsnew file mode 100644index 00000000..16a89ddc--- /dev/null+++ b/src-tauri/src/platforms/bilibili/parser/favlist.rs@@ -0,0 +1,119 @@+use serde_json::Value;++use super::super::api::{check_api_response, ApiClient, BilibiliError, Result};+use super::{ContentMetadata, EpisodeItem, PaginationInfo, ParsedContent};++const RESOURCE_LIST_URL: &str = "https://api.bilibili.com/x/v3/fav/resource/list";+const PAGE_SIZE: u32 = 40;++pub async fn parse(client: &ApiClient, fid: u64, page: u32) -> Result<ParsedContent> {+ let url = format!(+ "{}?media_id={}&pn={}&ps={}&keyword=&order=mtime&type=0&tid=0&platform=web&web_location=333.1387",+ RESOURCE_LIST_URL,+ fid,+ page.max(1),+ PAGE_SIZE+ );+ let raw = client.get_json(&url).await?;+ let data = check_api_response(&raw)?;++ let info = data.get("info");+ let fav_title = info+ .and_then(|i| i.get("title"))+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let media_count = info+ .and_then(|i| i.get("media_count"))+ .and_then(Value::as_u64)+ .unwrap_or(0) as u32;+ let owner_name = info+ .and_then(|i| i.get("upper"))+ .and_then(|u| u.get("name"))+ .and_then(Value::as_str)+ .map(String::from);+ let owner_id = info+ .and_then(|i| i.get("upper"))+ .and_then(|u| u.get("mid"))+ .and_then(Value::as_u64);+ let total_pages = ((media_count + PAGE_SIZE - 1) / PAGE_SIZE).max(1);++ let medias = data+ .get("medias")+ .and_then(Value::as_array)+ .cloned()+ .unwrap_or_default();++ let mut items: Vec<EpisodeItem> = Vec::new();+ for m in &medias {+ let bvid = m+ .get("bvid")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ if bvid.is_empty() {+ continue;+ }+ let title = m+ .get("title")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let duration = m.get("duration").and_then(Value::as_f64);+ let cover = m+ .get("cover")+ .and_then(Value::as_str)+ .map(String::from);+ let pub_time = m.get("pubtime").and_then(Value::as_u64);+ let fav_time = m.get("fav_time").and_then(Value::as_u64);+ let is_ogv = m.get("ogv").is_some() && !m.get("ogv").unwrap_or(&Value::Null).is_null();+ let badge = if is_ogv {+ Some("badge.bilibili.pgc".to_string())+ } else {+ None+ };+ let ep_id = m+ .get("ogv")+ .and_then(|o| o.get("ep_id"))+ .and_then(Value::as_u64);+ items.push(EpisodeItem {+ episode_id: format!("fav:{}:{}", fid, bvid),+ title,+ bvid: Some(bvid.clone()),+ ep_id,+ duration_seconds: duration,+ cover_url: cover,+ pub_time_secs: fav_time.or(pub_time),+ badge,+ url: Some(if is_ogv {+ format!("https://www.bilibili.com/bangumi/play/ep{}", ep_id.unwrap_or(0))+ } else {+ format!("https://www.bilibili.com/video/{}", bvid)+ }),+ ..EpisodeItem::default()+ });+ }++ if items.is_empty() {+ return Err(BilibiliError::ContentUnavailable);+ }++ let metadata = ContentMetadata {+ favorites_name: Some(fav_title.clone()),+ favorites_owner: owner_name,+ uploader_uid: owner_id,+ ..ContentMetadata::default()+ };++ Ok(ParsedContent {+ title: fav_title,+ items,+ metadata,+ pagination: Some(PaginationInfo {+ total_items: media_count,+ total_pages,+ current_page: page.max(1),+ page_size: PAGE_SIZE,+ }),+ })+}diff --git a/src-tauri/src/platforms/bilibili/parser/festival.rs b/src-tauri/src/platforms/bilibili/parser/festival.rsnew file mode 100644index 00000000..ab9f23f1--- /dev/null+++ b/src-tauri/src/platforms/bilibili/parser/festival.rs@@ -0,0 +1,11 @@+use super::super::api::{ApiClient, BilibiliError, Result};+use super::super::url_kind::extract_festival_bvid;+use super::video;+use super::ParsedContent;++pub async fn parse(client: &ApiClient, url: &str) -> Result<ParsedContent> {+ let html = String::from_utf8(client.get_bytes(url).await?)+ .map_err(|_| BilibiliError::ContentUnavailable)?;+ let bvid = extract_festival_bvid(&html).ok_or(BilibiliError::ContentUnavailable)?;+ video::parse(client, &bvid, None).await+}diff --git a/src-tauri/src/platforms/bilibili/parser/history.rs b/src-tauri/src/platforms/bilibili/parser/history.rsnew file mode 100644index 00000000..e5446c96--- /dev/null+++ b/src-tauri/src/platforms/bilibili/parser/history.rs@@ -0,0 +1,120 @@+use serde_json::Value;++use super::super::api::{check_api_response, ApiClient, BilibiliError, Result};+use super::{ContentMetadata, EpisodeItem, PaginationInfo, ParsedContent};++const HISTORY_URL: &str = "https://api.bilibili.com/x/web-interface/history/search";+const PAGE_SIZE: u32 = 20;++pub async fn parse(client: &ApiClient, page: u32) -> Result<ParsedContent> {+ if client.account_slug().is_none() {+ return Err(BilibiliError::NotLoggedIn);+ }+ let url = format!(+ "{}?pn={}&ps={}&keyword=&business=archive&add_time_start=0&add_time_end=0&arc_max_duration=0&arc_min_duration=0&device_type=0&web_location=333.1391",+ HISTORY_URL,+ page.max(1),+ PAGE_SIZE+ );+ let raw = client.get_json(&url).await?;+ let data = check_api_response(&raw)?;++ let total = data+ .get("page")+ .and_then(|p| p.get("total"))+ .and_then(Value::as_u64)+ .unwrap_or(0) as u32;+ let total_pages = ((total + PAGE_SIZE - 1) / PAGE_SIZE).max(1);+ let list = data+ .get("list")+ .and_then(Value::as_array)+ .cloned()+ .unwrap_or_default();++ let mut items: Vec<EpisodeItem> = Vec::new();+ for v in &list {+ let history = v.get("history");+ let business = history+ .and_then(|h| h.get("business"))+ .and_then(Value::as_str)+ .unwrap_or("archive");+ let bvid = history+ .and_then(|h| h.get("bvid"))+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let cid = history+ .and_then(|h| h.get("cid"))+ .and_then(Value::as_u64);+ if bvid.is_empty() && business == "archive" {+ continue;+ }+ let title_main = v+ .get("title")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let long_title = v+ .get("long_title")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let composed_title = if business == "pgc" && !long_title.is_empty() {+ format!("{} - {}", title_main, long_title)+ } else {+ title_main+ };+ let cover = v.get("cover").and_then(Value::as_str).map(String::from);+ let duration = v.get("duration").and_then(Value::as_f64);+ let view_at = v.get("view_at").and_then(Value::as_u64);+ let expired = duration.map(|d| d <= 0.0).unwrap_or(true);+ let badge = if expired {+ Some("badge.bilibili.expired".to_string())+ } else {+ None+ };+ let ep_id = history+ .and_then(|h| h.get("epid").and_then(Value::as_u64))+ .or_else(|| {+ history+ .and_then(|h| h.get("ep_id"))+ .and_then(Value::as_u64)+ });+ items.push(EpisodeItem {+ episode_id: format!("history:{}:{}", business, bvid),+ title: composed_title,+ bvid: if bvid.is_empty() { None } else { Some(bvid.clone()) },+ cid,+ ep_id,+ duration_seconds: duration,+ cover_url: cover,+ pub_time_secs: view_at,+ badge,+ url: Some(if business == "pgc" {+ format!(+ "https://www.bilibili.com/bangumi/play/ep{}",+ ep_id.unwrap_or(0)+ )+ } else {+ format!("https://www.bilibili.com/video/{}", bvid)+ }),+ ..EpisodeItem::default()+ });+ }++ if items.is_empty() {+ return Err(BilibiliError::ContentUnavailable);+ }++ Ok(ParsedContent {+ title: String::from("History"),+ items,+ metadata: ContentMetadata::default(),+ pagination: Some(PaginationInfo {+ total_items: total,+ total_pages,+ current_page: page.max(1),+ page_size: PAGE_SIZE,+ }),+ })+}diff --git a/src-tauri/src/platforms/bilibili/parser/list.rs b/src-tauri/src/platforms/bilibili/parser/list.rsnew file mode 100644index 00000000..6e4ffb61--- /dev/null+++ b/src-tauri/src/platforms/bilibili/parser/list.rs@@ -0,0 +1,170 @@+use serde_json::Value;++use super::super::api::{check_api_response, ApiClient, BilibiliError, Result};+use super::{ContentMetadata, EpisodeItem, PaginationInfo, ParsedContent};++const COLLECTION_URL: &str =+ "https://api.bilibili.com/x/polymer/web-space/seasons_archives_list";+const SERIES_ARCHIVES_URL: &str = "https://api.bilibili.com/x/series/archives";+const SERIES_META_URL: &str = "https://api.bilibili.com/x/series/series";+const PAGE_SIZE: u32 = 30;++pub async fn parse_collection(+ client: &ApiClient,+ mid: u64,+ sid: u64,+ page: u32,+) -> Result<ParsedContent> {+ let url = format!(+ "{}?mid={}&season_id={}&sort_reverse=false&page_size={}&page_num={}",+ COLLECTION_URL,+ mid,+ sid,+ PAGE_SIZE,+ page.max(1)+ );+ let raw = client.get_json(&url).await?;+ let data = check_api_response(&raw)?;+ let meta_title = data+ .get("meta")+ .and_then(|m| m.get("name"))+ .and_then(Value::as_str)+ .map(String::from);+ let total = data+ .get("page")+ .and_then(|p| p.get("total"))+ .and_then(Value::as_u64)+ .unwrap_or(0) as u32;+ let total_pages = ((total + PAGE_SIZE - 1) / PAGE_SIZE).max(1);+ let archives = data+ .get("archives")+ .and_then(Value::as_array)+ .cloned()+ .unwrap_or_default();+ let items = archives_to_items(&archives, format!("collection:{}", sid));+ if items.is_empty() {+ return Err(BilibiliError::ContentUnavailable);+ }+ let title = meta_title+ .clone()+ .unwrap_or_else(|| format!("Bilibili Collection {}", sid));+ let metadata = ContentMetadata {+ collection_title: meta_title,+ uploader_uid: Some(mid),+ ..ContentMetadata::default()+ };+ Ok(ParsedContent {+ title,+ items,+ metadata,+ pagination: Some(PaginationInfo {+ total_items: total,+ total_pages,+ current_page: page.max(1),+ page_size: PAGE_SIZE,+ }),+ })+}++pub async fn parse_series(+ client: &ApiClient,+ mid: u64,+ sid: u64,+ page: u32,+) -> Result<ParsedContent> {+ let url = format!(+ "{}?mid={}&series_id={}&only_normal=true&sort=desc&pn={}&ps={}&web_location=333.999",+ SERIES_ARCHIVES_URL,+ mid,+ sid,+ page.max(1),+ PAGE_SIZE+ );+ let raw = client.get_json(&url).await?;+ let data = check_api_response(&raw)?;+ let total = data+ .get("page")+ .and_then(|p| p.get("total"))+ .and_then(Value::as_u64)+ .unwrap_or(0) as u32;+ let total_pages = ((total + PAGE_SIZE - 1) / PAGE_SIZE).max(1);+ let archives = data+ .get("archives")+ .and_then(Value::as_array)+ .cloned()+ .unwrap_or_default();+ let items = archives_to_items(&archives, format!("series:{}", sid));+ if items.is_empty() {+ return Err(BilibiliError::ContentUnavailable);+ }++ let meta_title: Option<String> = {+ let meta_url = format!("{}?series_id={}", SERIES_META_URL, sid);+ let meta_raw = client.get_json(&meta_url).await.ok();+ meta_raw+ .as_ref()+ .and_then(|r| check_api_response(r).ok())+ .and_then(|d| d.get("meta"))+ .and_then(|m| m.get("name"))+ .and_then(Value::as_str)+ .map(String::from)+ };++ let title = meta_title+ .clone()+ .unwrap_or_else(|| format!("Bilibili Series {}", sid));+ let metadata = ContentMetadata {+ collection_title: meta_title,+ uploader_uid: Some(mid),+ ..ContentMetadata::default()+ };+ Ok(ParsedContent {+ title,+ items,+ metadata,+ pagination: Some(PaginationInfo {+ total_items: total,+ total_pages,+ current_page: page.max(1),+ page_size: PAGE_SIZE,+ }),+ })+}++fn archives_to_items(archives: &[Value], prefix: String) -> Vec<EpisodeItem> {+ let mut items: Vec<EpisodeItem> = Vec::new();+ for a in archives {+ let bvid = a+ .get("bvid")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ if bvid.is_empty() {+ continue;+ }+ let aid = a.get("aid").and_then(Value::as_u64);+ let title = a+ .get("title")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let cover = a+ .get("pic")+ .and_then(Value::as_str)+ .map(String::from);+ let duration = a.get("duration").and_then(Value::as_f64);+ let pub_time = a.get("pubdate").and_then(Value::as_u64);+ items.push(EpisodeItem {+ episode_id: format!("{}:{}", prefix, bvid),+ title,+ aid,+ bvid: Some(bvid.clone()),+ duration_seconds: duration,+ cover_url: cover,+ pub_time_secs: pub_time,+ url: Some(format!("https://www.bilibili.com/video/{}", bvid)),+ ..EpisodeItem::default()+ });+ }+ items+}diff --git a/src-tauri/src/platforms/bilibili/parser/mod.rs b/src-tauri/src/platforms/bilibili/parser/mod.rsnew file mode 100644index 00000000..8a973178--- /dev/null+++ b/src-tauri/src/platforms/bilibili/parser/mod.rs@@ -0,0 +1,111 @@+use serde::{Deserialize, Serialize};++use super::api::{ApiClient, Result};+use super::url_kind::UrlKind;++pub mod bangumi;+pub mod cheese;+pub mod favlist;+pub mod festival;+pub mod history;+pub mod list;+pub mod popular;+pub mod space;+pub mod video;+pub mod watch_later;++#[derive(Debug, Clone, Serialize, Deserialize, Default)]+pub struct EpisodeItem {+ pub episode_id: String,+ pub title: String,+ pub aid: Option<u64>,+ pub bvid: Option<String>,+ pub cid: Option<u64>,+ pub ep_id: Option<u64>,+ pub season_id: Option<u64>,+ pub duration_seconds: Option<f64>,+ pub cover_url: Option<String>,+ pub pub_time_secs: Option<u64>,+ pub page: Option<u32>,+ pub page_title: Option<String>,+ pub badge: Option<String>,+ pub section_title: Option<String>,+ pub episode_number: Option<u32>,+ pub url: Option<String>,+}++#[derive(Debug, Clone, Serialize, Deserialize, Default)]+pub struct ContentMetadata {+ pub series_title: Option<String>,+ pub season_title: Option<String>,+ pub season_number: Option<u32>,+ pub season_id: Option<u64>,+ pub media_id: Option<u64>,+ pub uploader: Option<String>,+ pub uploader_uid: Option<u64>,+ pub uploader_avatar: Option<String>,+ pub description: Option<String>,+ pub cover: Option<String>,+ pub poster: Option<String>,+ pub areas: Vec<String>,+ pub styles: Vec<String>,+ pub actors: Option<String>,+ pub rating: Option<f32>,+ pub premiered_secs: Option<u64>,+ pub favorites_name: Option<String>,+ pub favorites_owner: Option<String>,+ pub collection_title: Option<String>,+ pub space_owner: Option<String>,+}++#[derive(Debug, Clone, Serialize, Deserialize, Default)]+pub struct PaginationInfo {+ pub total_items: u32,+ pub total_pages: u32,+ pub current_page: u32,+ pub page_size: u32,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+pub struct ParsedContent {+ pub title: String,+ pub items: Vec<EpisodeItem>,+ pub metadata: ContentMetadata,+ pub pagination: Option<PaginationInfo>,+}++impl ParsedContent {+ pub fn single(title: String, item: EpisodeItem) -> Self {+ Self {+ title,+ items: vec![item],+ metadata: ContentMetadata::default(),+ pagination: None,+ }+ }+}++pub async fn parse(client: &ApiClient, kind: &UrlKind) -> Result<ParsedContent> {+ match kind {+ UrlKind::Video { bvid_or_av, page } => video::parse(client, bvid_or_av, *page).await,+ UrlKind::BangumiEpisode { ep_id } => {+ bangumi::parse_by_ep(client, *ep_id).await+ }+ UrlKind::BangumiSeason { season_id } => {+ bangumi::parse_by_season(client, *season_id).await+ }+ UrlKind::BangumiMedia { media_id } => {+ bangumi::parse_by_media(client, *media_id).await+ }+ UrlKind::CheeseEpisode { ep_id } => cheese::parse_by_ep(client, *ep_id).await,+ UrlKind::CheeseSeason { season_id } => cheese::parse_by_season(client, *season_id).await,+ UrlKind::Space { mid } => space::parse(client, *mid, 1).await,+ UrlKind::Favlist { fid } => favlist::parse(client, *fid, 1).await,+ UrlKind::Collection { mid, sid } => list::parse_collection(client, *mid, *sid, 1).await,+ UrlKind::Series { mid, sid } => list::parse_series(client, *mid, *sid, 1).await,+ UrlKind::PopularWeek { num } => popular::parse(client, *num).await,+ UrlKind::WatchLater => watch_later::parse(client, 1).await,+ UrlKind::History => history::parse(client, 1).await,+ UrlKind::Festival { url } => festival::parse(client, url).await,+ }+}diff --git a/src-tauri/src/platforms/bilibili/parser/popular.rs b/src-tauri/src/platforms/bilibili/parser/popular.rsnew file mode 100644index 00000000..096b0bdd--- /dev/null+++ b/src-tauri/src/platforms/bilibili/parser/popular.rs@@ -0,0 +1,84 @@+use serde_json::Value;++use super::super::api::{check_api_response, ApiClient, BilibiliError, Result};+use super::super::wbi;+use super::{ContentMetadata, EpisodeItem, ParsedContent};++const POPULAR_URL: &str = "https://api.bilibili.com/x/web-interface/popular/series/one";++pub async fn parse(client: &ApiClient, num: u32) -> Result<ParsedContent> {+ let params: Vec<(&str, String)> = vec![+ ("number", num.to_string()),+ ("web_location", "333.934".to_string()),+ ];+ let signed = wbi::signed_query(client, ¶ms).await?;+ let url = format!("{}?{}", POPULAR_URL, signed);+ let raw = client.get_json(&url).await?;+ let data = check_api_response(&raw)?;++ let label = data+ .get("config")+ .and_then(|c| c.get("label"))+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let title = if label.is_empty() {+ format!("Bilibili Popular #{}", num)+ } else {+ label+ };++ let list = data+ .get("list")+ .and_then(Value::as_array)+ .cloned()+ .unwrap_or_default();++ let mut items: Vec<EpisodeItem> = Vec::new();+ for v in &list {+ let bvid = v+ .get("bvid")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ if bvid.is_empty() {+ continue;+ }+ let aid = v.get("aid").and_then(Value::as_u64);+ let cid = v.get("cid").and_then(Value::as_u64);+ let title_v = v+ .get("title")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let cover = v+ .get("pic")+ .and_then(Value::as_str)+ .map(String::from);+ let duration = v.get("duration").and_then(Value::as_f64);+ let pub_time = v.get("pubdate").and_then(Value::as_u64);+ items.push(EpisodeItem {+ episode_id: format!("popular:{}:{}", num, bvid),+ title: title_v,+ aid,+ bvid: Some(bvid.clone()),+ cid,+ duration_seconds: duration,+ cover_url: cover,+ pub_time_secs: pub_time,+ url: Some(format!("https://www.bilibili.com/video/{}", bvid)),+ ..EpisodeItem::default()+ });+ }++ if items.is_empty() {+ return Err(BilibiliError::ContentUnavailable);+ }++ Ok(ParsedContent {+ title,+ items,+ metadata: ContentMetadata::default(),+ pagination: None,+ })+}diff --git a/src-tauri/src/platforms/bilibili/parser/space.rs b/src-tauri/src/platforms/bilibili/parser/space.rsnew file mode 100644index 00000000..4ed98dac--- /dev/null+++ b/src-tauri/src/platforms/bilibili/parser/space.rs@@ -0,0 +1,145 @@+use serde_json::Value;++use super::super::api::{check_api_response, ApiClient, BilibiliError, Result};+use super::super::wbi;+use super::{ContentMetadata, EpisodeItem, PaginationInfo, ParsedContent};++const SEARCH_URL: &str = "https://api.bilibili.com/x/space/wbi/arc/search";+const CARD_URL: &str = "https://api.bilibili.com/x/web-interface/card";+const PAGE_SIZE: u32 = 40;++pub async fn parse(client: &ApiClient, mid: u64, page: u32) -> Result<ParsedContent> {+ let card_url = format!("{}?mid={}", CARD_URL, mid);+ let card_raw = client.get_json(&card_url).await.ok();+ let space_owner = card_raw+ .as_ref()+ .and_then(|r| check_api_response(r).ok())+ .and_then(|d| d.get("card"))+ .and_then(|c| c.get("name"))+ .and_then(Value::as_str)+ .map(String::from);++ let pn = page.max(1).to_string();+ let ps = PAGE_SIZE.to_string();+ let mid_str = mid.to_string();+ let params: Vec<(&str, String)> = vec![+ ("mid", mid_str),+ ("pn", pn),+ ("ps", ps),+ ("tid", "0".to_string()),+ ("order", "pubdate".to_string()),+ ("platform", "web".to_string()),+ ("web_location", "333.1387".to_string()),+ ];+ let signed = wbi::signed_query(client, ¶ms).await?;+ let url = format!("{}?{}", SEARCH_URL, signed);+ let raw = client.get_json(&url).await?;+ let data = check_api_response(&raw)?;++ let count = data+ .get("page")+ .and_then(|p| p.get("count"))+ .and_then(Value::as_u64)+ .unwrap_or(0) as u32;+ let total_pages = ((count + PAGE_SIZE - 1) / PAGE_SIZE).max(1);++ let vlist = data+ .get("list")+ .and_then(|l| l.get("vlist"))+ .and_then(Value::as_array)+ .cloned()+ .unwrap_or_default();++ let mut items: Vec<EpisodeItem> = Vec::new();+ for v in &vlist {+ let bvid = v+ .get("bvid")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ if bvid.is_empty() {+ continue;+ }+ let aid = v.get("aid").and_then(Value::as_u64);+ let title = v+ .get("title")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let cover = v+ .get("pic")+ .and_then(Value::as_str)+ .map(String::from);+ let duration = v+ .get("length")+ .and_then(Value::as_str)+ .and_then(parse_mmss_to_seconds);+ let created = v.get("created").and_then(Value::as_u64);+ let mut badge: Option<String> = None;+ if v.get("is_charging_arc")+ .and_then(Value::as_bool)+ .unwrap_or(false)+ {+ badge = Some("badge.bilibili.charging_exclusive".to_string());+ } else if v.get("is_union_video").and_then(Value::as_u64).unwrap_or(0) > 0 {+ badge = Some("badge.bilibili.collab".to_string());+ }+ items.push(EpisodeItem {+ episode_id: format!("space:{}:{}", mid, bvid),+ title,+ aid,+ bvid: Some(bvid.clone()),+ duration_seconds: duration,+ cover_url: cover,+ pub_time_secs: created,+ badge,+ url: Some(format!("https://www.bilibili.com/video/{}", bvid)),+ ..EpisodeItem::default()+ });+ }++ if items.is_empty() {+ return Err(BilibiliError::ContentUnavailable);+ }++ let title = space_owner+ .clone()+ .map(|n| format!("{} · Bilibili", n))+ .unwrap_or_else(|| format!("Bilibili Space {}", mid));++ let metadata = ContentMetadata {+ space_owner,+ uploader_uid: Some(mid),+ ..ContentMetadata::default()+ };++ Ok(ParsedContent {+ title,+ items,+ metadata,+ pagination: Some(PaginationInfo {+ total_items: count,+ total_pages,+ current_page: page.max(1),+ page_size: PAGE_SIZE,+ }),+ })+}++fn parse_mmss_to_seconds(s: &str) -> Option<f64> {+ let parts: Vec<&str> = s.split(':').collect();+ match parts.len() {+ 2 => {+ let m: u64 = parts[0].parse().ok()?;+ let sec: u64 = parts[1].parse().ok()?;+ Some((m * 60 + sec) as f64)+ }+ 3 => {+ let h: u64 = parts[0].parse().ok()?;+ let m: u64 = parts[1].parse().ok()?;+ let sec: u64 = parts[2].parse().ok()?;+ Some((h * 3600 + m * 60 + sec) as f64)+ }+ _ => None,+ }+}diff --git a/src-tauri/src/platforms/bilibili/parser/video.rs b/src-tauri/src/platforms/bilibili/parser/video.rsnew file mode 100644index 00000000..0b69b60a--- /dev/null+++ b/src-tauri/src/platforms/bilibili/parser/video.rs@@ -0,0 +1,238 @@+use serde_json::Value;++use super::super::api::{check_api_response, ApiClient, BilibiliError, Result};+use super::super::url_kind::av_to_bv;+use super::super::wbi;+use super::{ContentMetadata, EpisodeItem, ParsedContent};++const VIEW_URL: &str = "https://api.bilibili.com/x/web-interface/wbi/view";++pub async fn parse(+ client: &ApiClient,+ bvid_or_av: &str,+ page_filter: Option<u32>,+) -> Result<ParsedContent> {+ let bvid = normalize_bvid(bvid_or_av).ok_or(BilibiliError::ContentUnavailable)?;+ let params: Vec<(&str, String)> = vec![("bvid", bvid.clone())];+ let signed = wbi::signed_query(client, ¶ms).await?;+ let url = format!("{}?{}", VIEW_URL, signed);+ let raw = client.get_json(&url).await?;+ let data = check_api_response(&raw)?;++ let title = data+ .get("title")+ .and_then(Value::as_str)+ .unwrap_or("Bilibili Video")+ .to_string();+ let cover = data+ .get("pic")+ .and_then(Value::as_str)+ .map(String::from);+ let uploader = data+ .get("owner")+ .and_then(|o| o.get("name"))+ .and_then(Value::as_str)+ .map(String::from);+ let uploader_uid = data+ .get("owner")+ .and_then(|o| o.get("mid"))+ .and_then(Value::as_u64);+ let uploader_avatar = data+ .get("owner")+ .and_then(|o| o.get("face"))+ .and_then(Value::as_str)+ .map(String::from);+ let description = data+ .get("desc")+ .and_then(Value::as_str)+ .map(String::from);+ let pub_time = data.get("pubdate").and_then(Value::as_u64);+ let bvid_val = data+ .get("bvid")+ .and_then(Value::as_str)+ .unwrap_or(&bvid)+ .to_string();+ let aid = data.get("aid").and_then(Value::as_u64);+ let badge = if data+ .get("is_upower_exclusive")+ .and_then(Value::as_bool)+ .unwrap_or(false)+ {+ Some("badge.bilibili.charging_exclusive".to_string())+ } else {+ None+ };++ let mut metadata = ContentMetadata {+ uploader,+ uploader_uid,+ uploader_avatar,+ description,+ cover: cover.clone(),+ premiered_secs: pub_time,+ ..ContentMetadata::default()+ };++ if let Some(season) = data.get("ugc_season").and_then(Value::as_object) {+ let series_title = season+ .get("title")+ .and_then(Value::as_str)+ .map(String::from);+ metadata.collection_title = series_title.clone();+ metadata.series_title = series_title;+ let sections = season.get("sections").and_then(Value::as_array);+ let mut items: Vec<EpisodeItem> = Vec::new();+ if let Some(secs) = sections {+ for sec in secs {+ let section_title = sec+ .get("title")+ .and_then(Value::as_str)+ .map(String::from);+ if let Some(eps) = sec.get("episodes").and_then(Value::as_array) {+ for (i, ep) in eps.iter().enumerate() {+ let ep_bvid = ep+ .get("bvid")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ 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);+ items.push(EpisodeItem {+ episode_id: format!("ugc:{}", ep_bvid),+ title: ep_title,+ aid: ep_aid,+ bvid: Some(ep_bvid.clone()),+ cid: ep_cid,+ duration_seconds: dur,+ cover_url: cover_ep,+ pub_time_secs: pub_ep,+ episode_number: Some((i as u32) + 1),+ section_title: section_title.clone(),+ url: Some(format!("https://www.bilibili.com/video/{}", ep_bvid)),+ ..EpisodeItem::default()+ });+ }+ }+ }+ }+ if !items.is_empty() {+ return Ok(ParsedContent {+ title,+ items,+ metadata,+ pagination: None,+ });+ }+ }++ let pages = data.get("pages").and_then(Value::as_array);+ if let Some(pgs) = pages {+ if pgs.len() > 1 || page_filter.is_some() {+ let mut items: Vec<EpisodeItem> = Vec::new();+ for p in pgs {+ let page_num = p.get("page").and_then(Value::as_u64).unwrap_or(0) as u32;+ if let Some(filter) = page_filter {+ if filter != page_num {+ continue;+ }+ }+ let cid = p.get("cid").and_then(Value::as_u64);+ let part = p+ .get("part")+ .and_then(Value::as_str)+ .unwrap_or("")+ .to_string();+ let dur = p.get("duration").and_then(Value::as_f64);+ items.push(EpisodeItem {+ episode_id: format!("page:{}:{}", bvid_val, page_num),+ title: if part.is_empty() {+ title.clone()+ } else {+ part.clone()+ },+ aid,+ bvid: Some(bvid_val.clone()),+ cid,+ duration_seconds: dur,+ cover_url: cover.clone(),+ pub_time_secs: pub_time,+ page: Some(page_num),+ page_title: Some(part),+ badge: badge.clone(),+ url: Some(format!(+ "https://www.bilibili.com/video/{}?p={}",+ bvid_val, page_num+ )),+ ..EpisodeItem::default()+ });+ }+ if !items.is_empty() {+ return Ok(ParsedContent {+ title: title.clone(),+ items,+ metadata,+ pagination: None,+ });+ }+ }+ }++ let cid = data+ .get("cid")+ .and_then(Value::as_u64)+ .or_else(|| pages.and_then(|p| p.first()).and_then(|p| p.get("cid")).and_then(Value::as_u64));+ let duration = data.get("duration").and_then(Value::as_f64);+ let item = EpisodeItem {+ episode_id: format!("video:{}", bvid_val),+ title: title.clone(),+ aid,+ bvid: Some(bvid_val.clone()),+ cid,+ duration_seconds: duration,+ cover_url: cover,+ pub_time_secs: pub_time,+ badge,+ url: Some(format!("https://www.bilibili.com/video/{}", bvid_val)),+ ..EpisodeItem::default()+ };+ Ok(ParsedContent::single_with_meta(title, item, metadata))+}++fn normalize_bvid(input: &str) -> Option<String> {+ if input.starts_with("BV") {+ return Some(input.to_string());+ }+ if let Some(rest) = input.strip_prefix("av") {+ if let Ok(n) = rest.parse::<u64>() {+ return Some(av_to_bv(n));+ }+ }+ None+}++impl ParsedContent {+ pub fn single_with_meta(title: String, item: EpisodeItem, metadata: ContentMetadata) -> Self {+ Self {+ title,+ items: vec![item],+ metadata,+ pagination: None,+ }+ }+}diff --git a/src-tauri/src/platforms/vimeo/mod.rs b/src-tauri/src/platforms/vimeo/mod.rsindex fc660216..dbe304a2 100644--- a/src-tauri/src/platforms/vimeo/mod.rs+++ b/src-tauri/src/platforms/vimeo/mod.rs@@ -1,3 +1,4 @@+use omniget_core::models::progress::ProgressUpdate;use std::collections::HashSet;use anyhow::anyhow;@@ -140,9 +141,9 @@ impl PlatformDownloader for VimeoDownloader {&self,info: &MediaInfo,opts: &DownloadOptions,- progress: mpsc::Sender<f64>,+ progress: mpsc::Sender<ProgressUpdate>,) -> anyhow::Result<DownloadResult> {- let _ = progress.send(0.0).await;+ let _ = progress.send(ProgressUpdate::percent(0.0)).await;let ytdlp_path = ytdlp::ensure_ytdlp().await?;