[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



>I have made the decision to convert my huge CD collection to MP3 now
>that I have a DVD burner.  My CD's take up too much room and I can just
>store them in my attic.  I normally use mp3c but I would still like to
>use it but in script form to create a structure like this on disk:
>
><genre>/<artist>/<album>/<mp3>
>
>Has anyone written scripts that can do this?  
>

The attached perl script is a quick hack I did in December to organize 
my collection in three different ways: ByAlbum/abum/song.mp3, 
ByArtist/artist/album/song.mp3, ByGenre/genre/artist/album/song.mp3. cd 
to the top of a directory full of mp3s and let it go to work. It tries 
to be clever with symlinks and doesn't always get things right but, hey, 
it *is* a quick hack :-)

>Maybe even a perl script
>that can read the information from the mp3 file and place it in those
>directores.  Maybe even outmut a 
>
>_______________________________________________
>Ale mailing list
>Ale at ale.org
&gt;<a  rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale";>http://www.ale.org/mailman/listinfo/ale</a>
&gt;  
&gt;

-------------- next part --------------
#!/usr/bin/perl

# jcej - 12/2003
# A quick script to organize a set of MP3s
# into directories ByArtist, ByAlbum, ByGenre

use File::Basename;
use File::Find;
use File::Path;
use Getopt::Std;
use MP3::Tag;

# Additional genre's not known by MP3::Tag
my $gl = { 141 =&gt; &quot;Christian Rock&quot;
         };

my %cl = ();
getopts(&quot;Vvg&quot;, \%cl);

if($cl{g}) {
  my $genres = MP3::Tag-&gt;genres;
  print join(&quot;, &quot;, sort @$genres) . &quot;\n&quot;;
  exit 0;
}

foreach my $catalog (&quot;ByArtist&quot;, &quot;ByAlbum&quot;, &quot;ByGenre&quot;) {
  mkpath($catalog, 1, 0755);
}

my $options =
  {
   wanted =&gt; \&amp;catalog,
   no_chdir =&gt; 1,
  };
find($options, @ARGV);

sub catalog {
  my $file = $File::Find::name;
  return if( ! -f $file || -l $file || $file !~ m/\.mp3$/ );
  print &quot;$file\n&quot; if($cl{v} || $cl{V});

  my $mp3 = MP3::Tag::-&gt;new($file);
  return if( ! $mp3 );

  my ($song, $track, $artist, $album) = $mp3-&gt;autoinfo();

  if($cl{V}) {
    my @tags = $mp3-&gt;get_tags;
    foreach my $tagType (@tags) {
      my $tag = $mp3-&gt;{$tagType};
      while ( my ($key, $value) = each %$tag) {
        print &quot;$tagType\t$key\t$value\n&quot;;
      }
    }
  }

  my $genre = $mp3-&gt;{ID3V1}-&gt;{genre};
  if($genre eq '') {
    my $genreID = $mp3-&gt;{ID3v1}-&gt;{genreID};
    $genre = $mp3-&gt;genres($genreID);
    if($genre eq '') {
      $genre = $gl-&gt;{$genreID};
    }
    if($genre eq '' || ref($genre)) {
      $genre = 'UNKNOWN';
    }
  }

  my $byAlbum  = &quot;$album/$song&quot; . &quot;\.mp3&quot;;
  my $byArtist = &quot;$artist/$byAlbum&quot;;
  my $byGenre  = &quot;$genre/$byArtist&quot;;

  makeLink($file, &quot;ByArtist/$byArtist&quot;);
  makeLink($file, &quot;ByAlbum/$byAlbum&quot;);
  makeLink($file, &quot;ByGenre/$byGenre&quot;);
}

sub makeLink {
  my($from, $to) = @_;
  my $dir = dirname($to);
  mkpath($dir, 1, 0755);
  my $prefix = calculatePrefix($to);
  symlink($prefix . $from, $to);
}

sub calculatePrefix {
  my $file = shift;
  my $pfx = &quot;&quot;;
  while(($file = dirname($file)) ne '.') {
    $pfx .= &quot;../&quot;;
  }
  return $pfx;
}


</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00617" href="msg00617.html">[ale] Ripping CD's</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Chris Fowler)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00962.html">[ale] [OT] securing sensitive data</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00964.html">[ale] Nokia 3589i DKU-5 Data Cable</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00644.html">[ale] Ripping CD's</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00625.html">[ale] whois question</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00963"><strong>Date</strong></a></li>
<li><a href="threads.html#00963"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>