-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreadcondep.py
132 lines (122 loc) · 4.92 KB
/
readcondep.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
#!/usr/bin/python
#===============================================================
# readcondep.py - A utility to inspect CartChunk'ed BWF files,
# such as those generated by the ContentDepot(TM) system.
# Uses the cdpfile.py library functions
# February 4, 2010
#
#===============================================================
#
#===============================================================
#License (see the MIT License)
#
#Copyright (c) 2010 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"
chunklist = ("cart", "bext", "mext", "fact", "fmt")
parser = OptionParser(usage="usage: %prog [options] wavefile")
parser.add_option("-v", "--ver", dest="show_version",
action="store_true", default=False,
help="show program version")
for chunkname in chunklist:
parser.add_option("--" + chunkname, action="store_true",
dest="show" + chunkname,
help="show the values stored in the {0} chunk".format(chunkname))
parser.add_option("-a", "--all", dest="show_all_chunks", action="store_true",
help="show info in all chunks", default=False)
parser.add_option("--save-cart", dest="cart_xml_filename",
help="save cart chunk data to FILE for transfer", metavar="FILE")
parser.add_option("-x", "--extract-mp2", dest="mp2filename",
help="extract MP2 audio to FILE", metavar="FILE")
parser.add_option("--tagtext-out", dest="tagtextoutfile",
help="export TagText value to FILE", metavar="FILE")
(options, args) = parser.parse_args()
def main():
if options.show_version:
print "Readcondep Version {0}/Core version {1}".format(program_version,
cdpwavefile_core_version)
if len(args) != 1:
sys.exit()
picked_at_least_one_option = False
if len(args) != 1:
parser.error("Input file not specified. Try {0} -h for detailed help."
.format(os.path.basename(sys.argv[0])))
MyCDPFile = CDPFile()
try:
foundchunks = MyCDPFile.ReadWaveFile(args[0])
foundchunks.remove('data')
if options.show_all_chunks:
for chunkname in foundchunks:
if hasattr(options, "show" + chunkname):
setattr(options, "show" + chunkname, True)
else:
print "Unknown chunk '{0}' found, skipping".format(
chunkname)
for chunkname in chunklist:
if ( getattr(options, "show" + chunkname) and
(chunkname not in foundchunks) ):
print "Chunk ID '{0}' not found".format(chunkname)
picked_at_least_one_option = True
for chunkname in foundchunks:
if hasattr(options, "show" + chunkname):
if getattr(options, "show" + chunkname):
print "--Contents of {0} chunk--".format(chunkname)
print str(getattr(MyCDPFile, chunkname))
picked_at_least_one_option = True
if options.tagtextoutfile is not None:
with open(options.tagtextoutfile, 'w') as f:
print "Saving TagText to {0}".format(
options.tagtextoutfile)
f.write(MyCDPFile.cart.tagtext)
picked_at_least_one_option = True
if options.mp2filename is not None:
print "Saving MP2 audio to {0}".format(
options.mp2filename)
MyCDPFile.ExportMpegFile(options.mp2filename)
picked_at_least_one_option = True
if options.cart_xml_filename is not None:
with open(options.cart_xml_filename, 'w') as x:
print "Saving cart chunk to {0}".format(
options.cart_xml_filename)
x.write(MyCDPFile.cart.ExportXMLValues())
picked_at_least_one_option = True
if not picked_at_least_one_option:
if "cart" in foundchunks:
chunkname = "cart"
print "--Contents of {0} chunk--".format(chunkname)
print str(getattr(MyCDPFile, chunkname))
else:
print "CartChunk data not found"
except IOError as inst:
print "An IO error occurred"
print inst
except Exception as inst:
print "An error occurred"
print inst
if __name__ == "__main__":
main()