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

5

1

I have a bunch of recovered mp3 files that have system generated filenames. I want to use any embedded ID3 tag info in the files to rename each one to something human readable.

I've tried 'mp3rename' from the debian apt repo but it doesn't handle mp3 files without id3 tagging automatically. Is there a workable alternative?

rutherford

Posted 2013-02-21T17:27:53.313

Reputation: 1 041

Answers

2

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.

Rob

Posted 2013-02-21T17:27:53.313

Reputation: 2 152

3

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.

kmort

Posted 2013-02-21T17:27:53.313

Reputation: 1 609

1

I made a few changes to this script and put it on Github: https://github.com/hovenko/audio-renamer , which now also provides a print of "mv" commands to rename the files according to track number and title.

– hovenko – 2015-11-16T19:04:02.543

1

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

It's not limited to only MP3 files.

user1338062

Posted 2013-02-21T17:27:53.313

Reputation: 727

1

You can try the kid3-cli tool command from Kid3

Example :

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

SebMa

Posted 2013-02-21T17:27:53.313

Reputation: 599

1

This is not command line, but EasyTag is what I have always used. It lets me add Cover and CD artwork to the files also.

Linux User 1Million and 10

Posted 2013-02-21T17:27:53.313

Reputation: 11

2

Just mentioning the name of a tool isn't considered an answer. Please see http://meta.superuser.com/questions/5329/how-do-i-recommend-software-in-my-answers for guidance on recommending software. Thanks.

– fixer1234 – 2015-09-26T00:51:04.440