From 7855ca1efa7d6c107c859ea05498f4d79eb8fe46 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 30 Nov 2025 15:12:57 +0100 Subject: fix(yt/commands/select/add): Correct add behaviour --- .../yt/src/commands/select/implm/standalone/add.rs | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'crates') diff --git a/crates/yt/src/commands/select/implm/standalone/add.rs b/crates/yt/src/commands/select/implm/standalone/add.rs index dd11cb4..2a7db53 100644 --- a/crates/yt/src/commands/select/implm/standalone/add.rs +++ b/crates/yt/src/commands/select/implm/standalone/add.rs @@ -15,7 +15,7 @@ use crate::{ }; use anyhow::{Context, Result, bail}; -use log::{error, warn}; +use log::{debug, error, warn}; use url::Url; use yt_dlp::{YoutubeDL, info_json::InfoJson, json_cast, json_get, json_try_get}; @@ -28,11 +28,17 @@ pub(crate) async fn add( ) -> Result<()> { for url in urls { async fn process_and_add(app: &App, entry: InfoJson, yt_dlp: &YoutubeDL) -> Result<()> { - let url = json_get!(entry, "url", as_str).parse()?; - - let entry = yt_dlp - .extract_info(&url, false, true) - .with_context(|| format!("Failed to fetch entry for url: '{url}'"))?; + let entry = if json_try_get!(entry, "formats", as_array).is_some() { + // We assume, that this entry is already processed. + debug!("Refusing to re-process entry again"); + entry + } else { + let url = json_get!(entry, "url", as_str).parse()?; + + yt_dlp + .extract_info(&url, false, true) + .with_context(|| format!("Failed to fetch entry for url: '{url}'"))? + }; add_entry(app, entry).await?; @@ -72,7 +78,9 @@ pub(crate) async fn add( Ok(()) } - let yt_dlp = yt_dlp_opts_updating(start.unwrap_or(0) + stop.unwrap_or(0))?; + let yt_dlp = yt_dlp_opts_updating( + start.unwrap_or(0) + stop.map_or(usize::MAX, |val| val.saturating_add(1)), + )?; let entry = yt_dlp .extract_info(&url, false, true) @@ -92,6 +100,10 @@ pub(crate) async fn add( let start = start.unwrap_or(0); let stop = stop.unwrap_or(entries.len() - 1); + if entries.is_empty() { + bail!("Failed to add playlist, as it is empty (contains no entries).") + } + let respected_entries = take_vector(entries, start, stop).with_context(|| { format!( @@ -131,8 +143,7 @@ pub(crate) async fn add( } } other => bail!( - "Your URL should point to a video or a playlist, but points to a '{:#?}'", - other + "Your URL should point to a video or a playlist, but points to a '{other:#?}'" ), } } -- cgit 1.4.1