ytv: Deal with files that are renamed while running.

This commit is contained in:
Ole Tange 2020-06-05 12:44:51 +02:00
parent d990ce6bcb
commit ec48e1066d

51
ytv/ytv
View file

@ -95,37 +95,48 @@ sub playfiles {
my @files = @_; my @files = @_;
if($opt::kodi) { if($opt::kodi) {
my @existing = # Playlist includes partial files
uniq( my @plist =
grep { -f $_ } uniq(map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @files);
map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @files my $i = 0;
); while(1) {
for (my $i = 0; $i <= $#existing; $i++) { $_ = $plist[$i];
my $answer; if(-e $_) {
$_ = $existing[$i]; # Only try playing if the file exists
do {
print "KODI playing $_\n"; print "KODI playing $_\n";
if(not fork()) { if(not fork()) {
exec("idok", $_); exec("idok", $_);
} }
print "Press (r)etry, (d)elete, (p)revious, (n)ext\n"; print "Press (r)etry, (d)elete, (p)revious, (n)ext\n";
$answer = undef; my $answer;
while(not defined $answer) { while(not defined $answer) {
open(my $tty_fh, "<", "/dev/tty") || open(my $tty_fh, "<", "/dev/tty") ||
::die_bug("interactive-tty"); ::die_bug("interactive-tty");
$answer = <$tty_fh>; $answer = <$tty_fh>;
close $tty_fh; close $tty_fh;
if($answer =~ /^d$/i) {
unlink $_;
}
if($answer =~ /^p$/i) {
$i -= 2;
}
} }
} while($answer =~ /^r?$/i); if($answer =~ /^d$/i) {
} unlink $_;
if($answer =~ m,http.?://,) { }
play($answer); if($answer =~ /^p$/i) {
# Find previous existing file
do {
$i--;
} until (-e $plist[$i] or $i == 0);
}
if($answer =~ /^n$/i) {
# Find next existing file
do {
$i++;
} until (-e $plist[$i] or $i > $#plist);
}
} else {
# Find the first existing file
do {
$i++;
} until (-e $plist[$i] or $i > $#plist);
}
if($i > $#plist) { last; }
} }
} else { } else {
system("vlc", map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @files); system("vlc", map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @files);