ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to make a script that will create dir for each artist and then copy
all the files from that artist into that dir. Now I think I should be able
to create the script fine, but I need to be able to read the Mp3's Id3 tag
to get the name or the artist. Is this possible?
Just be aware that, unless you created the mp3 yourself, the id tag could be misspelled. This could tend to mess up your system if you use files obtained from p2p systems; some people have awful spelling
Of course, not that I would know because I never do that sort of thing
But with my basic script it will organize it a fair bit, instead of 30 Nine inch nails mp3's I only have 3 dir (NIN, Nine inch nails, and Nine Inch Nails).
I decided that it was time to organize some music and I realised I had a lot more OGGs that I'd realised, so here's a better script. It should also handle FLAC files (MP3, FLAC, and OGG are all that's currently supported under the module I'm using: http://search.cpan.org/~flora/Audio-...io/File/Tag.pm), although FLAC's implementation of ID3 is a little broken.
Just like the last one, it'll organize files by "./artist/album/". Just cd to the directory of songs you want organized and run this program. Enjoy.
Code:
#!/usr/bin/perl
use strict;
use Audio::File::Flac::Tag;
use Audio::File::Ogg::Tag;
use Audio::File::Mp3::Tag;
my @Mp3 = glob "*.mp3";
my @Flac = glob "*.flac";
my @Ogg = glob "*.ogg";
my $x;
foreach $x (@Mp3)
{
my $song = Audio::File::Mp3::Tag->new($x);
my ($artist, $album) = ($song->artist, $song->album);
if (!(-d "$artist"))
{
mkdir "$artist";
}
if (!-d "$artist/$album")
{
mkdir "$artist/$album";
}
rename ($x, "$artist/$album/$x");
printf ("Moved $x to $artist/$album/$x\n");
}
foreach $x (@Flac)
{
my $song = Audio::File::Flac::Tag->new($x);
my ($genre, $artist, $album) = ($song->artist, $song->album);
if (!(-d "$artist"))
{
mkdir "$artist";
}
if (!-d "$artist/$album")
{
mkdir "$artist/$album";
}
rename ($x, "$artist/$album/$x");
printf ("Moved $x to $artist/$album/$x\n");
}
foreach $x (@Ogg)
{
my $song = Audio::File::Ogg::Tag->new($x);
my ($artist, $album) = ($song->artist, $song->album);
if (!(-d "$artist"))
{
mkdir "$artist";
}
if (!-d "$artist/$album")
{
mkdir "$artist/$album";
}
rename ($x, "$artist/$album/$x");
printf ("Moved $x to $artist/$album/$x\n");
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.