LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-01-2002, 09:23 AM   #1
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Rep: Reputation: 15
Reading Id3 tags


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?

And if it is how can it be done
 
Old 05-01-2002, 09:51 AM   #2
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Original Poster
Rep: Reputation: 15
I figured out how to read id3 tags. I downloaded and installed id3ed

Now lets see if I can make teh script.

 
Old 05-01-2002, 09:52 AM   #3
kill-hup
Member
 
Registered: Aug 2000
Location: NY - USA
Distribution: Slackware
Posts: 109

Rep: Reputation: 15
In perl, you could use one of the modules from CPAN (http://www.perl.com/CPAN-local/modules/by-module/MP3/), then use that to read the tags and move files to the appropriate directories.

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
 
Old 05-01-2002, 10:33 AM   #4
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Original Poster
Rep: Reputation: 15
got it!!!

kill-hup, I know what you mean

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).

Much easier to handle.
 
Old 10-01-2005, 08:28 PM   #5
CoolAJ86
Member
 
Registered: Jan 2004
Location: VT, USA
Distribution: Gentoo, Ubuntu - t3h 1337 & the easy, respectively
Posts: 125

Rep: Reputation: 15
Care to share?

I'd be surprised if you get this message, but if you do would you mind posting a link to your script? I'm trying to do the same thing.
 
Old 10-01-2005, 09:04 PM   #6
destuxor
Member
 
Registered: Oct 2005
Posts: 51

Rep: Reputation: 16
You probably won't get an answer from these guys so...I went ahead and wrote a script of my own since I needed one for myself:
Code:
#!/usr/bin/perl

use MP3::Tag;
use strict;

my @a = glob "*.mp3";
my @b = glob "*.MP3";
my @files = (@a, @b);

my $x;
foreach $x (@files)
{
  my $mp3 = MP3::Tag->new($x);
  my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
  print "$x\n";
  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");
}
Save as somefile.pl, chmod u+x somefile.pl, then ./somefile.pl in the directory containing your unsorted mp3's.
 
Old 10-02-2005, 03:18 AM   #7
destuxor
Member
 
Registered: Oct 2005
Posts: 51

Rep: Reputation: 16
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");
}
 
Old 10-10-2005, 08:50 AM   #8
CoolAJ86
Member
 
Registered: Jan 2004
Location: VT, USA
Distribution: Gentoo, Ubuntu - t3h 1337 & the easy, respectively
Posts: 125

Rep: Reputation: 15
Adding this to the gentoo wiki:
http://gentoo-wiki.com/index.php?tit..._digital_music

Last edited by CoolAJ86; 10-10-2005 at 05:51 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Program for ID3 Tags Boffy Linux - General 1 02-17-2005 02:16 PM
ID3 tags in Audacity/Suse ?? redrobin77 SUSE / openSUSE 1 11-30-2004 07:10 AM
Reading id3 tags from JuK in itunes samcs Linux - Software 2 09-24-2004 12:14 PM
Grip trunctuates ID3 tags GT_Onizuka Linux - Software 5 06-13-2004 10:18 AM
Accessing ID3 Tags oulevon Programming 2 11-15-2002 03:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration