diff options
Diffstat (limited to 'src/watch/events/mod.rs')
-rw-r--r-- | src/watch/events/mod.rs | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/watch/events/mod.rs b/src/watch/events/mod.rs index 9ca12fd..1459147 100644 --- a/src/watch/events/mod.rs +++ b/src/watch/events/mod.rs @@ -8,7 +8,7 @@ // 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, env::current_exe, mem, time::Duration, usize}; +use std::{collections::HashMap, env::current_exe, mem, time::Duration}; use anyhow::{bail, Result}; use libmpv2::{ @@ -58,9 +58,9 @@ impl MpvEventHandler { let play_things = get_videos(app, &[VideoStatus::Cached], Some(false)).await?; // There is nothing to watch - if play_things.len() == 0 { + if play_things.is_empty() { if force_message { - Self::message(&mpv, "No new videos available to add", "3000")?; + Self::message(mpv, "No new videos available to add", "3000")?; } return Ok(0); } @@ -72,8 +72,7 @@ impl MpvEventHandler { .filter(|val| { !current_playlist .values() - .find(|a| *a == &val.extractor_hash) - .is_some() + .any(|a| a == &val.extractor_hash) }) .filter(|val| { if self @@ -112,7 +111,7 @@ impl MpvEventHandler { if force_message || num > 0 { Self::message( - &mpv, + mpv, format!( "Added {} videos ({} are marked as watch later)", num, blocked_videos @@ -163,7 +162,7 @@ impl MpvEventHandler { async fn mark_video_watched(&self, app: &App, hash: &ExtractorHash) -> Result<()> { let video = get_video_by_hash(app, hash).await?; debug!("MPV handler will mark video '{}' watched.", video.title); - set_video_watched(&app, &video).await?; + set_video_watched(app, &video).await?; Ok(()) } @@ -178,7 +177,7 @@ impl MpvEventHandler { .get(&playlist_index) .expect("The video index should always be correctly tracked"); - set_state_change(&app, video_hash, false).await?; + set_state_change(app, video_hash, false).await?; Ok(()) } async fn mark_video_active( @@ -192,7 +191,7 @@ impl MpvEventHandler { .get(&playlist_index) .expect("The video index should always be correctly tracked"); - set_state_change(&app, video_hash, true).await?; + set_state_change(app, video_hash, true).await?; Ok(()) } @@ -259,9 +258,9 @@ impl MpvEventHandler { // draining the playlist is okay, as mpv is done playing let mut handler = mem::take(&mut self.playlist_handler); let videos = handler.playlist_ids(mpv)?; - for (_, hash) in videos { - self.mark_video_watched(app, &hash).await?; - set_state_change(&app, &hash, false).await?; + for hash in videos.values() { + self.mark_video_watched(app, hash).await?; + set_state_change(app, hash, false).await?; } return Ok(true); } @@ -273,7 +272,7 @@ impl MpvEventHandler { } }, Event::StartFile(entry_id) => { - self.possibly_add_new_videos(app, &mpv, false).await?; + self.possibly_add_new_videos(app, mpv, false).await?; // We don't need to check, whether other videos are still active, as they should // have been marked inactive in the `Stop` handler. @@ -297,7 +296,7 @@ impl MpvEventHandler { } let status = Command::new("alacritty") - .args(&[ + .args([ "--title", "floating please", "--command", @@ -338,7 +337,7 @@ impl MpvEventHandler { } &["yt-description"] => { // let description = description(app).await?; - Self::message(&mpv, "<YT Description>", "6000")?; + Self::message(mpv, "<YT Description>", "6000")?; } &["yt-mark-watch-later"] => { mpv.execute("write-watch-later-config", &[])?; @@ -350,13 +349,13 @@ impl MpvEventHandler { "A video should not be blocked *and* in the playlist" ); - Self::message(&mpv, "Marked the video to be watched later", "3000")?; + Self::message(mpv, "Marked the video to be watched later", "3000")?; } &["yt-mark-done-and-go-next"] => { let cvideo_hash = self.remove_cvideo_from_playlist(mpv)?; self.mark_video_watched(app, &cvideo_hash).await?; - Self::message(&mpv, "Marked the video watched", "3000")?; + Self::message(mpv, "Marked the video watched", "3000")?; } &["yt-check-new-videos"] => { self.possibly_add_new_videos(app, mpv, true).await?; |