From 2e9eba9c834aa7c3b33d0b2595dd531940430337 Mon Sep 17 00:00:00 2001 From: Soispha Peetz Date: Sat, 28 Nov 2026 17:01:36 +0100 Subject: refactor(yt/config): Deduplicate `yt_dlp` config to it's own section Otherwise we have one for updating, and one for downloding. And the updating one was not even using the respective settings from the `update` config section, but the ones from the `download` section. --- crates/yt/src/config/def.rs | 33 +++++++++++++++----------------- crates/yt/src/yt_dlp/download_options.rs | 27 +++++--------------------- crates/yt/src/yt_dlp/mod.rs | 26 +++++++++++++------------ 3 files changed, 34 insertions(+), 52 deletions(-) (limited to 'crates') diff --git a/crates/yt/src/config/def.rs b/crates/yt/src/config/def.rs index 70456ea..1d8b421 100644 --- a/crates/yt/src/config/def.rs +++ b/crates/yt/src/config/def.rs @@ -88,22 +88,6 @@ mk_config::mk_config! { download: { /// The maximum cache size. max_cache_size: Bytes = try "3 GiB".parse(), - - /// The cookie file to pass to `yt_dlp`. - /// - /// If set takes priority over `cookies_from_browser` - cookies: Option = None, - - /// Pass `cookies_from_browser` to `yt_dlp` - /// - /// If `cookies` is set, that setting takes priority. - cookies_from_browser: Option = None, - - /// Additional options to pass to `yt-dlp`, when updating (or select adding). - /// - /// These are added _after_ the ones `yt` adds, so you can override hardcoded - /// options. - yt_dlp_options: HashMap = HashMap::new(), }, update: { /// How many videos to download, when checking for new ones. @@ -116,12 +100,25 @@ mk_config::mk_config! { /// /// For example, 16 means, that we will fetch 16 subscriptions at the same time. futures: usize = 16 * 4, - - /// Additional options to pass to `yt-dlp`, when updating (or select adding). + }, + /// Set specific configuration for `yt`'s `yt_dlp` usage + yt_dlp: { + /// Additional options to pass to `yt-dlp`, when downloading, updating or select adding. /// /// These are added _after_ the ones `yt` adds, so you can override hardcoded /// options. yt_dlp_options: HashMap = HashMap::new(), + + /// The cookie file to pass to `yt_dlp`. + /// + /// If set takes priority over `cookies_from_browser` + cookies: Option = None, + + /// Pass `cookies_from_browser` to `yt_dlp` + /// `yt_dlp` will then automatically load the cookies from this browser. + /// + /// If `cookies` is set, that setting takes priority. + cookies_from_browser: Option = None, }, } } diff --git a/crates/yt/src/yt_dlp/download_options.rs b/crates/yt/src/yt_dlp/download_options.rs index b045ac1..8db5d1b 100644 --- a/crates/yt/src/yt_dlp/download_options.rs +++ b/crates/yt/src/yt_dlp/download_options.rs @@ -14,7 +14,10 @@ use log::info; use serde_json::{Value, json}; use yt_dlp::{YoutubeDL, options::YoutubeDLOptions}; -use crate::{app::App, yt_dlp::match_filters::ignore_member_only_wrapped}; +use crate::{ + app::App, + yt_dlp::{add_default_options, match_filters::ignore_member_only_wrapped}, +}; use super::hooks::{wrapped_post_processor_hook, wrapped_progress_hook}; @@ -117,27 +120,7 @@ pub(crate) fn download_opts(app: &App, subtitle_langs: Option<&str>) -> anyhow:: // TODO: Add this, when it works. <2026-11-07> // .add_match_filter(ignore_member_only_wrapped); - let base = if let Some(cookies) = &app.config.download.cookies { - base.set("cookiefile", cookies.to_str()) - } else if let Some(cookies_from_browser) = &app.config.download.cookies_from_browser { - base.set( - "cookiesfrombrowser", - Value::Array(vec![cookies_from_browser.to_owned().into()]), - ) - } else { - base - }; - - let base = { - let mut final_base = base; - - for (key, value) in &app.config.update.yt_dlp_options { - info!("Adding additional yt-dlp freeform option: {key} to {value}"); - final_base = final_base.set(key, value.to_owned()); - } - - final_base - }; + let base = add_default_options(app, base); base.build() .context("Failed to instanciate download yt_dlp") diff --git a/crates/yt/src/yt_dlp/mod.rs b/crates/yt/src/yt_dlp/mod.rs index aaf68e2..3a2284a 100644 --- a/crates/yt/src/yt_dlp/mod.rs +++ b/crates/yt/src/yt_dlp/mod.rs @@ -57,9 +57,15 @@ pub(crate) fn yt_dlp_opts_updating( base }; - let base = if let Some(cookies) = &app.config.download.cookies { + let base = add_default_options(app, base); + + Ok(base.build()?) +} + +fn add_default_options(app: &App, base: YoutubeDLOptions) -> YoutubeDLOptions { + let base = if let Some(cookies) = &app.config.yt_dlp.cookies { base.set("cookiefile", cookies.to_str()) - } else if let Some(cookies_from_browser) = &app.config.download.cookies_from_browser { + } else if let Some(cookies_from_browser) = &app.config.yt_dlp.cookies_from_browser { base.set( "cookiesfrombrowser", Value::Array(vec![cookies_from_browser.to_owned().into()]), @@ -68,18 +74,14 @@ pub(crate) fn yt_dlp_opts_updating( base }; - let base = { - let mut final_base = base; + let mut final_base = base; - for (key, value) in &app.config.update.yt_dlp_options { - info!("Adding additional yt-dlp freeform option: {key} to {value}"); - final_base = final_base.set(key, value.to_owned()); - } - - final_base - }; + for (key, value) in &app.config.yt_dlp.yt_dlp_options { + info!("Adding additional yt-dlp freeform option: {key} to {value}"); + final_base = final_base.set(key, value.to_owned()); + } - Ok(base.build()?) + final_base } impl Video { -- cgit v1.3.1