Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; # mp3uncue: cut a multiple track MP3 into individual tracks using a .C +UE sheet # requires: # - mpgedit <http://mpgedit.org> # - id3tool <http://freshmeat.net/projects/id3tool/> # # Version 0.1: Nov 12, 2002, A. Pagaltzis # # (c)2002 A. Pagaltzis, licensed under the GPL # see http://www.gnu.org/copyleft/gpl.html use Env qw(@PATH); use File::Path; use File::Basename; use File::Spec::Functions; use Getopt::Long; use constant SEPARATOR => "TRACK"; use constant NAME_FMT => "%02d %s - %s.mp3"; use constant NAME_FIELDS => qw(TRACK PERFORMER TITLE); my %keyword = ( PERFORMER => sub { $_[0] }, TITLE => sub { $_[0] }, TRACK => sub { $_[0] }, INDEX => sub { my ($m, $s, $f) = split /:/, $_[1], 3; "$m:" . sprintf("%06.3f", $s + $f / 75); }, FILE => sub { $_[0] }, ); my ($infile, $outdir, $album, @exec, $mpgedit, $id3tool); ## parse cmdline options and check existence of tools ( GetOptions( 'infile|i=s', \$infile, 'outdir|d=s', \$outdir, ) && (@ARGV > 0) && (@exec = grep { -f and -x _ } map { my $dir = $_; opendir my($dh), $dir; map catfile($dir, $_), readdir $dh; } @PATH) && (($mpgedit) = grep basename($_) eq 'mpgedit', @exec) && (($id3tool) = grep basename($_) eq 'id3tool', @exec) ) or die << 'USAGE'; usage: mp3uncue [-i infile] [-d outdir] sheet.cue --infile -i defaults to filename from cue sheet --outdir -d defaults to current directory You need mpgedit <http://mpgedit.org> and id3tool <http://freshmeat.net/projects/id3tool> in your PATH to run this utility. USAGE ## parse cue sheet my $rx = do { local $" = "|"; qr/(@{[keys %keyword]})\s+(.*)/ }; my @track = ({}); while(<>) { chomp; (my ($key), $_) = /$rx/ or next; push @track, {} if $key eq SEPARATOR; $track[-1]->{$key} = $keyword{$key}->(/"?((?<!")\S+(?<!")|[^"]+)"?\s*/g); } push @track, { INDEX => '' }; ## set overall defaults for(shift @track) { $infile ||= $_->{FILE}; $album ||= $_->{TITLE}; $outdir ||= '.'; } ## process mkpath [$outdir] if not -d $outdir; for my $i (0 .. $#track-1) { for($track[$i]) { (my $filename = sprintf NAME_FMT, @$_{NAME_FIELDS()}, ('')x10) + =~ tr/ _/_/s; my $time = $_->{INDEX} . '-' . $track[$i+1]->{INDEX}; printf STDERR "%-19s = $filename\n", $time; $filename = catfile($outdir, $filename); system( $mpgedit, '-s', -e => $time, -f => $infile, -o => $filename, ) == 0 or die basename($0).": mpgedit failed creating $filenam +e\n"; system( $id3tool, "--set-title=" . ($_->{TITLE} || ""), "--set-artist=" . ($_->{PERFORMER} || ""), "--set-album=" . ($album || ""), "--set-track=" . ($_->{TRACK} || ""), $filename, ); } }

In reply to mp3uncue by Aristotle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-18 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found