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;
|
#$Data::Dumper::Maxdepth = 1;
|
||||||
|
|
||||||
my $homeDir = "/home/bluesaxman/";
|
my $homeDir = "/home/bluesaxman/";
|
||||||
my $cookiesFile = $homeDir.".scripts/cookies.txt";
|
my $cookiesFile = $homeDir."cookies.txt";
|
||||||
my $cachedFile = $homeDir.".yt_cache";
|
my $cachedFile = $homeDir.".yt_cache";
|
||||||
my $playlistFile = $homeDir.".yt_play";
|
my $playlistFile = $homeDir.".yt_play";
|
||||||
my $debugFile = $homeDir.".yt_last";
|
my $debugFile = $homeDir.".yt_last";
|
||||||
@ -166,17 +166,17 @@ open(CACHING, ">", $cachedFile);
|
|||||||
open(SAVE, ">", $playlistFile);
|
open(SAVE, ">", $playlistFile);
|
||||||
|
|
||||||
sub sync2files {
|
sub sync2files {
|
||||||
truncate(DEBUG,0);
|
truncate(DEBUG,0);
|
||||||
truncate(CACHING,0);
|
truncate(CACHING,0);
|
||||||
truncate(SAVE,0);
|
truncate(SAVE,0);
|
||||||
|
|
||||||
seek(DEBUG,0,0);
|
seek(DEBUG,0,0);
|
||||||
seek(CACHING,0,0);
|
seek(CACHING,0,0);
|
||||||
seek(SAVE,0,0);
|
seek(SAVE,0,0);
|
||||||
|
|
||||||
if ($rawFile) { print DEBUG $rawFile; }
|
if ($rawFile) { print DEBUG $rawFile; }
|
||||||
print CACHING encode_json(\@videos);
|
print CACHING encode_json(\@videos);
|
||||||
print SAVE encode_json(\@watchlist);
|
print SAVE encode_json(\@watchlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
@ -198,22 +198,32 @@ $suggestions->set_binding( sub {
|
|||||||
$wlist->draw();
|
$wlist->draw();
|
||||||
}, KEY_ENTER);
|
}, KEY_ENTER);
|
||||||
$suggestions->set_binding( sub {
|
$suggestions->set_binding( sub {
|
||||||
my $video = shift(@watchlist);
|
my $video = $watchlist[0];
|
||||||
$cui->status("Playing Video, controls will resume once video is compelte\n Currently Playing: ".shift(@watchArray));
|
$cui->status("Playing Video, controls will resume once video is compelte\n Currently Playing: ".$watchArray[0]);
|
||||||
`mpv --ytdl-raw-options=cookies=$cookiesFile,mark-watched= --terminal=no https://www.youtube.com/watch?v=$video->{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}`;
|
||||||
sync2files();
|
if($success) {
|
||||||
$win->draw();
|
shift(@watchlist);}
|
||||||
$suggestions->draw();
|
sync2files();
|
||||||
$wlist->draw();
|
$win->draw();
|
||||||
|
$suggestions->draw();
|
||||||
|
$wlist->draw();
|
||||||
|
} else {
|
||||||
|
$cui->status("PLAYBACK ERROR: Video not removed for safety.");
|
||||||
|
}
|
||||||
}, "p");
|
}, "p");
|
||||||
$wlist->set_binding( sub {
|
$wlist->set_binding( sub {
|
||||||
my $video = splice(@watchlist,$wlist->get_active_id(),1);
|
my $video = $watchlist[$wlist->get_active_id()];
|
||||||
$cui->status("Playing Video, controls will resume once video is compelte\n Currently Playing: ".splice(@watchArray,$wlist->get_active_id(),1));
|
$cui->status("Playing Video, controls will resume once video is compelte\n Currently Playing: ".$watchArray[$wlist->get_active_id()]);
|
||||||
`mpv --ytdl-raw-options=cookies=$cookiesFile,mark-watched= --terminal=no https://www.youtube.com/watch?v=$video->{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}`;
|
||||||
sync2files();
|
if ($success) {
|
||||||
$win->draw();
|
splice(@watchlist,$wlist->get_active_id(),1);
|
||||||
$suggestions->draw();
|
sync2files();
|
||||||
$wlist->draw();
|
$win->draw();
|
||||||
|
$suggestions->draw();
|
||||||
|
$wlist->draw();
|
||||||
|
} else {
|
||||||
|
$cui->status("PLAYBACK ERROR: Video not removed for safety.");
|
||||||
|
}
|
||||||
} , "p");
|
} , "p");
|
||||||
$suggestions->set_binding( sub {
|
$suggestions->set_binding( sub {
|
||||||
splice(@videos,0,scalar(@videos));
|
splice(@videos,0,scalar(@videos));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user