예제 #1
0
 def getReleaseMetaXml(self, releaseId):
     """Fetch release metadata XML from musicbrainz"""
     # get_release_by_id() handles throttling on its own
     mb.set_parser(mb.mb_parser_null)
     xml = mb.get_release_by_id(releaseId, includes=['artists', 'discids', 'media', 'labels', 'recordings'])
     mb.set_parser()
     return xml
예제 #2
0
 def _get_albumdata(self, meta):
     '''Get album data from MusicBrainz.'''
     data = None
     # search release-group mbid by release mbid
     if 'mbidrelgrp' not in meta and 'mbidrelease' in meta:
         VPRINT("  Using release-MBID: %s" % meta["mbidrelease"])
         req = mb.get_release_by_id(meta["mbidrelease"],
                                    includes=['release-groups'])
         if req and 'release' in req and 'release-group' in req:
             meta['mbidrelgrp'] = req['release']['release-group']['id']
         else:
             VPRINT("  Release not found, deleting invalid MBID")
             del meta['mbidrelease']
     # search album by release-group mbid
     if 'mbidrelgrp' in meta:
         VPRINT("  Using relgrp-MBID: %s" % meta['mbidrelgrp'])
         req = mb.get_release_group_by_id(meta['mbidrelgrp'],
                                          includes=['tags'])
         if req and 'release-group' in req:
             data = [req['release-group']]
         else:
             VPRINT("  Rel-Grp not found, deleting invalid MBID")
             del meta['mbidrelgrp']
     # search album without release-group mbid
     if not data:
         try:
             req = mb.search_release_groups(
                 release=self.searchstr(meta['album']),
                 artist=self.searchstr(meta.get('artist') or
                                       meta.get('aartist', '')),
                 arid=meta.get('mbidartist') or
                 meta.get('mbidaartist', ''))
         except ValueError:
             return None
         data = req.get('release-group-list', [])
     return [{'info': "%s - %s [%s]: "
              "http://musicbrainz.org/release-group/%s"
              % (x.get('artist-credit-phrase'), x.get('title'),
                 x.get('type'), x['id']),
              'title': (x.get('artist-credit-phrase', '') + ' - '
                        + x.get('title', '')),
              'tags': {tag['name']: int(tag['count']) for tag in
                       x.get('tag-list', [])},
              'mbid': x['id']} for x in data]
예제 #3
0
	def get_MB_tracks_from_release(self, MB_release):
			
		try:
			from musicbrainzngs import musicbrainz, ResponseError, NetworkError
		except ImportError as imperr:
			print "musicbrainzngs not available"
			self.error = ("100", "Import error", imperr)
			raise
			
		try:
			musicbrainz.set_useragent("xaudiocopy", "0.02.1")
		except:
			self.error(101, "User agent error", "")
			raise
		# Scarica la release del disco in base all'ID
		try:
			release = musicbrainz.get_release_by_id(MB_release["album-id"], 
				includes=["artists", "recordings", "release-groups", "labels"])
		except ResponseError as reserr:
			if reserr.cause.code == 404:
				print "Disc not found", reserr
				self.error = (int(reserr.cause.code), "Disc not found", reserr)
				raise
			else:
				print "Bad response from the MB server", reserr
				self.error = (int(reserr.cause.code), "Bad response from the MB server", reserr)
				raise
		except NetworkError as neterr:
			print "Network connection error", neterr
			self.error = (402, "Network connection error", neterr)
			raise
			""" Eccezione non gestita nella versione 0.2 di musicbrainzngs
		except AuthenticationError as auterr:
			print "Receved a HTTP 401 response while accessing a protected resource"
			self.error = (auterr, "Receved a HTTP 401 response while accessing a protected resource", auterr)		
			raise"""
		print release
		
		# La release è un dict con dentro un altro dict "release"
		# TODO Esistono release che hanno altri elementi?
		release = release["release"]

		tracks_list = []
		# Per ogni disco presente (se presente) trova quello giusto
		if release["id"] == MB_release["album-id"]:
			for medium in release["medium-list"]:
				for track in medium["track-list"]:
					# Dizionario con i tag della canzone
					self.track = {
						"track-number" : int(track["position"]),
						"title" : track["recording"]["title"],
						"artist" : release["artist-credit"][0]["artist"]["name"],
						"artist-sort-name" : release["artist-credit"][0]["artist"]["sort-name"],
						"album" : release["title"],
						"recording-id" : track["recording"]["id"],
						"album-id" : release["id"],
						"artist-id" : release["artist-credit"][0]["artist"]["id"],
						#"lenght" : track["recording"]["lenght"],
						"release" : MB_release,
						}
					tracks_list.append(self.track)
				
		# Stampa di prova
		i = 0
		for t in tracks_list:
			i+=1
			print
			print "TRACK %d" % i
			keys = t.keys()
			for k in keys:
				print '%s = %s' % (k,t[k])

		return tracks_list