about summary refs log tree commit diff stats
path: root/crates
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-15 07:10:08 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-15 07:10:08 +0200
commit45a45074e1afe0254d7e732d03f5ba29e6b53030 (patch)
tree8b43cffe81ed724d14557a5e5610b3bd85260d7d /crates
parentfeat(crates/yt): Support a `--format` argument for most commands with output (diff)
downloadyt-45a45074e1afe0254d7e732d03f5ba29e6b53030.zip
feat(crates/yt/subscribe): Support a `--no-check` argument
Diffstat (limited to 'crates')
-rw-r--r--crates/yt/src/cli.rs8
-rw-r--r--crates/yt/src/main.rs19
-rw-r--r--crates/yt/src/subscribe/mod.rs15
3 files changed, 33 insertions, 9 deletions
diff --git a/crates/yt/src/cli.rs b/crates/yt/src/cli.rs
index a19e035..20bce0d 100644
--- a/crates/yt/src/cli.rs
+++ b/crates/yt/src/cli.rs
@@ -218,6 +218,10 @@ pub(crate) enum SubscriptionCommand {
 
         /// The URL to listen to
         url: Url,
+
+        /// Don't check, whether the URL actually points to something yt understands.
+        #[arg(long, default_value_t = false)]
+        no_check: bool,
     },
 
     /// Unsubscribe from an URL
@@ -235,6 +239,10 @@ pub(crate) enum SubscriptionCommand {
         /// Remove any previous subscriptions
         #[arg(short, long)]
         force: bool,
+
+        /// Don't check, whether the URLs actually point to something yt understands.
+        #[arg(long, default_value_t = false)]
+        no_check: bool,
     },
     /// Write all subscriptions in an format understood by `import`
     Export {},
diff --git a/crates/yt/src/main.rs b/crates/yt/src/main.rs
index 4b9c4c2..0926ac7 100644
--- a/crates/yt/src/main.rs
+++ b/crates/yt/src/main.rs
@@ -186,8 +186,13 @@ async fn main() -> Result<()> {
             update::update(&app, max_backlog, subscriptions).await?;
         }
         Command::Subscriptions { cmd } => match cmd {
-            SubscriptionCommand::Add { name, url } => {
-                subscribe::subscribe(&app, name, url)
+            SubscriptionCommand::Add {
+                name,
+                url,
+                no_check,
+            } => {
+                let mut ops = Operations::new("main: subscribe");
+                subscribe::subscribe(&app, name, url, no_check, &mut ops)
                     .await
                     .context("Failed to add a subscription")?;
                 ops.commit(&app).await?;
@@ -210,13 +215,17 @@ async fn main() -> Result<()> {
                     println!("{}", val.url);
                 }
             }
-            SubscriptionCommand::Import { file, force } => {
+            SubscriptionCommand::Import {
+                file,
+                force,
+                no_check,
+            } => {
                 if let Some(file) = file {
                     let f = File::open(file).await?;
 
-                    subscribe::import(&app, BufReader::new(f), force).await?;
+                    subscribe::import(&app, BufReader::new(f), force, no_check).await?;
                 } else {
-                    subscribe::import(&app, BufReader::new(stdin()), force).await?;
+                    subscribe::import(&app, BufReader::new(stdin()), force, no_check).await?;
                 }
             }
         },
diff --git a/crates/yt/src/subscribe/mod.rs b/crates/yt/src/subscribe/mod.rs
index 93c1390..bcf778b 100644
--- a/crates/yt/src/subscribe/mod.rs
+++ b/crates/yt/src/subscribe/mod.rs
@@ -44,6 +44,7 @@ pub(crate) async fn import<W: AsyncBufRead + AsyncBufReadExt + Unpin>(
     app: &App,
     reader: W,
     force: bool,
+    no_check: bool,
 ) -> Result<()> {
     let mut ops = Operations::new("SubscribeImport: init");
 
@@ -58,7 +59,8 @@ pub(crate) async fn import<W: AsyncBufRead + AsyncBufReadExt + Unpin>(
     while let Some(line) = lines.next_line().await? {
         let url =
             Url::from_str(&line).with_context(|| format!("Failed to parse '{line}' as url"))?;
-        match subscribe(app, None, url)
+
+        match subscribe(app, None, url, no_check, &mut ops)
             .await
             .with_context(|| format!("Failed to subscribe to: '{line}'"))
         {
@@ -66,7 +68,7 @@ pub(crate) async fn import<W: AsyncBufRead + AsyncBufReadExt + Unpin>(
             Err(err) => eprintln!(
                 "Error while subscribing to '{}': '{}'",
                 line,
-                err.source().unreachable("Should have a source")
+                err.source().expect("Should have a source")
             ),
         }
     }
@@ -79,6 +81,7 @@ pub(crate) async fn subscribe(
     app: &App,
     name: Option<String>,
     url: Url,
+    no_check: bool,
     ops: &mut Operations<Operation>,
 ) -> Result<()> {
     if !(url.as_str().ends_with("videos")
@@ -111,6 +114,7 @@ pub(crate) async fn subscribe(
             app,
             videos,
             url.join("videos/").expect("See above."),
+            no_check,
             ops,
         )
         .await
@@ -122,6 +126,7 @@ pub(crate) async fn subscribe(
             app,
             streams,
             url.join("streams/").expect("See above."),
+            no_check,
             ops,
         )
         .await
@@ -136,6 +141,7 @@ pub(crate) async fn subscribe(
             app,
             shorts,
             url.join("shorts/").expect("See above."),
+            no_check,
             ops,
         )
         .await
@@ -143,7 +149,7 @@ pub(crate) async fn subscribe(
             error!("Failed to subscribe to the '{}' variant: {err}", "{Shorts}");
         });
     } else {
-        actual_subscribe(app, name, url, ops).await?;
+        actual_subscribe(app, name, url, no_check, ops).await?;
     }
 
     Ok(())
@@ -153,9 +159,10 @@ async fn actual_subscribe(
     app: &App,
     name: Option<String>,
     url: Url,
+    no_check: bool,
     ops: &mut Operations<Operation>,
 ) -> Result<()> {
-    if !check_url(url.clone()).await? {
+    if !no_check && !check_url(url.clone()).await? {
         bail!("The url ('{}') does not represent a playlist!", &url)
     }