Added network checking so videos don't vanish into the ether when I lose wifi
This commit is contained in:
parent
d6527dce66
commit
575cf2705a
58
ytbrowser.pl
58
ytbrowser.pl
@ -13,7 +13,7 @@ use Curses::UI;
|
||||
#$Data::Dumper::Maxdepth = 1;
|
||||
|
||||
my $homeDir = "/home/bluesaxman/";
|
||||
my $cookiesFile = $homeDir.".scripts/cookies.txt";
|
||||
my $cookiesFile = $homeDir."cookies.txt";
|
||||
my $cachedFile = $homeDir.".yt_cache";
|
||||
my $playlistFile = $homeDir.".yt_play";
|
||||
my $debugFile = $homeDir.".yt_last";
|
||||
@ -166,17 +166,17 @@ open(CACHING, ">", $cachedFile);
|
||||
open(SAVE, ">", $playlistFile);
|
||||
|
||||
sub sync2files {
|
||||
truncate(DEBUG,0);
|
||||
truncate(CACHING,0);
|
||||
truncate(SAVE,0);
|
||||
truncate(DEBUG,0);
|
||||
truncate(CACHING,0);
|
||||
truncate(SAVE,0);
|
||||
|
||||
seek(DEBUG,0,0);
|
||||
seek(CACHING,0,0);
|
||||
seek(SAVE,0,0);
|
||||
seek(DEBUG,0,0);
|
||||
seek(CACHING,0,0);
|
||||
seek(SAVE,0,0);
|
||||
|
||||
if ($rawFile) { print DEBUG $rawFile; }
|
||||
print CACHING encode_json(\@videos);
|
||||
print SAVE encode_json(\@watchlist);
|
||||
if ($rawFile) { print DEBUG $rawFile; }
|
||||
print CACHING encode_json(\@videos);
|
||||
print SAVE encode_json(\@watchlist);
|
||||
}
|
||||
|
||||
####################################################
|
||||
@ -198,22 +198,32 @@ $suggestions->set_binding( sub {
|
||||
$wlist->draw();
|
||||
}, KEY_ENTER);
|
||||
$suggestions->set_binding( sub {
|
||||
my $video = shift(@watchlist);
|
||||
$cui->status("Playing Video, controls will resume once video is compelte\n Currently Playing: ".shift(@watchArray));
|
||||
`mpv --ytdl-raw-options=cookies=$cookiesFile,mark-watched= --terminal=no https://www.youtube.com/watch?v=$video->{id}`;
|
||||
sync2files();
|
||||
$win->draw();
|
||||
$suggestions->draw();
|
||||
$wlist->draw();
|
||||
my $video = $watchlist[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);}
|
||||
sync2files();
|
||||
$win->draw();
|
||||
$suggestions->draw();
|
||||
$wlist->draw();
|
||||
} else {
|
||||
$cui->status("PLAYBACK ERROR: Video not removed for safety.");
|
||||
}
|
||||
}, "p");
|
||||
$wlist->set_binding( sub {
|
||||
my $video = splice(@watchlist,$wlist->get_active_id(),1);
|
||||
$cui->status("Playing Video, controls will resume once video is compelte\n Currently Playing: ".splice(@watchArray,$wlist->get_active_id(),1));
|
||||
`mpv --ytdl-raw-options=cookies=$cookiesFile,mark-watched= --terminal=no https://www.youtube.com/watch?v=$video->{id}`;
|
||||
sync2files();
|
||||
$win->draw();
|
||||
$suggestions->draw();
|
||||
$wlist->draw();
|
||||
my $video = $watchlist[$wlist->get_active_id()];
|
||||
$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) {
|
||||
splice(@watchlist,$wlist->get_active_id(),1);
|
||||
sync2files();
|
||||
$win->draw();
|
||||
$suggestions->draw();
|
||||
$wlist->draw();
|
||||
} else {
|
||||
$cui->status("PLAYBACK ERROR: Video not removed for safety.");
|
||||
}
|
||||
} , "p");
|
||||
$suggestions->set_binding( sub {
|
||||
splice(@videos,0,scalar(@videos));
|
||||
|
Loading…
x
Reference in New Issue
Block a user