本文整理汇总了Python中CDDB.query方法的典型用法代码示例。如果您正苦于以下问题:Python CDDB.query方法的具体用法?Python CDDB.query怎么用?Python CDDB.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDDB
的用法示例。
在下文中一共展示了CDDB.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def __init__(self):
cdaudio = DiscID.open()
print "CD: ", cdaudio
try:
self.disc_id = DiscID.disc_id(cdaudio)
print "disc_id: ", self.disc_id
self.is_audio_cd = True
except:
print "No CD"
disc_id = None
self.is_audio_cd = False
self.song_list = []
cdaudio.close()
raise
if self.is_audio_cd:
try:
self.query_status, self.query_info = CDDB.query(self.disc_id)
print "query_status: ", self.query_status
print "query_info: ", self.query_info
except:
print 'IOError'
self.song_list = []
cdaudio.close()
self.query_status = 409
self.query_info = {"disc_id": "", "category": "", "title":""}
pass
示例2: get_cddb
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def get_cddb(self):
try:
import CDDB, DiscID
except ImportError:
fatal('You need python-cddb (http://cddb-py.sf.net) to convert cds. Please install it.')
disc_id = DiscID.disc_id(DiscID.open(self.dev))
query_info = CDDB.query(disc_id)[1]
if not query_info:
fatal('The disk is not listed in FreeDB, dir2ogg only supports disk listed in MusicBrainz or FreeDB')
if isinstance(query_info, list):
query_info = query_info[0]
read_info = CDDB.read(query_info['category'], query_info['disc_id'])[1]
for track in range(disc_id[1]):
title = {}
title['discid'] = query_info['disc_id']
title['artist'], title['album'] = (track.strip() for track in query_info['title'].split("/"))
title['genre'] = read_info['DGENRE']
title['date'] = read_info['DYEAR']
title['title'] = read_info['TTITLE' + str(track)]
title['tracktotal'] = str(len(range(disc_id[1])) + 1)
title['ntracknumber'] = '0' * (len(title['tracktotal'] ) - len(str(track+1)) ) + str(track+1)
title['tracknumber'] = str(track+1)
for key, val in title.items():
title[key] = unicode(str(val), "ISO-8859-1")
ConvertTrack(self.dev, self.conf, track+1, title)
示例3: cddbRequest
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def cddbRequest(self, discInfo):
""" Return disc information from online CDDB, None if request fails """
import CDDB, socket
# Make sure to not be blocked by the request
socket.setdefaulttimeout(consts.socketTimeout)
try:
(status, info) = CDDB.query(discInfo)
if status == 200:
disc = info # Success
elif status == 210:
disc = info[0] # Exact multiple matches
elif status == 211:
disc = info[0] # Inexact multiple matches
else:
raise Exception, "Unknown disc (phase 1 returned %u)" % status
(status, info) = CDDB.read(disc["category"], disc["disc_id"])
if status == 210:
return info
else:
raise Exception, "Unknown disc (phase 2 returned %u)" % status
except:
logger.error("[%s] CDDB request failed\n\n%s" % (MOD_INFO[modules.MODINFO_NAME], traceback.format_exc()))
return None
示例4: get_cddb_info
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def get_cddb_info(self):
try:
disc = DiscID.open(self.device)
self.info = DiscID.disc_id(disc)
status, info = CDDB.query(self.info)
except IOError:
return
if status in (210, 211):
info = info[0]
status = 200
if status != 200:
return
(status, info) = CDDB.read(info['category'], info['disc_id'])
title = info['DTITLE'].split(" / ")
for i in range(self.info[1]):
tr = self[i]
tr.set_tag_raw('title',
info['TTITLE' + `i`].decode('iso-8859-15', 'replace'))
tr.set_tag_raw('album',
title[1].decode('iso-8859-15', 'replace'))
tr.set_tag_raw('artist',
title[0].decode('iso-8859-15', 'replace'))
tr.set_tag_raw('year',
info['EXTD'].replace("YEAR: ", ""))
tr.set_tag_raw('genre',
info['DGENRE'])
self.name = title[1].decode('iso-8859-15', 'replace')
event.log_event('cddb_info_retrieved', self, True)
示例5: __init__
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def __init__(self, disc_id):
# Assume that no results will be found.
self.artist = _("Unknown artist")
self.length = 0
self.title = _("Unknown title")
self.tracks = []
try:
(query_status, query_info) = CDDB.query(disc_id)
except IOError:
# Set query_status to 0 to act like an unknown CD.
query_status = 0
# See CDDB documentation for more information.
# http://cddb-py.sourceforge.net/CDDB/README
# query_info variable's type depends on query_status
if query_status == 200:
# On 200, a dictionary containing three items is returned
self._get_information_from_result_element(query_info, disc_id)
elif query_status == 210 or query_status == 211:
# On 211 or 210, a list will be returned as the second item.
# Each element of the list will be a dictionary containing
# three items, exactly the same as a single 200 success return.
self._get_information_from_result_element(query_info[0], disc_id)
else:
# No metadata found for this disc
for i in range(disc_id[1]):
self.tracks.append(CompactDiscTrack(i + 1,
_("Unknown track %(num)s.") % {'num': str(i + 1)}, 0))
示例6: read
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def read(self):
try:
device = DiscID.open()
disc_info = DiscID.disc_id(device)
(query_status, self.query_info) = CDDB.query(disc_info)
except cdrom.error, e:
raise cdrom.error, e
示例7: get_cddb_info
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def get_cddb_info(self):
try:
disc = DiscID.open(self.device)
self.info = DiscID.disc_id(disc)
status, info = CDDB.query(self.info)
except IOError:
return
if status in (210, 211):
info = info[0]
status = 200
if status != 200:
return
(status, info) = CDDB.read(info["category"], info["disc_id"])
title = info["DTITLE"].split(" / ")
for i in range(self.info[1]):
tr = self[i]
tr.set_tag_raw("title", info["TTITLE" + str(i)].decode("iso-8859-15", "replace"))
tr.set_tag_raw("album", title[1].decode("iso-8859-15", "replace"))
tr.set_tag_raw("artist", title[0].decode("iso-8859-15", "replace"))
tr.set_tag_raw("year", info["EXTD"].replace("YEAR: ", ""))
tr.set_tag_raw("genre", info["DGENRE"])
self.name = title[1].decode("iso-8859-15", "replace")
event.log_event("cddb_info_retrieved", self, True)
示例8: query
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def query(self, device):
cdromfd = cdrom.audiocd_open(device)
disc_id = cdrom.audiocd_id(cdromfd)
if kaa.metadata.USE_NETWORK:
try:
(query_stat, query_info) = CDDB.query(disc_id)
except Exception, e:
# Oops no connection
query_stat = 404
示例9: cddb_query
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def cddb_query(discid, cache_dir=os.path.expanduser('~/.cache/cddb')):
cache_path = os.path.join(cache_dir, '%08x' % discid[0])
query = cached(lambda:CDDB.query(discid)[1])(cache_path, discid)
categories = {}
if query is None:
raise Exception('Server has no data for this disc')
if isinstance(query, dict):
query = [query]
if isinstance(query, list):
for q in query:
categories[q['category']] = q['title']
return categories
示例10: getCDDB
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def getCDDB(self, cddbdiscid):
"""
@param cddbdiscid: list of id, tracks, offsets, seconds
@rtype: str
"""
# FIXME: convert to nonblocking?
import CDDB
code, md = CDDB.query(cddbdiscid)
self.debug('CDDB query result: %r, %r', code, md)
if code == 200:
return md['title']
return None
示例11: run
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def run(self):
(status, info) = CDDB.query(self._disc_id,
client_name="dmusic",
client_version="1.0")
if status in [200, 210, 211]:
if status in [210, 211]:
info = sorted(info, key=lambda w: w["category"])
info = info[0]
else:
self.logdebug('Unable to fetch CDDB info, status=%d', status)
(status, info) = CDDB.read(info['category'], info['disc_id'])
if status != 210:
self.logdebug('Unable to fetch CDDB info, status=%d', status)
return
gobject.idle_add(self._cb, self._disc_id, info)
示例12: CDDB_info
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def CDDB_info(CDINFO, DISCID):
# Get some information
cdrom = DiscID.open(CDINFO,)
disc_id = DiscID.disc_id(cdrom)
# Query CDDB
print "Querying CDDB ... "
(query_status, query_info) = CDDB.query(disc_id)
info = False
# Check for status messages
if (query_status == 200):
# 200: success
print " success."
info = True
elif (query_status == 210):
# 210: Multiple exact matches
if (DISCID is not None):
query_info = query_info[DISCID]
info = True
else:
multiple_matches("Multiple exact matches found:", query_info)
elif (query_status == 211):
# 211: Multiple inexact matches
if (DISCID > -1):
query_info = query_info[DISCID]
info = True
else:
multiple_matches("Multiple inexact matches found:", query_info)
elif (query_status == 202):
# 202: No match found
print " failed. No match found."
else:
# Something else went horribly wrong
print " failed with status "+str(query_status)+":\n"
print "Using: "
print query_info
return (info, query_info, disc_id)
示例13: getCDDB
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def getCDDB(self, cddbdiscid):
"""
@param cddbdiscid: list of id, tracks, offsets, seconds
@rtype: str
"""
# FIXME: convert to nonblocking?
import CDDB
try:
code, md = CDDB.query(cddbdiscid)
self.debug('CDDB query result: %r, %r', code, md)
if code == 200:
return md['title']
except IOError, e:
# FIXME: for some reason errno is a str ?
if e.errno == 'socket error':
self._stdout.write("Warning: network error: %r\n" % (e, ))
else:
raise
示例14: extractAudioCdInfo
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def extractAudioCdInfo (self):
""" extract the CD info (album art + artist + tracks), and construct the UPnP items"""
self.cdrom = DiscID.open(self.device_name)
disc_id = DiscID.disc_id(self.cdrom)
(query_status, query_info) = CDDB.query(disc_id)
if query_status in (210, 211):
query_info = query_info[0]
(read_status, read_info) = CDDB.read(query_info['category'], query_info['disc_id'])
# print query_info['title']
# print disc_id[1]
# for i in range(disc_id[1]):
# print "Track %.02d: %s" % (i, read_info['TTITLE' + `i`])
track_count = disc_id[1]
disc_id = query_info['disc_id']
self.disc_title = query_info['title'].encode('utf-8')
tracks = {}
for i in range(track_count):
tracks[i + 1] = read_info['TTITLE' + `i`].decode('ISO-8859-1').encode('utf-8')
self.name = self.disc_title
root_item = Container(None, self.disc_title)
# we will sort the item by "track_number"
def childs_sort(x, y):
return cmp(x.track_number, y.track_number)
root_item.sorting_method = childs_sort
self.set_root_item(root_item)
for number, title in tracks.items():
item = TrackItem(self.device_name, number, "Unknown", title)
external_id = "%s_%d" % (disc_id, number)
root_item.add_child(item, external_id=external_id)
self.info('Sharing audio CD %s', self.disc_title)
reactor.callLater(2, self.checkIfAudioCdStillPresent)
self.init_completed()
示例15: __init__
# 需要导入模块: import CDDB [as 别名]
# 或者: from CDDB import query [as 别名]
def __init__(self):
self.good = True
cdrom = DiscID.open("/dev/sr0")
self.disc_id = DiscID.disc_id(cdrom)
self.disc_info = []
(status,info) = CDDB.query(self.disc_id)
if status == 200:
info = [info]
elif status != 211 and status != 210:
lnp("CDDB: No matches found")
self.good = False
return
for i in info:
(status, read_info) = (None,None)
for j in range(3):
(status,read_info) = CDDB.read(i['category'],i['disc_id'])
if status != 210:
continue
else:
break
if status == 210:
read_info['DISCID'] = i['disc_id']
self.disc_info.append(read_info)