forked from tuffy/python-audio-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdinfo
executable file
·118 lines (91 loc) · 3.66 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
117
118
#!/usr/bin/python
#Audio Tools, a module and set of tools for manipulating audio data
#Copyright (C) 2007-2013 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__'):
import argparse
parser = argparse.ArgumentParser(description=_.DESCRIPTION_CDINFO)
parser.add_argument("--version",
action="version",
version="Python Audio Tools %s" % (audiotools.VERSION))
parser.add_argument("-c", "--cdrom",
dest="cdrom",
default=audiotools.DEFAULT_CDROM)
options = 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)
table = audiotools.output_table()
row = table.row()
row.add_column(_.LAB_TOTAL_TRACKS, "right")
row.add_column(u" : ")
row.add_column(unicode(len(cdda)))
row = table.row()
row.add_column(_.LAB_TOTAL_LENGTH, "right")
row.add_column(u" : ")
row.add_column(_.LAB_TRACK_LENGTH_FRAMES % (cdda.length() / 75 / 60,
cdda.length() / 75 % 60,
cdda.length()))
row = table.row()
row.add_column(_.LAB_FREEDB_ID, "right")
row.add_column(u" : ")
row.add_column(str(cdda.freedb_disc_id()).decode('ascii'))
row = table.row()
row.add_column(_.LAB_MUSICBRAINZ_ID, "right")
row.add_column(u" : ")
row.add_column(str(cdda.musicbrainz_disc_id()).decode('ascii'))
row = table.row()
row.add_column(_.LAB_ACCURATERIP_ID, "right")
row.add_column(u" : ")
row.add_column(str(cdda.accuraterip_disc_id()).decode('ascii'))
for row in table.format(sys.stdout.isatty()):
msg.output(row)
msg.output(u"")
table = audiotools.output_table()
row = table.row()
row.add_column(u"#")
row.add_column(u" ")
row.add_column(_.LAB_CDINFO_LENGTH)
row.add_column(u" ")
row.add_column(_.LAB_CDINFO_FRAMES)
row.add_column(u" ")
row.add_column(_.LAB_CDINFO_OFFSET)
row = table.divider_row([_.DIV, u" ", _.DIV, u" ", _.DIV, u" ", _.DIV])
for track in tracks:
row= table.row()
row.add_column(unicode(track.track_number), "right")
row.add_column(u" ")
row.add_column(
_.LAB_TRACK_LENGTH % (track.length() / 75 / 60,
track.length() / 75 % 60), "right")
row.add_column(u" ")
row.add_column(unicode(track.length()), "right")
row.add_column(u" ")
row.add_column(unicode(track.offset()), "right")
for row in table.format(sys.stdout.isatty()):
msg.output(row)
cdda.close()