App-rmcd
view release on metacpan or search on metacpan
toggle => 'pause',
pause => 'pause',
stop => 'stop',
fs => 'vo_fullscreen',
);
#list_channels();
my @opt_play_songs;
my($opt_shuffle, $opt_repeat) = (0, 1);
GetOptions(
'ch|chanlist' => \&list_channels,
'cp|copy' => \&cp,
'fav' => \&fav,
'kill' => sub { mplayer_stop( { pidfile => $pidfile } ); },
'load:s{1,}' => \@opt_play_songs,
'c|cmd:s{,}' => \&cmd,
'info' => \&info,
'pl|playlist' => \&show_playlist,
'r|shuffle' => \$opt_shuffle,
'repeat' => sub { $opt_repeat = 1; },
'n|next' => sub { cmd(undef, 'next') },
'p|prev' => sub { cmd(undef, 'prev') },
't|toggle' => sub { cmd(undef, 'pause') },
'f|fullscreen' => sub { cmd(undef, 'fs') },
's|stop' => sub { cmd(undef, 'stop'); },
'cl|clist' => sub {
print "$_\n" for(sort(keys(%allowed_cmds)));
print "\nSee 'mplayer -input cmdlist'\n";
exit;
},
'debug' => \$DEBUG,
'h|help' => sub { pod2usage(verbose => 1); exit },
'm|man' => sub { pod2usage(verbose => 3); exit },
'v|version' => sub { print "$APP v$VERSION\n"; exit },
);
if($opt_shuffle and !@opt_play_songs) {
print STDERR "You can not shuffle nothingness\n" and exit(-1);
}
if(@opt_play_songs) {
if($opt_shuffle) {
@opt_play_songs = shuffle(@opt_play_songs);
}
load(@opt_play_songs);
}
sub show_playlist {
my $current_file = (map { $_->{file} } now_playing($log, 'identify'))[0];
open(my $fh, '<', $temp_playlist) or die("Can not open $temp_playlist: $!");
chomp(my @list = <$fh>);
close($fh);
for(@list) {
if($_ eq $current_file) {
$_ =~ m{.+/(.+)$};
printf("%s\n", $1 ? bold($1) : bold($_));
}
else {
$_ =~ m{.+/(.+)$};
printf("%s\n", ($1) ? $1 : $_);
}
}
open(my $fh, '<', $rmcd_state) or die("Can not open $rmcd_state: $!");
chomp(my $state = <$fh>);
close($fh);
($opt_shuffle) = $state =~ m/Random: (\d+)/;
($opt_repeat) = $state =~ m/Repeat: (\d+)/;
printf("\nRandom: %s Repeat: %s\n",
$opt_shuffle ? bold(fg('blue4', 'On')) : 'Off',
$opt_repeat ? bold(fg('blue4', 'On')) : 'Off',
);
return;
}
sub fileexist {
if(!-p $fifo) {
require POSIX;
print $fifo, "\n\n";
POSIX::mkfifo($fifo, 0666) or croak("Cant mkfifo $fifo: $!");
}
if(-e $config) {
require($config);
print Dumper \%channels if($DEBUG);
}
if(!-e $rmcd_state) {
open(my $fh, '>', $rmcd_state) or die("Can not open $rmcd_state: $!");
close($fh);
}
}
sub load {
my @toload = @_;
my $listing = join("\n", @toload);
if(!-e $pidfile) { #not started
if($toload[0] !~ m;(?:http|mms)://;) {
my @fixme = @toload;
for(@fixme) {
s;.+/(.+);$1;;
print "Adding \033[1m$1\033[0m\n";
}
}
# regular files
open(my $plist, '>', $temp_playlist)
or die("Can not open $temp_playlist: $!");
print $plist $listing;
close($plist);
open(my $state, '>', $rmcd_state) or die("Can not open $rmcd_state: $!");
print $state "Random: $opt_shuffle Repeat: $opt_repeat\n";
close($state);
mplayer_play(
{
pidfile => $pidfile,
logfile => $log,
path => $player,
args => [ @playopt, @toload ],
}
);
#exec($player, @playopt, @toload);
}
# rmcd was already running
exit(0) if(!@toload);
( run in 0.745 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )