예제 #1
0
    name = unabridged.sub("",name)
    name = selections.sub("",name)
    name = name.split(":")[0].strip()   # Treat everything after the colon as a subtitle
    name = notallowed.sub("",name)
    name = name.rstrip(".")             # In FAT-32 if you do "md mydir..." it actually creates mydir which means that the name we asked for isn't there when we need it
    
    name = fndelim.join(name.split())
    return name.encode("latin-1")

for dirpath, dirs, files in os.walk(root):
    for name in files:
        if not name.endswith(".aa"):
            continue
        oldname = os.path.join(dirpath,name)
        try:
            aa = aafile(oldname)
        except IOError, details:
            print "Skipping %s. Could not process tags in the header because the file appears to be corrupt:\n%s" % (oldname, details)
            errors += 1
            continue
        author = good_filename(aa.author[0])
        title  = good_filename(aa.parent_title)
        newname = os.path.join(root,author,title,name)
        if os.path.normpath(os.path.normcase(oldname)) == os.path.normpath(os.path.normcase(newname)):
            continue
        try:
            os.renames(oldname, newname)
        except OSError, details:
            print "Skipping %s. Could not rename to %s because the operating system reported the following problem:\n%s" % (oldname, newname, details)
            errors += 1
            continue
예제 #2
0
# $Id$
#Sample usage:
import os.path
from pyaudibletags import aafile
for root, dirs, files in os.walk(r"F:\Documents\Audio Books\Kay Kenyon\The Entire and the Rose"):
    for name in files:
        if not name.endswith(".aa"):
            continue
        fullname = os.path.join(root,name)
        aa = aafile(fullname)
        print name
        for d in (aa.tags(),):
            for k,v in d.items():
                print "%-32s%r" % (k, v)