View previous topic :: View next topic |
Author |
Message |
linux_girl Apprentice
Joined: 12 Sep 2003 Posts: 287
|
Posted: Sun Sep 24, 2006 4:49 pm Post subject: mp3clean sorting mp3 collection using MP3::Tag |
|
|
i had over 1000 of mp3 into the same dire . it would takes me a lot of time to sort and make dirs:
so i wrote a litle perl prog (my first perl use)
cat ~/bin/mp3clean
Code: |
# ULTRA EXPERIMENTAL CODE
# Use it at your own risk !!
use MP3::Tag;
use File::Copy;
#open file
$filename= $ARGV[0];
$mp3 = MP3::Tag->new($filename);
# get some information about the file in the easiest way
($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
$destination=$artist."/".$album ."/";
print "moving ".$filename. " TO ".$destination."\n";
#MAKING DIR
mkdir ($artist);
mkdir($artist."/".$album);
#moving files
move($filename,$destination);
#END
$mp3->close();
|
Then cd /path/to/mp3
Code: |
for i in *.mp3 ; do perl ~/bin/mp3clean "$i";done
|
well if mp3 have goods TAGS it should goes well _________________ |
|
Back to top |
|
|
iarwain Apprentice
Joined: 25 Sep 2003 Posts: 253
|
Posted: Sun Sep 24, 2006 5:42 pm Post subject: |
|
|
Nice script. What a casuality, I needed exactly this 1 week ago, and as after a quick search I didn't find one I decided to do it in bash (uses id3info):
Code: | #!/bin/bash
find -type f -print -name .mp3 | while read file
do
infoid3=$( id3info "$file" )
group=$( id3info "$file" | grep TPE1 | sed s%===\ TPE1\ \(Lead\ performer\(s\)\/Soloist\(s\)\)\:\ %% )
album=$( id3info "$file" | grep TALB | sed s%===\ TALB\ \(Album\/Movie\/Show\ title\)\:\ %% )
if [ -n "$group" ]; then
if [ ! -d "$group"/"$album" ]; then
mkdir -p "$group"/"$album"
fi
mv "$file" "$group"/"$album"
else
if [ ! -d unsorted ]; then mkdir unsorted; fi
mv "$file" unsorted
fi
done
|
|
|
Back to top |
|
|
linux_girl Apprentice
Joined: 12 Sep 2003 Posts: 287
|
Posted: Sun Sep 24, 2006 7:56 pm Post subject: |
|
|
be carful. if you have some mp3 from a Various artist CD. it often the case with OST-CD _________________ |
|
Back to top |
|
|
TPC Tux's lil' helper
Joined: 16 Sep 2003 Posts: 135 Location: Sweden
|
Posted: Tue Sep 26, 2006 11:27 am Post subject: |
|
|
Nice idea, I made an improved version of your script.
Paste the script into /usr/local/bin/mp3sort and then chmod 755 it.
This version loops trought all filenames on the command-line, so any of the following will work:
mp3sort file1.mp3
mp3sort file1.mp3 file2.mp3 file3.mp3
mp3sort *.mp3
It also does some more advanced checking to determine the best path and filename,
based on the tags that are there. So this one should work fine even if the tags are not complete.
It will also never overwrite another file with the same name, so don't worry about data loss.
Enjoy.
Code: |
#!/usr/bin/perl
use MP3::Tag;
use warnings;
use strict;
foreach my $filename (@ARGV) {
# get file info
my $mp3 = MP3::Tag->new($filename);
my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
$mp3->close();
# 01 02 03 etc looks nicer than 1 2 3 etc in filenames
$track = "0$track" if $track and $track > 0 and $track < 9;
# replace / with - since / is forbidden in unix filenames
$album =~ s|/|-|;
$artist =~ s|/|-|;
$title =~ s|/|-|;
# determine destination path
# set it to unknown if tag doesn't exist
my $destpath;
$destpath .= "unknown artist/" unless $artist;
$destpath .= "$artist/" if $artist;
$destpath .= "unknown album/" unless $album;
$destpath .= "$album ($year)/" if $album and $year;
$destpath .= "$album/" if $album and not $year;
# determine destination filename
# make sure to generate a unique filename if a title doesn't exist
my $destfilename;
$destfilename .= "$track - " if $track;
$destfilename .= "$title" if $title;
$destfilename .= "unknown " . int(rand(10)) . int(rand(10)) . int(rand(10)) . int(rand(10)) unless $title;
$destfilename .= ".mp3";
# create file path
`mkdir -p -- \"$destpath\"`;
# rename file
# use mv -i to make sure that we don't overwrite anything important
print "mv -i \"$filename\" \"$destpath$destfilename\"\n";
`mv -i -- \"$filename\" \"$destpath$destfilename\"`;
}
|
|
|
Back to top |
|
|
fank l33t
Joined: 16 Oct 2004 Posts: 794 Location: Minsk, Belarus
|
Posted: Wed Sep 27, 2006 1:23 pm Post subject: |
|
|
is it possible to fetch lyrics and/or covers and store it locally like amarok does? |
|
Back to top |
|
|
linux_girl Apprentice
Joined: 12 Sep 2003 Posts: 287
|
Posted: Wed Sep 27, 2006 5:17 pm Post subject: |
|
|
very nice. there is so many rooms for improvement.
- like "tags that have same artist name in case Sensitive way." ie: Green Day=GREEN DAY=...
- replacing duplicates files by others that have a biger bitrates
- bogus tags like artistname set to somes digits
- VARIOUS ARTIST CD : avoid making many artists dirs as there is tracks. The albums is the same and should be in one dire
As far s know you can use "amazon ECS" and/or amazon web service "aws" to fetch trought HTPP request and XML for content like reviews / covers / prices ans so on.
i am also planing to make a script that will handles multi-parts rar files that are in the same dir. Recover damaged parts using par2 recovry info and unrar archive and del archive.
if only i had more time but i had to work to pay my studies _________________ |
|
Back to top |
|
|
|