-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmplayer.pl
executable file
·82 lines (72 loc) · 2.28 KB
/
mplayer.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
#
#Tue May 30 22:18:04 CEST 2017;
use TempFileNames;
use Set;
use Data::Dumper;
use File::Slurp;
# default options
$main::d = { config => 'config.cfg', 'hello' => sub { print "hello world\n"; }, triggerPrefix => 'do',
triggerDefault => undef, doReturn => 0, unlink => 1 };
# options
# mplayer -nolirc URL -dumpstream -dumpfile OUTPUT
$main::o = ['nolirc', 'dumpstream', 'dumpfile=s', 'unlink!'];
$main::usage = '';
$main::helpText = <<HELP_TEXT.$TempFileNames::GeneralHelp;
mplayer.pl -nolirc file.3u8 -dumpstream -dumpfile a.out --dologonly --no-unlink
HELP_TEXT
#
# <p> helpers
#
sub option2str { my ($c, $o) = @_;
my ($n, $a) = ($o =~ m{([a-z][a-z0-9-_]+)(?:=(.))?}soi);
return defined($c->{$n})? "-$n". ($a ne ''? ' '. qs($c->{$n}): ''): '';
}
sub options2str { my ($c, @o) = @_;
return join(' ', map { option2str($c, $_) } @o);
}
my @mplayerOptions = ('nolirc', 'dumpstream', 'dumpfile=s');
#
# <p> mplayer wrappers
#
sub mplayer_default { my ($c, @args) = @_;
my $cmd = 'mplayer '. options2str($c, @mplayerOptions). ' '. join(' ', map { qs($_) } @args);
System($cmd, 2);
}
sub mplayer_m3u { my ($c, @args) = @_;
mplayer_default($c, @args);
# <!> assume m3u was dumped
my $file = $c->{dumpfile};
my $spM = splitPathDict($file);
my @files = (grep { ! ($_ =~ m{^#}so) } read_file($file, chomp => 1));
my @o = map {
my $i = $_;
my $f = $files[$i];
my $sp = splitPathDict($f);
#my $cmd = sprintf('wget -o %s-%03d.%s '. qs($f), qs($spM->{base}), $i, $sp->{extension});
my $fo = sprintf('%s-%03d.%s', $spM->{basePath}, $i, $sp->{extension});
my $options = options2str({%$c, dumpfile => $fo}, @mplayerOptions);
my $cmd = "mplayer $options ". qs($f);
System($cmd, 4);
$fo
} (0 .. $#files);
my $cmd = 'mkvmerge -o '. qs($spM->{basePath}). '.mkv '. join(' + ', map { qs($_) } @o);
System($cmd, 2);
if ($c->{unlink}) {
Log("Removing temp files.", 2);
Log("Temp files: ". join(' ', @o), 5);
unlink(@o);
}
}
my %extensionDict = ( m3u => 'm3u', m3u8 => 'm3u' );
sub mplayer { my ($c, @args) = @_;
my $file = $args[0];
my $sp = splitPathDict($file);
my $handler = 'mplayer_'. firstDef($extensionDict{$sp->{extension}}, 'default');
$handler->($c, @args);
}
#main $#ARGV @ARGV %ENV
#initLog(2);
my $c = StartStandardScript($main::d, $main::o);
mplayer($c, @ARGV);
exit(0);