about summary refs log tree commit diff stats
path: root/src/watch/mod.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-24 16:38:31 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-24 16:38:31 +0200
commit75f2a6a9cf0bab4be6530a0f91fa05bf9d9d1b24 (patch)
tree3527b4319aefddd9d297874521f17a3e6c965f8d /src/watch/mod.rs
parentfeat(watch): Idle until new videos are available instead of exiting (diff)
downloadyt-75f2a6a9cf0bab4be6530a0f91fa05bf9d9d1b24.tar.gz
yt-75f2a6a9cf0bab4be6530a0f91fa05bf9d9d1b24.zip
refactor(watch): Don't track the playlist, use the properties of `mpv` instead
Diffstat (limited to 'src/watch/mod.rs')
-rw-r--r--src/watch/mod.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/watch/mod.rs b/src/watch/mod.rs
index 9eb1c18..376b245 100644
--- a/src/watch/mod.rs
+++ b/src/watch/mod.rs
@@ -8,6 +8,8 @@
 // You should have received a copy of the License along with this program.
 // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
 
+use std::collections::HashMap;
+
 use anyhow::Result;
 use events::MpvEventHandler;
 use libmpv2::{events::EventContext, Mpv};
@@ -77,20 +79,21 @@ pub async fn watch(app: &App) -> Result<()> {
         play_things.len()
     );
 
-    let mut playlist_cache: Vec<ExtractorHash> = Vec::with_capacity(play_things.len());
+    let mut playlist_cache: HashMap<String, ExtractorHash> =
+        HashMap::with_capacity(play_things.len());
 
     for play_thing in play_things {
         debug!("Adding '{}' to playlist.", play_thing.title);
 
         let orig_cache_path = play_thing.cache_path.expect("Is cached and thus some");
         let cache_path = orig_cache_path.to_str().expect("Should be vaild utf8");
-        let cache_path = format!("\"{}\"", cache_path);
+        let fmt_cache_path = format!("\"{}\"", cache_path);
 
-        let args = &[&cache_path, "append-play"];
+        let args = &[&fmt_cache_path, "append-play"];
 
         mpv.execute("loadfile", args)?;
 
-        playlist_cache.push(play_thing.extractor_hash);
+        playlist_cache.insert(cache_path.to_owned(), play_thing.extractor_hash);
     }
 
     let mut mpv_event_handler = MpvEventHandler::from_playlist(playlist_cache);