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.

feat(api): enhance get_item_detail to support pagination and add audio_url and title fields to EstrategiaLdiTrack

Tonho1d96459fb618
diff --git a/src-tauri/src/platforms/estrategia_ldi/api.rs b/src-tauri/src/platforms/estrategia_ldi/api.rs
index 9736a408..2bc6627a 100644
--- a/src-tauri/src/platforms/estrategia_ldi/api.rs
+++ b/src-tauri/src/platforms/estrategia_ldi/api.rs
@@ -44,6 +44,8 @@ pub struct EstrategiaLdiLesson {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EstrategiaLdiTrack {
pub url: String,
+ pub audio_url: Option<String>,
+ pub title: Option<String>,
pub duration: Option<f64>,
}
@@ -258,25 +260,65 @@ pub async fn get_item_detail(
session: &EstrategiaLdiSession,
item_id: &str,
) -> anyhow::Result<serde_json::Value> {
- let url = format!(
- "{}/v3/mci/items/{}?page=1&per_page=50",
- API_BASE, item_id
- );
+ let mut all_sub_blocks = Vec::new();
+ let mut page = 1u32;
- let resp = session.client.get(&url).send().await?;
- let status = resp.status();
- let body_text = resp.text().await?;
+ loop {
+ let url = format!("{}/v3/mci/items/{}", API_BASE, item_id);
+
+ let resp = session.client.get(&url)
+ .query(&[
+ ("page", page.to_string().as_str()),
+ ("order", "asc"),
+ ("per_page", "30"),
+ ("view_mode", "complete"),
+ ("should_load_metadata", "true"),
+ ("video_only", "false"),
+ ("text_only", "false"),
+ ("question_only", "false"),
+ ("cast_only", "false"),
+ ("attachment_only", "false"),
+ ])
+ .send()
+ .await?;
- if !status.is_success() {
- return Err(anyhow!(
- "get_item_detail returned status {}: {}",
- status,
- &body_text[..body_text.len().min(300)]
- ));
+ let status = resp.status();
+ let body_text = resp.text().await?;
+
+ if !status.is_success() {
+ if all_sub_blocks.is_empty() {
+ return Err(anyhow!(
+ "get_item_detail returned status {}: {}",
+ status,
+ &body_text[..body_text.len().min(300)]
+ ));
+ }
+ break;
+ }
+
+ let body: serde_json::Value = serde_json::from_str(&body_text)?;
+ let item_data = body.get("data").unwrap_or(&body);
+
+ if let Some(blocks) = item_data.get("sub_blocks").and_then(|v| v.as_array()) {
+ all_sub_blocks.extend(blocks.clone());
+ }
+
+ let total_pages = body
+ .get("meta")
+ .and_then(|m| m.get("last_page"))
+ .and_then(|v| v.as_u64())
+ .unwrap_or(1) as u32;
+
+ if page >= total_pages {
+ break;
+ }
+ page += 1;
}
- let body: serde_json::Value = serde_json::from_str(&body_text)?;
- Ok(body)
+ let result = serde_json::json!({
+ "sub_blocks": all_sub_blocks
+ });
+ Ok(result)
}
pub async fn get_track_info(