From 03d492c9460791dfb00ff274efbc1e705cfb4a2b Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Tue, 25 Oct 2022 16:00:30 -0600 Subject: [PATCH] Added playlist safety for videos that fail to play --- ytbrowser.pl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ytbrowser.pl b/ytbrowser.pl index bdcf309..72fed93 100755 --- a/ytbrowser.pl +++ b/ytbrowser.pl @@ -199,28 +199,32 @@ $suggestions->set_binding( sub { }, KEY_ENTER); $suggestions->set_binding( sub { my $video = $watchlist[0]; + unless($video) { return 0; } $cui->status("Playing Video, controls will resume once video is compelte\n Currently Playing: ".$watchArray[0]); - my $success=`mpv --script-opts=ytdl_hook-ytdl_path=yt-dlp --ytdl-raw-options=cookies=$cookiesFile,mark-watched=,buffer-size=200M,format='bestvideo[height<=720]+bestaudio/best[height<=720]' --terminal=no https://www.youtube.com/watch?v=$video->{id}`; - if($success) { - shift(@watchlist);} + if (0 == system("mpv --script-opts=ytdl_hook-ytdl_path=yt-dlp --ytdl-raw-options=cookies=$cookiesFile,mark-watched=,buffer-size=200M,format='bestvideo[height<=720]+bestaudio/best[height<=720]' --terminal=no https://www.youtube.com/watch?v=$video->{id}")) { + shift(@watchArray); + shift(@watchlist); sync2files(); $win->draw(); $suggestions->draw(); $wlist->draw(); + $cui->status("Playback Complete, video cleared"); } else { $cui->status("PLAYBACK ERROR: Video not removed for safety."); } }, "p"); $wlist->set_binding( sub { my $video = $watchlist[$wlist->get_active_id()]; + unless($video) { return 0; } $cui->status("Playing Video, controls will resume once video is compelte\n Currently Playing: ".$watchArray[$wlist->get_active_id()]); - my $success=`mpv --script-opts=ytdl_hook-ytdl_path=yt-dlp --ytdl-raw-options=cookies=$cookiesFile,mark-watched=,buffer-size=200M,format='bestvideo[height<=720]+bestaudio/best[height<=720]' --terminal=no https://www.youtube.com/watch?v=$video->{id}`; - if ($success) { + if (0 == system("mpv --script-opts=ytdl_hook-ytdl_path=yt-dlp --ytdl-raw-options=cookies=$cookiesFile,mark-watched=,buffer-size=200M,format='bestvideo[height<=720]+bestaudio/best[height<=720]' --terminal=no https://www.youtube.com/watch?v=$video->{id}")) { + splice(@watchArray,$wlist->get_active_id(),1); splice(@watchlist,$wlist->get_active_id(),1); sync2files(); $win->draw(); $suggestions->draw(); $wlist->draw(); + $cui->status("Playback Complete, video cleared"); } else { $cui->status("PLAYBACK ERROR: Video not removed for safety."); } @@ -244,7 +248,7 @@ $suggestions->set_binding( sub { $cui->status("Video: ".$vid->{title}."\nChannel: ".$vid->{channel}."\nRuntime: ".$vid->{runtime}."\nPublished: ".$vid->{published}."\nURL: https://www.youtube.com/watch?v=".$vid->{id}); }, "i"); $wlist->set_binding( sub { - my $vid = $videos[$wlist->get_active_id()]; + my $vid = $watchlist[$wlist->get_active_id()]; $cui->status("Video: ".$vid->{title}."\nChannel: ".$vid->{channel}."\nRuntime: ".$vid->{runtime}."\nPublished: ".$vid->{published}."\nURL: https://www.youtube.com/watch?v=".$vid->{id}); } , "i");