ytv: Deal with files that are renamed while running.
This commit is contained in:
parent
d990ce6bcb
commit
ec48e1066d
39
ytv/ytv
39
ytv/ytv
|
@ -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) {
|
if($answer =~ /^d$/i) {
|
||||||
unlink $_;
|
unlink $_;
|
||||||
}
|
}
|
||||||
if($answer =~ /^p$/i) {
|
if($answer =~ /^p$/i) {
|
||||||
$i -= 2;
|
# 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);
|
||||||
}
|
}
|
||||||
} while($answer =~ /^r?$/i);
|
} else {
|
||||||
|
# Find the first existing file
|
||||||
|
do {
|
||||||
|
$i++;
|
||||||
|
} until (-e $plist[$i] or $i > $#plist);
|
||||||
}
|
}
|
||||||
if($answer =~ m,http.?://,) {
|
if($i > $#plist) { last; }
|
||||||
play($answer);
|
|
||||||
}
|
}
|
||||||
} 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);
|
||||||
|
|
Loading…
Reference in a new issue