Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (5)
    As of 2015-07-04 19:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls