-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakecondep.py
151 lines (145 loc) · 5.94 KB
/
makecondep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/python
#===============================================================
# makecondep.py - A utility to wrap an MP2 audio file with
# RIFF WAVE chunks using CartChunk and BWF chunks, generating
# a WAVE file similar to those used by ContentDepot(TM)
# Uses the cdpfile.py library functions
# February 4, 2010
#
#===============================================================
#
#===============================================================
#License (see the MIT License)
#
#Copyright (c) 2009 John McMellen
#
#Permission is hereby granted, free of charge, to any person
#obtaining a copy of this software and associated documentation
#files (the "Software"), to deal in the Software without
#restriction, including without limitation the rights to use,
#copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the
#Software is furnished to do so, subject to the following
#conditions:
#
#The above copyright notice and this permission notice shall be
#included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
#OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
#OTHER DEALINGS IN THE SOFTWARE.
#
#=================================================================
from cdpwavefile import *
from optparse import OptionParser
import sys
program_version = "1.4"
parser = OptionParser(usage="usage: %prog [options] PCM/MP2inputfile wrappedoutputfile")
parser.add_option("-v", "--ver", dest="show_version",
action="store_true", default=False,
help="show program version")
parser.add_option("-t", "--title", dest="title",
help="set CartChunk Title to TITLE")
parser.add_option("-a", "--artist", dest="artist",
help="set CartChunk Artist to ARTIST")
parser.add_option("-c", "--cutnum", dest="cutnum",
help="set CartChunk Cutnum to CUTNUM")
parser.add_option("-q", "--outcue", dest="outcue",
help="set CartChunk Outcue to OUTCUE")
parser.add_option("--startdate", dest="startdate",
help="set CartChunk StartDate to YYYY/MM/DD")
parser.add_option("--starttime", dest="starttime",
help="set CartChunk StartTime to 24 hour HH:MM:SS")
parser.add_option("--enddate", dest="enddate",
help="set CartChunk EndDate to YYYY/MM/DD")
parser.add_option("--endtime", dest="endtime",
help="set CartChunk EndTime to 24 hour HH:MM:SS")
parser.add_option("--category", dest="category",
help="set CartChunk Category to CATEGORY")
parser.add_option("--classification", dest="classification",
help="set CartChunk Classification to CLASSIFICATION")
parser.add_option("--appid", dest="appid", default="PythonUtil",
help="set CartChunk AppID to APPID, default value is PythonUtil")
parser.add_option("--appver", dest="appver", default=program_version,
help="set CartChunk AppVersion to APPVER, default value is" \
" {0}".format(program_version))
parser.add_option("--url", dest="url",
help="set CartChunk URL field to URL")
parser.add_option("--tagtext-in", dest="tagtextinfile",
help="import TagText value from FILE", metavar="FILE")
parser.add_option("--restore-cart", dest="cart_xml_filename",
help="restore cart chunk info (minus TagText) from FILE",
metavar="FILE")
(options, args) = parser.parse_args()
def main():
if options.show_version:
print "Makecondep Version {0}/Core version {1}".format(program_version,
cdpwavefile_core_version)
if len(args) != 2:
sys.exit()
if len(args) != 2:
parser.error("Input or output file not specified. "
"Try {0} -h for detailed help."
.format(os.path.basename(sys.argv[0])))
inputfile = args[0]
outputfile = args[1]
MyCDPFile = CDPFile()
MyCDPFile.cart.tagtext = ""
try:
if re.match(r'.*\.mp2$', inputfile, re.I) is not None:
MyCDPFile.ImportMpegFile(inputfile)
elif re.match(r'.*\.wav$', inputfile, re.I) is not None:
MyCDPFile.ReadWaveFile(inputfile)
else:
raise Exception("Unrecognized filename extension on file: {0}".format(
inputfile))
if options.cart_xml_filename is not None:
with open(options.cart_xml_filename, 'r') as x:
print "Restoring CartChunk values from {0}".format(
options.cart_xml_filename)
MyCDPFile.cart.ImportXMLValues(x.read())
options.appid = None
options.appver = None
for option, value in options.__dict__.iteritems():
if value is not None:
try:
getattr(MyCDPFile.cart, option)
setattr(MyCDPFile.cart, option, value)
print "Setting '{0}' to '{1}'".format(option, value)
except AttributeError:
pass
if options.tagtextinfile is not None:
with open(options.tagtextinfile, 'r') as f:
print "Imported TagText from {0}".format(options.tagtextinfile)
MyCDPFile.cart.tagtext = f.read()
#print MyCDPFile
if MyCDPFile.fmt.compressioncode == 80:
MyCDPFile.WriteCompressedWaveFile(outputfile)
elif MyCDPFile.fmt.compressioncode == 1:
MyCDPFile.WritePCMWaveFile(outputfile)
else:
raise Exception("Incompatible input file type: {0}".format(
inputfile))
except InvalidMPEGDataError as inst:
print "There was a problem with the MPEG data. " \
"Are you sure it is a valid MP2 audio file with no ID3 tags?"
print "Error: {0}".format(inst)
except IOError as inst:
print "An IO error occurred"
print inst
except ValueError as inst:
print "Unable to set an attribute value. " \
"Are you sure you entered dates and times in the right format?"
print "Error: {0}".format(inst)
except Exception as inst:
print "An undefined error occurred"
print type(inst)
print inst.args
print inst
if __name__ == "__main__":
main()