2 # Copyright (c) 2007 Jesus Climent <jesus.climent@hispalinux.es>
3 # This code is hereby licensed for public consumption under either the
4 # GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.
6 # You should have received a copy of the GNU General Public License along
7 # with this program; if not, write to the Free Software Foundation, Inc.,
8 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10 # $Id: abcde 232 2007-03-22 21:39:30Z data $
12 # import those needed modules.
22 __version__
= "1.0-$Revision$"
25 abcde.py - A Better CD Encoder - python release
26 Copyright (C) 2007 Jesus Climent <jesus.climent@hispalinux.es>
30 help = """This is abcde version """ + __version__
+ """
32 usage: abcde.py [options] [tracks]
34 -1 Encode the whole CD in a single file
35 -a <action1[,action2]...>
37 cddb,read,normalize,encode,tag,move,replaygain,playlist,clean
38 -b Enable batch normalization
40 Specify a configuration file (overrides system and user config files)
42 Specify discid to resume from (only needed if you no longer have the cd)
44 Specify CDROM device to grab (flac uses a single-track flac file)
45 -D Debugging mode (equivalent to sh -x abcde)
46 -e Erase encoded track information from status file
47 -f Force operations that otherwise are considered harmful. Read "man abcde"
48 -g Use "lame --nogap" for MP3 encoding. Disables low disk and pipes flags
49 -h This help information
50 #-i Tag files while encoding, when possible (local only) -NWY-
51 -j <#> Number of encoder processes to run at once (localhost)
52 -k Keep the wav tracks for later use
53 -l Use low disk space algorithm
54 -L Use local CDDB storage directory
55 -n No lookup. Don't query CDDB, just create and use template
56 -N Noninteractive. Never prompt for anything
57 -m Modify playlist to include CRLF endings, to comply with some players
58 WARNING: Deprecated. Use \"cue\" action
60 Output file type(s) (vorbis,mp3,flac,spx,mpc,wav,m4a). Defaults to vorbis
61 -p Pad track numbers with 0's (if less than 10 tracks)
62 -P Use UNIX pipes to read+encode without wav files
64 Set quality level (high,medium,low)
66 Also encode on these remote hosts
67 -R Use local CDDB in recursive mode
69 Show dielfs from the CDDB info (year,genre)
70 -S <#> Set the CD speed
71 -t <#> Start the track numbering at a given number
72 -T <#> Same as -t but modifies tag numbering
73 -U Do NOT use UNICODE (UTF8) tags and comments
74 -v Show version number and exit
75 -V Be a bit more verbose about what is happening behind the scenes
76 -x Eject CD after all tracks are read
78 Add a comment to the CD tracks
79 -W <#> Contatenate CDs: -T #01 -w "CD #"
80 -z Use debug CDROMREADERSYNTAX option (needs cdparanoia)
82 Tracks is a space-delimited list of tracks to grab.
83 Ranges specified with hyphens are allowed (i.e., 1-5).
90 def addstatus(status
,file):
92 file = open(file, "w")
94 log("error","file",file,"cannot be read")
97 def log(status
,logstring
):
98 if re
.compile("info").match(status
):
101 elif re
.compile("warning").match(status
):
104 elif re
.compile("error").match(status
):
106 status
= "[ERROR] %s\n"
107 sys
.stderr
.write(status
% logstring
)
112 def f_seq_row (min,max):
117 log(error
,"syntax error while processing track numbers")
120 def f_seq_line (min,max):
125 log(error
,"syntax error while processing track numbers")
130 # get_first and get_last can be substituted by range[0] and range[:-1]
132 # checkstatus(string)
133 # Returns "0" if the string was found, returns 1 if it wasn't
134 # Puts the blurb content, if available, on stdout.
135 # Otherwise, returns "".
136 def checkstatus (string
, file):
138 patern
= re
.compile("^"+string
+"(=.*)?$")
141 file = open(file, "r")
143 log("error","file "+file+" cannot be read")
148 line
= file.readline()
150 blurb
.append(re
.search(patern
,line
).string
)
159 # checks where we can find a program in the path
161 for path
in string
.split(os
.environ
["PATH"], ":"):
162 if os
.path
.exists(os
.path
.join(path
, program
)):
163 return os
.path
.join(path
, program
)
169 opts
, args
= getopt
.getopt(sys
.argv
[1:], "1a:bc:C:d:DefghjklLnNmopPqrRsStTUvVxwWz")
171 log("error","unknown error")
172 sys
.stderr
.write(usage
% sys
.argv
[0])
177 for opt
, optarg
in opts
:
179 if opt
== "-1": o_onetrack
= "y"
180 if opt
== "-a": o_actions
= optarg
181 if opt
== "-b": o_batchnormalize
= "y"
182 if opt
== "-B": o_nobatchreplygain
= "y"
184 o_configfile
= str(optarg
)
186 if not re
.compile("\.\/").search(o_configfile
):
187 o_configfile
= os
.environ
.get("PWD", "./") + "/" + o_configfile
188 os
.path
.exists(o_configfile
)
190 log("error",o_configfile
+" cannot be read")
192 if re
.compile("abcde\.").match(optarg
):
195 o_discid
= "abcde." + optarg
196 if opt
== "-d": o_cdrom
= optarg
197 if opt
== "-D": o_debug
= "y"
201 if opt
== "-e": o_eraseencodedstatus
= "y"
202 # if opt == "-E": o_encoding
203 if opt
== "-f": o_force
= "y"
204 if opt
== "-g": o_nogap
= "y"
205 if opt
== "-j": o_maxprocs
= optarg
206 if opt
== "-k": o_keepwavs
= "y"
207 if opt
== "-l": o_lowdisk
= "y"
208 if opt
== "-L": o_localcddb
= "y"
209 if opt
== "-n": o_cddbavailable
= "n"
210 if opt
== "-m": o_dosplaylist
= "y"
211 if opt
== "-M": o_docue
= "y"
212 if opt
== "-N": o_interactive
= "n"
213 if opt
== "-o": o_outputtypes
= optarg
214 if opt
== "-p": o_padtracks
= "y"
215 if opt
== "-P": o_usepipes
= "y"
216 if opt
== "-q": o_qualitylevel
= optarg
217 #if opt == "-r": o_remotehosts = optarg
218 if opt
== "-R": o_localcddbrecursive
= "y"
219 if opt
== "-s": o_showcddbfields
= "y"
220 if opt
== "-S": o_cdspeed
= optarg
221 if opt
== "-t": o_starttracknumber
= optarg
223 o_starttracknumber
= optarg
224 o_starttracknumbertag
= "y"
225 if opt
== "-U": o_cddbproto
= 5
227 print "This is abcde v", __version__
228 print "Usage: abcde.py [options] [tracks]"
229 print "abcde -h for extra help"
231 if opt
== "-V": o_verbose
= "y"
232 if opt
== "-x": o_eject
= "y"
233 # if opt == "-X": o_cue2discid = optarg
234 if opt
== "-w": o_comment
= optarg
236 if re
.compile("^\d+$").search(optarg
)
237 o_starttracknumber
= optarg
+ "01"
238 o_starttracknumbertag
= "y"
239 o_comment
= "CD" + optarg
241 log("error","opt -W must be an integer")
245 #log("error","arguments were not correct")
250 ## checkstatus("test", "/tmp/status")
255 # -------------------------------
256 if __name__
== "__main__": main()