1
0
mirror of http://mpg123.de/trunk/.git synced 2025-07-31 13:24:22 +03:00

Add --continue mode, with example script to utilize it.

git-svn-id: svn://scm.orgis.org/mpg123/trunk@3120 35dc7657-300d-0410-a2e5-dc2837fedb53
This commit is contained in:
thor
2012-04-22 23:04:16 +00:00
parent db9c24e249
commit 8c8675fa09
7 changed files with 133 additions and 9 deletions

89
scripts/conplay Executable file
View File

@ -0,0 +1,89 @@
#!/bin/env perl
# Hacked by Thomas Orgis, use at your leisure.
use strict;
my @mpg123_command = qw(mpg123 --continue -Cv --rva-album);
my $listfile = "conplay.m3u";
my $glob = '*.mp[123]';
my $dir = shift;
unless(defined $dir)
{
print STDERR "\nThis little wrapper runs $mpg123_command[0] on a given directory (hand in '.' for the current one), playing all $glob files therein in terminal control mode. The extra trick is that a playlist file ($listfile) is read and updated (created) with the position you left playback at (via 'q' key), to return on next invokation.\n\n";
print STDERR "The name stands for CONtinued PLAYback. What did you think?;-)\n\n";
exit;
}
chdir($dir) or die "Cannot enter $dir ($!)!\n";
print STDERR "Playing things in: $dir\n";
my @files;
my $entry = 1;
my $frame = 0;
if(-e $listfile)
{
open(LIST, '<', $listfile) or die "Cannot read playlist ($!)!\n";
while(<LIST>)
{
chomp;
unless(/^#/)
{
push(@files, $_);
}
elsif(/^#\s*current entry:\s*(\d+)$/)
{
$entry = $1;
}
elsif(/^#\s*current frame:\s*(\d+)$/)
{
$frame = $1;
}
}
close(LIST);
}
else
{
@files = glob($glob);
write_list();
}
if($entry < 0 or $entry > $#files or $frame < 0)
{
die "You got bad data in your playlist file. Clean that up.\n";
}
push(@mpg123_command, '-k', $frame, '--listentry', $entry, '-@', $listfile);
print STDERR "running player:\n\t@mpg123_command\n\n";
open(MPG123, '-|', @mpg123_command) or die "Cannot run mpg123!";
while(<MPG123>)
{
print STDOUT $_;
if(/^\[CONTINUE\]\s+track\s+(\d+)\s+frame\s+(\d+)/)
{
$entry = $1;
$frame = $2;
}
}
close(MPG123);
print STDERR "Continue point is in track $entry, frame $frame.\n";
write_list();
sub write_list
{
open(LIST, '>', $listfile) or die "Cannot write Playlist";
print LIST "#M3U\n";
print LIST "#current entry: $entry\n";
print LIST "#current frame: $frame\n";
for my $f (@files)
{
print LIST "$f\n";
}
close(LIST);
}