ytv: Deal with files that are renamed while running.
This commit is contained in:
parent
d990ce6bcb
commit
ec48e1066d
51
ytv/ytv
51
ytv/ytv
|
@ -95,37 +95,48 @@ sub playfiles {
|
|||
my @files = @_;
|
||||
|
||||
if($opt::kodi) {
|
||||
my @existing =
|
||||
uniq(
|
||||
grep { -f $_ }
|
||||
map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @files
|
||||
);
|
||||
for (my $i = 0; $i <= $#existing; $i++) {
|
||||
my $answer;
|
||||
$_ = $existing[$i];
|
||||
do {
|
||||
# Playlist includes partial files
|
||||
my @plist =
|
||||
uniq(map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @files);
|
||||
my $i = 0;
|
||||
while(1) {
|
||||
$_ = $plist[$i];
|
||||
if(-e $_) {
|
||||
# Only try playing if the file exists
|
||||
print "KODI playing $_\n";
|
||||
if(not fork()) {
|
||||
exec("idok", $_);
|
||||
}
|
||||
print "Press (r)etry, (d)elete, (p)revious, (n)ext\n";
|
||||
$answer = undef;
|
||||
my $answer;
|
||||
while(not defined $answer) {
|
||||
open(my $tty_fh, "<", "/dev/tty") ||
|
||||
::die_bug("interactive-tty");
|
||||
$answer = <$tty_fh>;
|
||||
close $tty_fh;
|
||||
if($answer =~ /^d$/i) {
|
||||
unlink $_;
|
||||
}
|
||||
if($answer =~ /^p$/i) {
|
||||
$i -= 2;
|
||||
}
|
||||
}
|
||||
} while($answer =~ /^r?$/i);
|
||||
}
|
||||
if($answer =~ m,http.?://,) {
|
||||
play($answer);
|
||||
if($answer =~ /^d$/i) {
|
||||
unlink $_;
|
||||
}
|
||||
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 {
|
||||
system("vlc", map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @files);
|
||||
|
|
Loading…
Reference in a new issue