about summary refs log tree commit diff stats
path: root/crates/yt/src/commands/select/implm
diff options
context:
space:
mode:
Diffstat (limited to 'crates/yt/src/commands/select/implm')
-rw-r--r--crates/yt/src/commands/select/implm/standalone/add.rs17
1 files changed, 6 insertions, 11 deletions
diff --git a/crates/yt/src/commands/select/implm/standalone/add.rs b/crates/yt/src/commands/select/implm/standalone/add.rs
index ec32039..dd11cb4 100644
--- a/crates/yt/src/commands/select/implm/standalone/add.rs
+++ b/crates/yt/src/commands/select/implm/standalone/add.rs
@@ -17,7 +17,7 @@ use crate::{
 use anyhow::{Context, Result, bail};
 use log::{error, warn};
 use url::Url;
-use yt_dlp::{YoutubeDL, info_json::InfoJson, json_cast, json_get};
+use yt_dlp::{YoutubeDL, info_json::InfoJson, json_cast, json_get, json_try_get};
 
 #[allow(clippy::too_many_lines)]
 pub(crate) async fn add(
@@ -55,14 +55,10 @@ pub(crate) async fn add(
                         .await
                         .with_context(|| format!(
                             "Failed to format hash of video '{}' as short hash",
-                            entry
-                                .get("url")
-                                .map_or("<Unknown video Url>".to_owned(), ToString::to_string)
+                            json_try_get!(entry, "url", as_str).unwrap_or("<Unknown video Url>")
                         ))?,
-                    entry.get("title").map_or(String::new(), |title| format!(
-                        " (\"{}\")",
-                        json_cast!(title, as_str)
-                    ))
+                    json_try_get!(entry, "title", as_str)
+                        .map_or(String::new(), |title| format!(" (\"{title}\")"))
                 );
                 return Ok(());
             }
@@ -82,7 +78,7 @@ pub(crate) async fn add(
             .extract_info(&url, false, true)
             .with_context(|| format!("Failed to fetch entry for url: '{url}'"))?;
 
-        match entry.get("_type").map(|val| json_cast!(val, as_str)) {
+        match json_try_get!(entry, "_type", as_str) {
             Some("video") => {
                 add_entry(app, entry).await?;
                 if start.is_some() || stop.is_some() {
@@ -92,8 +88,7 @@ pub(crate) async fn add(
                 }
             }
             Some("playlist") => {
-                if let Some(entries) = entry.get("entries") {
-                    let entries = json_cast!(entries, as_array);
+                if let Some(entries) = json_try_get!(entry, "entries", as_array) {
                     let start = start.unwrap_or(0);
                     let stop = stop.unwrap_or(entries.len() - 1);