forked from tuffy/python-audio-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdinfo
executable file
·116 lines (92 loc) · 3.57 KB
/
cdinfo
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
#!/usr/bin/python
#Audio Tools, a module and set of tools for manipulating audio data
#Copyright (C) 2007-2012 Brian Langenberger
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os.path
import sys
import audiotools
import audiotools.text as _
if (__name__ == '__main__'):
parser = audiotools.OptionParser(
usage=_.USAGE_CDINFO,
version="Python Audio Tools %s" % (audiotools.VERSION))
parser.add_option('-c', '--cdrom', action='store',
type='string', dest='cdrom',
default=audiotools.DEFAULT_CDROM)
(options, args) = parser.parse_args()
msg = audiotools.Messenger("cd2info", options)
try:
cdda = audiotools.CDDA(options.cdrom, perform_logging=False)
except ValueError, err:
msg.error(unicode(err))
sys.exit(1)
if (len(cdda) == 255):
msg.error(_.ERR_NO_CDDA)
sys.exit(1)
elif (len(cdda) < 1):
msg.error(_.ERR_NO_EMPTY_CDDA)
sys.exit(1)
tracks = list(cdda)
msg.new_row()
msg.output_column(_.LAB_TOTAL_TRACKS, True)
msg.output_column(u" : ")
msg.output_column(unicode(len(cdda)))
msg.new_row()
msg.output_column(_.LAB_TOTAL_LENGTH, True)
msg.output_column(u" : ")
msg.output_column(
_.LAB_TRACK_LENGTH_FRAMES % (cdda.length() / 75 / 60,
cdda.length() / 75 % 60,
cdda.length()))
msg.new_row()
msg.output_column(_.LAB_FREEDB_ID, True)
msg.output_column(u" : ")
msg.output_column(str(cdda.freedb_disc_id()).decode('ascii'))
msg.new_row()
msg.output_column(_.LAB_MUSICBRAINZ_ID, True)
msg.output_column(u" : ")
msg.output_column(str(cdda.musicbrainz_disc_id()).decode('ascii'))
msg.blank_row()
msg.output_rows()
msg.new_row()
msg.output_column(u"#", True)
msg.output_column(u" ")
msg.output_column(_.LAB_CDINFO_LENGTH)
msg.output_column(u" ")
msg.output_column(_.LAB_CDINFO_FRAMES)
msg.output_column(u" ")
msg.output_column(_.LAB_CDINFO_OFFSET)
msg.new_row()
msg.output_column(u"--")
msg.output_column(u" ")
msg.output_column(
u"-" * len(audiotools.display_unicode(_.LAB_CDINFO_LENGTH)))
msg.output_column(u" ")
msg.output_column(
u"-" * len(audiotools.display_unicode(_.LAB_CDINFO_FRAMES)))
msg.output_column(u" ")
msg.output_column(
u"-" * len(audiotools.display_unicode(_.LAB_CDINFO_OFFSET)))
for track in tracks:
msg.new_row()
msg.output_column(unicode(track.track_number), True)
msg.output_column(u" ")
msg.output_column(
_.LAB_TRACK_LENGTH % (track.length() / 75 / 60,
track.length() / 75 % 60), True)
msg.output_column(u" ")
msg.output_column(unicode(track.length()))
msg.output_column(u" ")
msg.output_column(unicode(track.offset()))
msg.output_rows()
cdda.close()