def getReleaseWithTracks(release): """Given a release, look up that release with track info. MusicBrainz requires you explictly ask for track info when requesting a release to get that info. So, when applying post-processing that requires track info, this function is used.""" return contactMB( mbws.Query().getReleaseById, [release.id, mbws.ReleaseIncludes(tracks=True)])
def album_for_id(albumid): """Fetches an album by its MusicBrainz ID and returns an information dictionary. If no match is found, returns None. """ query = mbws.Query() inc = mbws.ReleaseIncludes(artist=True, tracks=True) try: album = _query_wrap(query.getReleaseById, albumid, inc) except (mbws.ResourceNotFoundError, mbws.RequestError): return None return release_dict(album, album.tracks)
def release_info(release_id): """Given a MusicBrainz release ID, fetch a list of tracks on the release and the release group ID. If the release is not found, returns None. """ inc = mbws.ReleaseIncludes(tracks=True, releaseGroup=True) release = _query_wrap(mbws.Query().getReleaseById, release_id, inc) if release: return release.getTracks(), release.getReleaseGroup().getId() else: return None
def __result_changed(self, combo): """Called when a release is chosen from the result combo.""" idx = combo.get_active() if idx == -1: return rel_id = self._resultlist[idx][0].id if rel_id in self._releasecache: self.__update_results(self._releasecache[rel_id]) else: self.result_label.set_markup("<i>Loading result...</i>") inc = ws.ReleaseIncludes( artist=True, releaseEvents=True, tracks=True) self._qthread.add(self.__update_result, self._query.getReleaseById, rel_id, inc)
def get_release_by_releaseid(releaseid): """ Given a musicbrainz release-id, fetch the release from musicbrainz. """ q = ws.Query(clientId=CLIENTID) requests = { "artist": True, "counts": True, "tracks": True, "releaseEvents": True, "releaseRelations": True, "urlRelations": True, "tags": True, } if SUBMIT_SUPPORT: requests["isrcs"] = True includes = ws.ReleaseIncludes(**requests) return q.getReleaseById(id_=releaseid, include=includes)
raise self.MBError discId = disc.getId() try: myfilter = mbws.ReleaseFilter(discId=discId) results = query.getReleases(myfilter) except mbws.WebServiceError, err: warn(err) raise self.MBError if len(results) == 0: print "Disc is not yet in the MusicBrainz database." print "Consider adding it via", mbdisc.getSubmissionUrl(disc) raise self.MBError try: inc = mbws.ReleaseIncludes(artist=True, tracks=True, releaseEvents=True) release = query.getReleaseById(results[0].release.getId(), inc) except mbws.WebServiceError, err: warn(err) raise self.MBError isSingleArtist = release.isSingleArtistRelease() try: # try to get the CDDB ID import DiscID cddb_id = '%08lx' % long(DiscID.disc_id(DiscID.open(self.dev))[0]) except: cddb_id = False trackn = 1
""" import random import musicbrainz2.model as m import musicbrainz2.webservice as ws query = ws.Query() track_inc = ws.TrackIncludes(artist=True, releases=True) artist_inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), tags=True, releaseGroups=True) release_inc = ws.ReleaseIncludes(artist=True, releaseEvents=True, labels=True, discs=True, tracks=True, releaseGroup=True) def get_track(keyword, id=False): if id == True: result = query.getTrackById(keyword, track_inc) else: f = ws.TrackFilter(title=keyword) result = query.getTracks(f) return result def get_artist(keyword, id=False): if id == True:
def get_mb_release(self, id): q = ws.Query() include = ws.ReleaseIncludes(artist=True, tracks=True) try : res = q.getReleaseById(id, include) except: return None else: return res
def get_mb(self): try: import musicbrainz2.disc as mbdisc import musicbrainz2.webservice as mbws except ImportError as err: warn( 'You need python-musicbrainz2 (or python-cddb) to convert cds. Please install it. Trying cddb.' ) raise self.MBError(err) service = mbws.WebService() query = mbws.Query(service) # Read the disc in the drive try: disc = mbdisc.readDisc(self.dev) except mbdisc.DiscError as err: warn(err) raise self.MBError discId = disc.getId() try: myfilter = mbws.ReleaseFilter(discId=discId) results = query.getReleases(myfilter) except mbws.WebServiceError as err: warn(err) raise self.MBError if len(results) == 0: print("Disc is not yet in the MusicBrainz database.") print("Consider adding it via", mbdisc.getSubmissionUrl(disc)) raise self.MBError try: inc = mbws.ReleaseIncludes(artist=True, tracks=True, releaseEvents=True) release = query.getReleaseById(results[0].release.getId(), inc) except mbws.WebServiceError as err: warn(err) raise self.MBError isSingleArtist = release.isSingleArtistRelease() try: # try to get the CDDB ID import DiscID cddb_id = '%08lx' % int(DiscID.disc_id(DiscID.open(self.dev))[0]) except: cddb_id = False trackn = 1 for track in release.tracks: title = {} title[ 'artist'] = isSingleArtist and release.artist.name or track.artist if cddb_id: title['discid'] = cddb_id title['album'] = release.title title['date'] = release.getEarliestReleaseDate() title['musicbrainz_albumartistid'] = release.artist.id.split( "/")[-1] title['musicbrainz_albumid'] = release.id.split("/")[-1] title['musicbrainz_discid'] = discId title['musicbrainz_sortname'] = release.artist.sortName title['musicbrainz_trackid'] = track.id.split("/")[-1] title['title'] = track.title title['tracktotal'] = str(len(release.tracks)) title['ntracknumber'] = "%02d" % trackn title['tracknumber'] = str(trackn) ConvertTrack(self.dev, self.conf, trackn, title) trackn += 1