3
# Copyright 2005 Decklin Foster, licensed under the same terms as abcde.
8
import musicbrainz.queries as mq
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)
21
def lookup_discid(mb, id):
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
matches = mb.GetResultInt(mq.MBE_GetNumAlbums)
48
print >>sys.stderr, "could not find an entry for this CD"
51
print >>sys.stderr, "warning: multiple matches, using first"
53
mb.Select1(mq.MBS_SelectAlbum, 1)
54
album = mb.GetResultData(mq.MBE_AlbumGetAlbumName)
55
n = mb.GetResultInt(mq.MBE_AlbumGetNumTracks)
57
artistid = mb.GetIDFromURL(mb.GetResultData(mq.MBE_AlbumGetAlbumArtistId))
58
if artistid == mq.MBI_VARIOUS_ARTIST_ID:
59
artist = 'Various Artists'
62
artist = mb.GetResultData1(mq.MBE_AlbumGetArtistName, 1)
63
except musicbrainz.MusicBrainzError:
64
artist = 'Unknown Artist'
67
tracks = map(int, args)
69
tracks = range(1, n+1)
73
if artistid == mq.MBI_VARIOUS_ARTIST_ID:
75
tartist = mb.GetResultData1(mq.MBE_AlbumGetArtistName, i)
76
except musicbrainz.MusicBrainzError:
77
tartist = 'Unknown Artist'
81
ttitle = mb.GetResultData1(mq.MBE_AlbumGetTrackName, i)
82
except musicbrainz.MusicBrainzError:
83
tartist = 'Unknown Track'
85
tlength = mb.GetResultInt1(mq.MBE_AlbumGetTrackDuration, i)
86
except musicbrainz.MusicBrainzError:
88
trackinfo.append((tartist, ttitle, tlength))
90
print "# fake CD database file generated by musicbrainz-get-tracks 0.1"
92
print "# Track frame offsets:"
94
# Assume standard pregap
97
tartist, ttitle, tlength = t
98
print "# %d" % (total_len / (1000.0/75.0))
102
print "# Disc length: %d seconds" % (total_len / 1000)
104
print "# Revision: 0"
105
print "# Processed by: MusicBrainz"
106
print "# Submitted by: MusicBrainz"
107
print "DISCID=%s" % id
108
print "DTITLE=%s / %s" % (artist, album)
110
for i in range(0, len(trackinfo)):
111
tartist, ttitle, tlength = trackinfo[i]
113
print "TTITLE%d=%s / %s" % (i, tartist, ttitle)
115
print "TTITLE%d=%s" % (i, ttitle)
119
for i in range(0, len(trackinfo)):