10
10
DEF_CD_DEV = '/dev/cdrom'
14
# * --cdrom should take an argument, e.g. /dev/cdrom1. musicbrainz.queries
15
# doesn't seem to provide for this.
17
def get_toc_discid(mb):
18
mb.Query(mq.MBQ_GetCDTOC)
19
return mb.GetResultData(mq.MBE_TOCGetCDIndexId)
12
def get_toc_discid(mb, dev):
15
mb.Query(mq.MBQ_GetCDTOC)
16
return mb.GetResultData(mq.MBE_TOCGetCDIndexId)
17
except musicbrainz.MusicBrainzError:
18
print >>sys.stderr, "error: could not read TOC from disc"
21
21
def lookup_discid(mb, id):
22
22
mb.QueryWithArgs(mq.MBQ_GetCDInfoFromCDIndexId, [id])
24
if __name__ == "__main__":
26
longopts = ['cdrom', 'discid=']
31
opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
36
if opt in ('--cdrom', '-c'):
37
id = get_toc_discid(mb)
39
if opt in ('--discid', '-d'):
43
id = get_toc_discid(mb)
46
25
matches = mb.GetResultInt(mq.MBE_GetNumAlbums)
48
print >>sys.stderr, "could not find an entry for this CD"
27
print >>sys.stderr, "error: could not find an entry for this disc"
51
30
print >>sys.stderr, "warning: multiple matches, using first"
122
101
print "PLAYORDER="
104
if __name__ == "__main__":
106
longopts = ['no-lookup', 'device=', 'id=']
108
mb = musicbrainz.mb()
111
opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
116
for opt, arg in opts:
117
if opt in ('--no-lookup', '-n'):
119
if opt in ('--device', '-d'):
120
id = get_toc_discid(mb, arg)
121
if opt in ('--id', '-i'):
124
id = get_toc_discid(mb, DEF_CD_DEV)
127
lookup_discid(mb, id)