View previous topic :: View next topic |
Author |
Message |
viduka_kewell n00b
Joined: 13 Sep 2003 Posts: 3
|
Posted: Sat Sep 13, 2003 3:16 am Post subject: Mp3 folder renaming script??? |
|
|
Has anyone got a quick an easy way to rename mp3 folders from:
Artist - Album\TrackNo - Track Name
to:
Artist\Album\TrackNo - Track Name
I know it's probably extremely easy, but scripting is definitely not one of my strong points. Thx!!!! |
|
Back to top |
|
|
Z? Tux's lil' helper
Joined: 22 Jan 2003 Posts: 118 Location: Waterloo, Ontario, Canada
|
Posted: Sat Sep 13, 2003 5:25 am Post subject: |
|
|
Try EasyTag:
Code: | [ Results for search key : easytag ]
[ Applications found : 1 ]
* media-sound/easytag
Latest version available: 0.28
Latest version installed: 0.28
Size of downloaded files: 1,065 kB
Homepage: http://easytag.sourceforge.net/
Description: EasyTAG mp3/ogg ID3 tag editor |
|
|
Back to top |
|
|
viduka_kewell n00b
Joined: 13 Sep 2003 Posts: 3
|
Posted: Sat Sep 13, 2003 9:04 am Post subject: |
|
|
Nice program (will now be my default renamer), but it doesn't quite achieve the folder renaming scenario. I found this in the mailing list:
Quote: |
Beto Reyes wrote:
> Is there a way to rename a file and create a directory with the name artist
> (or any field) in the process?
>
At the present time, you can't do it. Only is supported renaming file
from the tag, but it's a already a requested feature. |
The search continues. |
|
Back to top |
|
|
dweimer n00b
Joined: 31 Aug 2003 Posts: 40
|
Posted: Sat Sep 13, 2003 11:17 am Post subject: Re: mp3 move script |
|
|
Here's a perl script that I believe does what you want. I commented out the actual mkdir and move commands so you can run it and make sure the printed functions are correct. If they are what you want just remove the # before the mkdir and system lines. Code: | #!/usr/bin/perl -w
my $basedir=".";
my ($origdir, @files);
opendir(DIRLIST, $basedir) || die "Could not open directory: $basedir: $!";
my @origdirs = map { (/^[^.]/ && -d "$basedir/$_")?$_:() } readdir(DIRLIST);
foreach (@origdirs)
{
print "For $basedir/$_\n";
$_ =~ /(.*?)\s-\s(.*)/;
print "Make $basedir/$1/$2\n";
# mkdir "$basedir/$1" || die "Could not make directory: $!";
# mkdir "$basedir/$1/$2" || die "Could not make directory: $!";
print "Moving files from $basedir/$_/* to $basedir/$1/$2\n\n";
# system("mv \"$basedir/$_\"/* \"$basedir/$1/$2\"");
}
close DIRLIST;
| You should set $basedir to the directory that contains the "Artist - Album" directories. Here is some sample output from a test I ran: Quote: | For ./Artist One - Album 1
Make ./Artist One/Album 1
Moving files from ./Artist One - Album 1/* to ./Artist One/Album 1
For ./Artist One - Album 2
Make ./Artist One/Album 2
Moving files from ./Artist One - Album 2/* to ./Artist One/Album 2
For ./Artist One - Album 3
Make ./Artist One/Album 3
Moving files from ./Artist One - Album 3/* to ./Artist One/Album 3
For ./Artist One - Album 4
Make ./Artist One/Album 4
Moving files from ./Artist One - Album 4/* to ./Artist One/Album 4
For ./Artist One - Album 5
Make ./Artist One/Album 5
Moving files from ./Artist One - Album 5/* to ./Artist One/Album 5
For ./Artist One - Album 6
Make ./Artist One/Album 6
Moving files from ./Artist One - Album 6/* to ./Artist One/Album 6
For ./Artist 2 - Album Seven
Make ./Artist 2/Album Seven
Moving files from ./Artist 2 - Album Seven/* to ./Artist 2/Album Seven
|
Hopefully this is what you were looking for,
Doug
PS: You may want to back up the directory tree before running the scipt with the mkdir and system lines uncommented. It's much better to be safe than run into a problem when it's too late to fix. |
|
Back to top |
|
|
viduka_kewell n00b
Joined: 13 Sep 2003 Posts: 3
|
Posted: Tue Sep 23, 2003 9:20 am Post subject: |
|
|
Cool thanks for that, I'll try it when I get home!! |
|
Back to top |
|
|
woodwizzle Apprentice
Joined: 30 Nov 2003 Posts: 225
|
Posted: Wed Apr 21, 2004 6:12 am Post subject: |
|
|
Sorry for the old thread bump. But this was a problem I was having too. I don't know why easytag doesn't support this feature. In any case. I've written a python script which does this dynamically and can use any portion of the ID3 tag when naming files. Don't forget to change the base directory.
Code: | #!/usr/bin/python
import sys,os,os.path,string
from output import *
from ID3 import *
# Defaults
formatString = "%b/%a/%d/%n-%t.mp3"
baseDir = "/mnt/media/Music/Testing"
strings = {};
strings['b'] = baseDir
# Mode Variables
organise = 0
strip = 0
look = 0
def help():
print "Usage:"
print " mp3tool [ options ] [ files... ]"
print "Options: -[ocslf=[format string]]"
print " --format=[format string] (-f=[format string] short option)"
print " If this option is not used the format string defaults to %s" % formatString
print " These variables may be used in the format string:"
print " Base Directory %%b (defaults to %s)" % baseDir
print " Title %t"
print " Artist %a"
print " Album %d"
print " Tracknumber %n"
print " Genre %g"
print " Year %y"
print " Comment %c"
print " NOTES: No white space is allowed in the format string!"
print " Don't forget the .mp3 extension! It is not automatically added."
print " --organise (-o short option)"
print " Organise and rename files into directories using the format string."
print " --strip (-s short option)"
print " Strip a file of its ID3 tag."
print " --look (-l short option)"
print " Display a file's ID3 tag."
def convertFormat(fstring):
pos = 0
for letter in fstring:
if letter == '%':
fstring = fstring[:pos+1] + '(' + fstring [pos+1] + ')s' + fstring [pos+2:]
pos = pos + 3
pos = pos + 1
return fstring
mp3files=[]
if len(sys.argv)>1:
x=1
while x < len(sys.argv):
if sys.argv[x][0:9] == "--format=" or sys.argv[x][0:3] == "-f=":
if sys.argv[x][0:9] == "--format=":
formatString = sys.argv[x][9:]
elif sys.argv[x][0:3] == "-f=":
formatString = sys.argv[x][3:]
print green("Format String set to: %s" % formatString)
elif sys.argv[x] == "--organise" or sys.argv[x] == "-o":
organise = 1
elif sys.argv[x] == "--strip" or sys.argv[x] == "-s":
strip = 1
elif sys.argv[x] == "--look" or sys.argv[x] == "-l":
look = 1
elif sys.argv[x] == "--help" or sys.argv[x] == "-h" or sys.argv[x] == "-?":
help()
sys.exit(1)
elif os.path.isdir(sys.argv[x]):
for y in os.listdir(os.path.abspath(sys.argv[x])):
if string.split(y,".")[-1] == "mp3":
mp3files.append(y)
elif os.path.isfile(sys.argv[x]):
if string.split(sys.argv[x],".")[-1] == "mp3":
mp3files.append(sys.argv[x])
else:
print red("Argument: \"%s\" is neither valid option or a valid mp3 file" % sys.argv[x])
sys.exit(1)
x+=1
else:
help()
sys.exit(2)
for x in mp3files:
# retrieve ID3 tag information
id3info = ID3(x)
try: strings['t'] = id3info['TITLE']
except KeyError:
print red("Failed to retrieve title of %s" % x)
continue
try: strings['a'] = id3info['ARTIST']
except KeyError:
print red("Failed to retrieve artist of %s" % x)
continue
try: strings['d'] = id3info['ALBUM']
except KeyError:
print red("Failed to retrieve album of %s" % x)
continue
try: strings['y'] = id3info['YEAR']
except KeyError:
print red("Failed to retrieve year of %s" % x)
continue
try: strings['c'] = id3info['COMMENT']
except KeyError:
print red("Failed to retrieve comment of %s" % x)
continue
try: strings['g'] = id3info['GENRE']
except KeyError:
print red("Failed to retrieve genre of %s" % x)
continue
try: strings['n'] = id3info['TRACKNUMBER']
except KeyError:
print red("Failed to retrieve tracknumber of %s" % x)
continue
if organise:
try:
newPath = convertFormat(formatString) % strings
os.renames(x, newPath)
print green("Renamed %s to %s" % (x, newPath))
except KeyError:
print red("Failed to rename %s" % x)
if strip:
id3info.delete()
print green("ID3 tag stripped from %s" % x)
if look:
print "%s\n" % id3info
|
|
|
Back to top |
|
|
dsd Developer
Joined: 30 Mar 2003 Posts: 2162 Location: nr London
|
Posted: Wed Apr 21, 2004 10:25 pm Post subject: |
|
|
woodwizzle wrote: | Sorry for the old thread bump. But this was a problem I was having too. I don't know why easytag doesn't support this feature. |
easytag does do this, see the "rename file" scanner.
as pointed out in this thread, easytag does lack the ability to automatically rename _directories_ but not files. _________________ http://dev.gentoo.org/~dsd |
|
Back to top |
|
|
woodwizzle Apprentice
Joined: 30 Nov 2003 Posts: 225
|
Posted: Sat Apr 24, 2004 9:41 am Post subject: |
|
|
I'm aware of the rename scanner in easytag. I'm also aware that it doesn't rename or work with directories at all. My script can handle directories and thats why I wrote it. |
|
Back to top |
|
|
jonny5 n00b
Joined: 01 May 2002 Posts: 18 Location: USA
|
Posted: Fri Apr 30, 2004 6:01 pm Post subject: |
|
|
Just wanted to say thanks to everyone that made fixing my mp3 library a breeze. You guys are awesome.
_________________ Jonny5
Dell Optiplex GX260
Love-Sources 2.6.5-love5
nova-labs
mid-west massive
^_^ |
|
Back to top |
|
|
|