def get_release_cb (self, data, args): (key, store, callback, cbargs) = args if data is None: print("musicbrainz release request returned nothing") callback(True) return try: parsed = dom.parseString(data) storekey = RB.ExtDBKey.create_storage('album', key.get_field('album')) # check that there's an artist that isn't 'various artists' artist_tags = parsed.getElementsByTagName('artist') print(artist_tags) if len(artist_tags) > 0: artist_id = artist_tags[0].attributes['id'].firstChild.data if artist_id != MUSICBRAINZ_VARIOUS_ARTISTS: # add the artist name (as album-artist) to the storage key nametags = artist_tags[0].getElementsByTagName('name') if len(nametags) > 0: artistname = nametags[0].firstChild.data storekey.add_field('artist', artistname) else: storekey.add_field("artist", key.get_field("artist")) continue_search = True # look for an ASIN tag asin_tags = parsed.getElementsByTagName('asin') if len(asin_tags) > 0: asin = asin_tags[0].firstChild.data image_url = AMAZON_IMAGE_URL % asin print("got url %s" % image_url) #now get file size before downloading site = rb3compat.urlopen(image_url) meta = site.info() if rb3compat.PYVER >= 3: size = meta.get_all('Content-Length')[0] else: size = meta.getheaders("Content-Length")[0] if int(size) > 1000: print(size) store.store_uri(storekey, RB.ExtDBSourceType.SEARCH, image_url) else: print("no search") print(size) continue_search = False else: print("no ASIN for this release") print(callback) callback(continue_search) except Exception as e: print("exception parsing musicbrainz response: %s" % e) callback(True)
def artist_info_cb (self, data): if data is None: print("last.fm query returned nothing") self.callback (True) return encoding = chardet.detect(data)['encoding'] encoded = data.decode(encoding) json_data = json.loads(encoded) if 'artist' not in json_data: print ("no artists found in data returned") self.callback (True) return artist = json_data['artist'] # find image URLs image_urls = [] if 'image' not in artist: print ("no images found for artist") self.callback (True) return for key in artist['image']: for url in list(key.values()): url.strip() if url.endswith('.png') or url.endswith('.jpg'): image_urls.append(url) if len(image_urls) > 0: # images tags appear in order of increasing size, and we want the largest. probably. url = image_urls.pop() #last check - ensure the size is relatively large to hide false positives site = rb3compat.urlopen(url) meta = site.info() if rb3compat.PYVER >= 3: size = meta.get_all('Content-Length')[0] else: size = meta.getheaders("Content-Length")[0] if int(size) > 1000: self.store.store_uri(self.current_key, RB.ExtDBSourceType.SEARCH, str(url)) self.callback(False) return self.callback (True)
def album_info_cb(self, data): if data is None: print("last.fm query returned nothing") self.search_next() return parsed = dom.parseString(data) # find image URLs image_urls = [] for tag in parsed.getElementsByTagName('image'): if tag.firstChild is None: print("got useless image tag") continue url = tag.firstChild.data url.strip() if url != "": print("found image url: %s" % url) image_urls.append(url) if len(image_urls) > 0: # images tags appear in order of increasing size, and we want the largest. probably. url = image_urls.pop() # last check - ensure the size is relatively large to hide false positives site = rb3compat.urlopen(url) meta = site.info() if rb3compat.PYVER >= 3: size = meta.get_all('Content-Length')[0] else: size = meta.getheaders("Content-Length")[0] if int(size) > 1000: print(size) self.store.store_uri(self.current_key, RB.ExtDBSourceType.SEARCH, url) self.callback(False) else: self.search_next() else: self.search_next()