Linux command line tool to batch rename MP3 files based on ID3 tag info, or give random name if no ID3 info present

Solution 1:

id3v2 and some scripting should make this possible. I'll look through the man pages and try to write up an example, but id3v2 -l file will list the tags from that file. From there you can pipe through awk/sed/whatever to end up with a command to rename the file.

Solution 2:

If you like Perl, an easy way to get a hold of the tags is this:

#!/usr/bin/env perl
use File::Find;
use MP3::Tag;
use Cwd;

$dir = ".";
open(OUTFILE,">tags.txt") || die "Can't open: $!\n";
print OUTFILE 'Output for "'.getcwd().'"'." and subdirectories\n";
print OUTFILE "Path;Artist;Title;Track;Album;Year;Genre;File Size\n";

find(\&edits, $dir);
close(OUTFILE);
print "Done\n";

sub edits() 
{
    $fn=$_;
    $not_shown=1;
    if ( -f and $fn=~m/.+\.mp3$/ig)
        {
        $mp3 = MP3::Tag->new($fn);
        ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
        $fs= -s $fn;
        print OUTFILE "$File::Find::name\\$fn;$artist;$title;$track;$album;$year;$genre;$fs\n";
        }
    if ( -f and $fn=~m/.+\.wav$|\.m4a$/ig)
        {
        $fs= -s $fn;
        print OUTFILE "$File::Find::name\\$fn;;;;;;;$fs\n";
        }
}

From there, a little scripting, and you've got what you want.

Solution 3:

You can try the kid3-cli tool command from Kid3

Example :

kid3-cli -c 'fromtag "%{track}__%{album}__%{title}" 1' *.mp3

Solution 4:

Have a look at exiftool, more specifically, the manpage section titled RENAMING EXAMPLES.

It's not limited to only MP3 files.