5 from optparse
import OptionParser
6 from tag_wrapper
import tag
8 ACCEPTEXTS
= [".ogg"] # Keep it simple for now
10 def issupportedfile(name
):
11 for ext
in ACCEPTEXTS
:
12 if os
.path
.splitext(name
)[1] == ext
:
16 def newpath(file, target
, pattern
):
17 # Create the tokens dictionary
20 # TODO: add tracknumber, disknumber and possibily compilation
21 for t
in ["title", "artist", "album artist", "album", "composer", "genre", "date"]:
26 # %album artist% is %artist% if nothing can be found in the tags
27 if tokens
["album artist"] == None:
28 tokens
["album artist"] = tokens
["artist"]
30 # That appears in no tag
31 tokens
["base"] = target
35 usage
= "Usage: %prog [options] directory pattern"
36 parser
= OptionParser(usage
=usage
)
37 parser
.add_option("-r", "--recursive", action
="store_true",
38 dest
="recursive", help="also move/copy files from sub-directories", default
=False)
39 parser
.add_option("-t", "--target", dest
="target",
40 help="create new directory structure in directory TARGET (default=directory)")
41 (options
, args
) = parser
.parse_args()
46 print "You must specify a directory"
52 print "You must specify a pattern"
55 if options
.target
!= None:
56 target
= options
.target
62 files
= basepath
.walkfiles()
64 files
= basepath
.files()
66 if issupportedfile(file):
68 print newpath(file, target
, pattern
)
70 if __name__
== "__main__":