本文整理汇总了Python中musicbrainzngs.search_releases函数的典型用法代码示例。如果您正苦于以下问题:Python search_releases函数的具体用法?Python search_releases怎么用?Python search_releases使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了search_releases函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match_album
def match_album(artist, album, tracks=None):
"""Searches for a single album ("release" in MusicBrainz parlance)
and returns an iterator over AlbumInfo objects. May raise a
MusicBrainzAPIError.
The query consists of an artist name, an album name, and,
optionally, a number of tracks on the album.
"""
# Build search criteria.
criteria = {'release': album.lower().strip()}
if artist is not None:
criteria['artist'] = artist.lower().strip()
else:
# Various Artists search.
criteria['arid'] = VARIOUS_ARTISTS_ID
if tracks is not None:
criteria['tracks'] = six.text_type(tracks)
# Abort if we have no search terms.
if not any(criteria.values()):
return
try:
res = musicbrainzngs.search_releases(
limit=config['musicbrainz']['searchlimit'].get(int), **criteria)
except musicbrainzngs.MusicBrainzError as exc:
raise MusicBrainzAPIError(exc, 'release search', criteria,
traceback.format_exc())
for release in res['release-list']:
# The search result is missing some data (namely, the tracks),
# so we just use the ID and fetch the rest of the information.
albuminfo = album_for_id(release['id'])
if albuminfo is not None:
yield albuminfo
示例2: getNowTracks
def getNowTracks(self, albumnumber):
rx = re.compile('\W');
ret = []
res = musicbrainzngs.search_releases(query='Now That\'s What I Call Music ' + str(albumnumber))
if(not('release-list' in res)):
return ret
for release in res['release-list']:
title = rx.sub('', release['title'].encode('ascii', 'ignore').lower())
if title != 'nowthatswhaticallmusic' + str(albumnumber):
continue
if release['country'] != 'GB':
continue
format = 0
for medium in release['medium-list']:
if 'format' in medium:
if medium['format'] == 'CD':
format = 1
if format == 1:
ret.append(release)
if len(ret) == 1:
mbid = ret[0]['id']
return self.getCompilationAlbumTracks(mbid)
ret = []
return ret
示例3: find_releases
def find_releases(artists_set, year_month):
good = u""
questionable = u""
for artist in artists_set:
result = musicbrainzngs.search_releases(
query=u"artist:\"{}\" AND date:{}-?? AND status:official AND primarytype:album".format(artist, year_month))
if not result['release-list']:
Logger.debug("no release found for artist %s", artist)
music_brains_links = u""
for (idx, rel) in enumerate(result['release-list'], start=1):
log_album(artist, rel, idx)
music_brains_links += u'<a href="http://musicbrainz.org/release/{}">{}</a> '\
.format(rel['id'], rel.get('country', 'NONE'))
if idx < len(result['release-list']) and rel['title'] == result['release-list'][idx]['title']:
continue
album_info = u"<b>{}</b>".format(artist)
if artist != rel["artist-credit-phrase"]:
album_info += u"({})".format(rel["artist-credit-phrase"])
album_info += u" - {} - Released {} in {}<br/>\n".format(rel['title'], rel['date'], music_brains_links)
music_brains_links = u""
album_info += u'Links: <a href="https://play.google.com/music/listen#/sr/{0}">Google Music</a> ' \
u'<a href="http://www.emusic.com/search/music/?s={0}">eMusic</a> ' \
u'<br/><br/>'.format(urllib.quote_plus(rel['title'].encode('utf8')))
if artist.lower() == rel["artist-credit-phrase"].lower():
good += album_info
else:
questionable += album_info
return good + questionable
示例4: match_album
def match_album(artist, album, tracks=None, limit=SEARCH_LIMIT):
"""Searches for a single album ("release" in MusicBrainz parlance)
and returns an iterator over AlbumInfo objects. May raise a
MusicBrainzAPIError.
The query consists of an artist name, an album name, and,
optionally, a number of tracks on the album.
"""
# Build search criteria.
criteria = {"release": album.lower()}
if artist is not None:
criteria["artist"] = artist.lower()
else:
# Various Artists search.
criteria["arid"] = VARIOUS_ARTISTS_ID
if tracks is not None:
criteria["tracks"] = str(tracks)
# Abort if we have no search terms.
if not any(criteria.itervalues()):
return
try:
res = musicbrainzngs.search_releases(limit=limit, **criteria)
except musicbrainzngs.MusicBrainzError as exc:
raise MusicBrainzAPIError(exc, "release search", criteria, traceback.format_exc())
for release in res["release-list"]:
# The search result is missing some data (namely, the tracks),
# so we just use the ID and fetch the rest of the information.
albuminfo = album_for_id(release["id"])
if albuminfo is not None:
yield albuminfo
示例5: search_releases
def search_releases(artist, album, limit):
from lxml import etree
root = etree.XML(u'<searchreleases></searchreleases>')
result = musicbrainzngs.search_releases(artist=artist, release=album, country="GB", limit=limit)
if not result['release-list']:
etree.SubElement(root, "error").text = "No Releases found"
log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))
sys.exit(1)
for (idx, release) in enumerate(result['release-list']):
pprint.pprint(release)
relNode = etree.SubElement(root, "release")
etree.SubElement(relNode, "id").text = release['id']
etree.SubElement(relNode, "ext-score").text = release['ext:score']
etree.SubElement(relNode, "title").text = release['title']
etree.SubElement(relNode, "artist-credit-phrase").text = release["artist-credit-phrase"]
etree.SubElement(relNode, "country").text = release["country"]
if 'date' in release:
etree.SubElement(relNode, "date").text = release['date']
etree.SubElement(relNode, "status").text = release['status']
if 'release-group' in release:
etree.SubElement(relNode, "releasegroup").text = release["release-group"]["id"]
log(True, etree.tostring(root, encoding='UTF-8', pretty_print=True, xml_declaration=True))
sys.exit(0)
示例6: MBReleaseGroup
def MBReleaseGroup(self):
"""Search for releases on musicbrainz by group ID"""
rgid = raw_input('Enter release group ID: ')
results = musicbrainzngs.search_releases(rgid=rgid,
limit=self.searchResultsLimit)
if results:
self.printQueryResults(results)
示例7: MBReleaseTitle
def MBReleaseTitle(self):
"""Search for release on musicbrainz by title"""
title = raw_input('Enter title: ')
results = musicbrainzngs.search_releases(release=title,
limit=self.searchResultsLimit)
if results:
self.printQueryResults(results)
示例8: MBReleaseBarcode
def MBReleaseBarcode(self):
"""Search for release on musicbrainz by barcode"""
barcode = raw_input('Enter barcode: ')
results = musicbrainzngs.search_releases(barcode=barcode,
limit=self.searchResultsLimit)
if results:
self.printQueryResults(results)
示例9: find_releases
def find_releases(name, limit=10, artist_id=None,
wanted_keys=('name', 'id', 'title', 'country', 'release-group', 'ext:score', 'asin')):
with musicbrainz_lock:
strict = True if artist_id else False
params = {'release': name, 'arid': artist_id}
search_results = musicbrainzngs.search_releases(limit=limit, strict=strict, **params)['release-list']
sorted_by_score = sorted(search_results, cmp=lambda x, y: max(x, y), key=lambda d: int(d['ext:score']))
return [{k: v for k, v in d.items() if k in wanted_keys} for d in sorted_by_score]
示例10: _request
def _request(query, artist, album=None, track=None):
results = None
if track:
results = musicbrainzngs.search_recordings(query=query)
elif album:
results = musicbrainzngs.search_releases(query=query)
elif artist:
results = musicbrainzngs.search_artists(query=query)
return results
示例11: MBReleaseCatno
def MBReleaseCatno(self):
"""Search for release on musicbrainz by catalog number"""
catno = raw_input('Enter catalog number: ')
if ' ' in catno:
_log.warning('Removing whitespaces from string (workaround)')
catno = catno.replace(' ', '')
results = musicbrainzngs.search_releases(catno=catno,
limit=self.searchResultsLimit)
if results:
self.printQueryResults(results)
示例12: artistSearch
def artistSearch(artist):
if request.method == 'POST':
artist = request.form['artist']
if artist == '':
return redirect(url_for('artistSearch', artist='artistSearch'))
searched = artist
result = musicbrainzngs.search_releases(artist=artist, limit=5)
# relList = result['release-list']
relList = releaseInfo(result['release-list'])
return render_template('release_results.html', releases=relList,
search_by='artist', searched=searched)
示例13: catnoSearch
def catnoSearch(catno):
if request.method == 'POST':
catno = request.form['catno']
if catno == '':
return redirect(url_for('catnoSearch', catno='catnoSearch'))
searched = catno
result = musicbrainzngs.search_releases(catno=catno, limit=5)
# relList = result['release-list']
relList = releaseInfo(result['release-list'])
return render_template('release_results.html', releases=relList,
search_by='catno', searched=searched)
示例14: barcodeSearch
def barcodeSearch(barcode):
if request.method == 'POST':
barcode = request.form['barcode']
if barcode == '':
return redirect(url_for('barcodeSearch', barcode='barcodeSearch'))
searched = barcode
result = musicbrainzngs.search_releases(barcode=barcode, limit=5)
# relList = result['release-list']
relList = releaseInfo(result['release-list'])
return render_template('release_results.html', releases=relList,
search_by='barcode', searched=searched)
示例15: searchMusicBrainzAlbumAndArtist
def searchMusicBrainzAlbumAndArtist(artist, album):
"""searchMusicBrainzByID looks for a release ID by an album and an artist"""
result = musicbrainzngs.search_releases(artist=artist, release=album)
results = []
if not result['release-list']:
return results
for release in result['release-list']:
# If we haven't seen this id yet, add it to the return list
if release.get('id') not in results:
results.append(release.get('id'))
return results