2

I want a CLI or GUI solution for replacing file name of each file with the title of that file.

I have multiple radio podcasts with file names that do not properly show the content. That is visible in media players under Title, but I have problems seeing those in file mangers, so I want to replace file names with titles.

I am looking for a Linux native tool, while I know how to do this in Wine with programs like Foobar2000.

Edit after comment: these are mp3 files. I can see the title data displayed in the info panel of Dolphin file manager.

  • 2
    What format are the files in? “Title” is not a universal property of a file, it depends on the file format. – Gilles Nov 20 '16 at 13:43
  • @Gilles - I will add that in the question. – user32012 Nov 20 '16 at 15:42
1

If you are looking for a native tool there is the command line mp3rename available with some distributions, and the gui pyrenamer.

For the former, first set up a format of "title" (&t) with

mp3rename -s '&t'

then you can rename your files by just running mp3rename on them by just giving it a list of filenames. E.g. if you are in a directory with mp3 files you type mp3rename *.mp3. Or you can recursively search for files named *.mp3 from some starting directory ABC with e.g.

find ABC -name '*.mp3' -exec mp3rename {} \;

You might want to work on a copy of your files to ensure you have no surprises!

For the gui pyrenamer, later versions have a tab Music where you "rename music using its metadata". Put the string {title}.mp3 in this field, select the files to operate on, and click Preview to see what the names would become.

enter image description here

  • how do you "run mp3rename on them"? – user32012 Nov 20 '16 at 17:24
  • you just have to give it a list of filenames, I updated my answer. Please work on a copy of your files! – meuh Nov 20 '16 at 17:35
1

How about Perl? It's native to Linux. My test setup is as follows... mp3.pl script is in the same directory as the music directory which contains the songs we'll be working on. I pass this in as a command line argument. The code iterates over this directory, fetching all mp3 files. It then iterates over the list of tracks, and one at a time, renames them to the track title:

First, see what tracks we have:

$ ls music
track1.mp3  track2.mp3

The code:

use warnings;
use strict;

use File::Copy;
use File::Find::Rule;
use MP3::Tag;

if (! @ARGV){
    print "usage: perl mp3.pl <directory>\n";
    exit;
}

my $dir = $ARGV[0];

my @files = File::Find::Rule->file()
                            ->name('*.mp3')
                            ->in($dir);

for my $track (@files){
    my $mp3 = MP3::Tag->new($track);

    my $title = $mp3->title;
    $title .= '.mp3';

    move $track, "$dir/$title" or die $!;
}

Run it:

perl mp3.pl music

The 'music' directory after the change:

$ ls music/
Almost Famous.mp3  No Love (feat Lil Wayne).mp3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy