1 ###########################################################################
2 # Copyright (C) 2008 by Andrew Mahone
3 # <andrew.mahone@gmail.com>
5 # Copyright: See COPYING file that comes with this distribution
7 ###########################################################################
14 from audiomangler
import scan
, Config
, util
, sync_sets
16 def parse_options(args
= None, options
= []):
17 if args
is None and len(sys
.argv
) == 1:
25 for (s_opt
, l_opt
, name
, desc
) in options
:
27 name_map
['-'+s_opt
.rstrip(':')] = name
30 name_map
['--'+l_opt
.rstrip('=')] = name
32 s_opts
= ''.join(s_opts
)
34 (opts
, args
) = getopt
.getopt(args
,s_opts
,l_opts
)
35 except getopt
.GetoptError
:
43 def print_usage(opts
):
45 %s [options] [files or directories to process]
47 options:""" % sys
.argv
[0]
48 for short
,long_
,name
,desc
in opts
:
49 print " -%s, --%-10s %s" %(short
.rstrip(':'),long_
.rstrip('='),desc
)
52 ('b:','base=','base','base directory for target files'),
53 ('f:','filename=','filename','format for target filenames'),
54 ('p:','profile=','profile','profile to load settings from'),
57 rename_opts
= common_opts
58 def rename(args
= None):
59 args
= parse_options(args
, rename_opts
)
60 (album_list
, dir_list
) = scan(args
)
61 for (dir_
,files
) in dir_list
.items():
62 print "from dir %s:" % dir_
69 print " skipping %s, already named correctly" % src
71 print " %s -> %s" % (src
, dst
)
72 dstdir
= os
.path
.split(dst
)[0]
73 if dstdir
not in dstdirs
and dstdir
!= dir_
:
77 if e
.errno
!= errno
.EEXIST
or not os
.path
.isdir(dstdir
):
82 dstdir
= dstdirs
.pop()
83 for file_
in os
.listdir(dir_
):
84 src
= os
.path
.join(dir_
,file_
)
85 dst
= os
.path
.join(dstdir
,file_
)
86 print " %s -> %s" % (src
,dst
)
88 while len(os
.listdir(dir_
)) == 0:
89 print " removing empty directory: %s" % dir_
94 newdir
= os
.path
.split(dir_
)[0]
100 sync_opts
= common_opts
+ (
101 ('t:','type=','type','type of audio to encode to'),
102 ('s:','preset=','preset','codec preset to use'),
103 ('e:','encopts=','encopts','encoder options to use'),
104 ('j:','jobs=','jobs','number of jobs to run'),
106 def sync(args
= None):
107 args
= parse_options(args
, sync_opts
)
108 (album_list
, dir_list
) = scan(args
)
109 sync_sets(album_list
.values())