#!/usr/bin/env python
import eyeD3, os, sys
default_subs = {
':': ' -',
}
bad_chars = ['?','/',':']
def clean(x, subs=default_subs, bad_chars=bad_chars):
for a,b in subs.iteritems():
x = x.replace(a,b)
for c in bad_chars:
x = x.replace(c,'')
return x
def do_rename_file(fname):
tag = eyeD3.Tag()
tag.link(fname)
name = []
num = tag.getTrackNum()[0]
if num:
name.append('%02d' % num)
name.append('-')
artist = tag.getArtist()
if artist:
name.append(clean(artist))
name.append('-')
title = tag.getTitle()
if title:
name.append(clean(title))
name = ''.join(name)
if not title:
print 'Not renaming %s - not enough tag data' % fname
return
name = name+'.mp3'
print 'Renaming "%s" to "%s": (OK,q,sub_name)' % (fname, name)
x=raw_input()
if len(x) > 2:
name = x
elif len(x) > 0:
print 'OK, skipping.'
return
os.rename(fname, name)
if __name__=='__main__':
for f in sys.argv[1:]:
do_rename_file(f)
You can modify the output format by... changing the code. But python is pretty readable.
No comments:
Post a Comment