Intro

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

Configuration

Instructions

Usage

user@host:~$ ./audio_rename.pl

Code

#!/usr/bin/perl
# Role : Perl script which allow to rename audio files
# Author : http://shebangthedolphins.net/
# 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
}
Licence Creative Commons
This websitehttp://shebangthedolphins.net is licensed to the public under a licence Creative Commons Attribution licence.
Contact :