rss logo


Here is a perl script that I use to automatically rename audios using tags informations inside the file.




user@host:~$ ./


# Role : Perl script which allow to rename audio files
# Author :
# Instructions  : 
# - create a folder /tmp/MP3/ and add mp3 files which will be renamed
# - create a folder /tmp/MP3/TRIE which will contain renamed files
# 1.0 first version

use strict; use File::Copy;
no warnings;                 #avoid warnings in case of a field which cannot be get

foreach my $i (`ls -1 /tmp/MP3/*mp3`) {
        chomp ($i);
        $i =~ s/\s/\\ /g;                                       #convert space by "\ "
        my $MEDIA = `/usr/bin/mediainfo $i`;           #put tags inside $MEDIA
        my ($ARTIST) = ($MEDIA =~ m/Performer.*: (.*)/);        #get artist name
        my ($TITRE) = ($MEDIA =~ m/Track name.*: (.*)/);        #get title
        my ($NUM) = ($MEDIA =~ m/Track name\/Position.*: ([0-3]?[0-9])/);       #get track number
        printf "$ARTIST - $NUM - $TITRE\n" if (defined($ARTIST));       #print formated name
        my ($NOM) = "$ARTIST - $NUM - $TITRE.mp3";              #format name
        $i =~ s/\\ / /g;                                        #convert spaces by " " (needed for the copy function)
        copy("$i","/tmp/MP3/TRIE/$NOM");               #copy file to /tmp/MP3/TRIE/ folder with the new name
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address