Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Handy script! I added some tag checking/customization:
#!/usr/bin/perl use strict; use warnings; # Create folder hierarchy based on MP3 tags. # Based on: # To get mp3 files from directories # find /path/to/mp3_dirs/ -iname '*.mp3' -exec cp "{}" . \; use MP3::Tag; use File::Copy::Recursive qw(fmove); my $Debug = 1; # 1 - don't move files just print the new path foreach my $file (<*.mp3>) { my $mp3 = MP3::Tag->new($file); my ( $title, $track, $artist, $album ) = ( $mp3->autoinfo() )[ 0, +1, 2, 3 ]; $mp3->close(); # Check/customize tags $track = $track =~ /^([0-9]+)/ ? sprintf "%02d", $1 : undef; $title = $title eq '' ? 'uknown_title' : $title; $artist = $artist eq '' ? 'uknown_artist' : $artist; $album = $album eq '' ? 'uknown_album' : $album; s/[\\\/:*?"<>|]//g for $artist, $album; # Set the new path my $path = defined $track ? "$artist/$album/$track $title.mp3" : "$artist/$album/$title.mp3"; if ($Debug) { print "$path\n"; } else { fmove( $file, $path ) or warn "Can't fmove '$file': $!"; } }
Update: Replaced path setting if structure with the ternary operator.

Have a nice day, j

In reply to Re: Create folder hierarchy based on MP3 tags by reisinge
in thread Create folder hierarchy based on MP3 tags by thmsdrew

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (8)
    As of 2018-06-23 07:27 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (125 votes). Check out past polls.