def send_update(metadata): if metadata.hifiberry_cover_found: return if metadata.mbid is None: return key = "update" + metadata.songId() best_picture_url(key, metadata.externalArtUrl) artUrl = best_picture_url(key, metadata.artUrl) if artUrl is not None: (width, height) = best_picture_size(key) else: return if metadata.albummbid is not None: mbid = metadata.albummbid else: mbid = metadata.mbid data = {"mbid": mbid, "url": artUrl, "width": width, "height": height} try: logging.info("sending cover update to hifiberry musicdb") url = "{}/cover-update".format(BASE_URL) post_data(url, data) except Exception as e: logging.exception(e)
def enrich_metadata(metadata): if metadata.mbid is None: return (artUrl, width, height) = hifiberry_cover(metadata.mbid, metadata.albummbid, metadata.artistmbid, metadata.playerName) # check if the cover is improved key = metadata.songId() metadata.externalArtUrl = best_picture_url(key, artUrl, width, height) if metadata.externalArtUrl == artUrl and artUrl is not None: metadata.hifiberry_cover_found = True
def enrich_metadata(metadata): if metadata.hifiberry_cover_found: return if metadata.is_unknown(): # Do not try to retrieve metadata for unknown songs return if metadata.albummbid is None: return key = metadata.songId() if good_enough(key): return artUrl = coverartarchive_cover(metadata.albummbid) # check if the cover is improved metadata.externalArtUrl = best_picture_url(key, artUrl)
def enrich_metadata(metadata, allow_artist_picture=False): if metadata.hifiberry_cover_found: return if metadata.is_unknown(): # Do not try to retrieve metadata for unknown songs return if metadata.artistmbid is None: logging.debug("artist mbid unknpown, can't use fanart.tv") return key = metadata.songId() if good_enough(key): logging.debug("existing cover is good enough, skipping fanart.tv") return url = get_fanart_cover(metadata.artistmbid, metadata.albummbid, allow_artist_picture) metadata.externalArtUrl = best_picture_url(key, url)
def enrich_metadata(metadata): logging.debug("enriching metadata") if metadata.artist is None or metadata.title is None: logging.debug("artist and/or title undefined, can't enrich metadata") userparam = "" if lastfmuser is not None: userparam = "&user={}".format(quote(lastfmuser)) metadata.loveSupported = True logging.debug("Love supported") else: logging.debug("Love unsupported") trackdata = None albumdata = None key = metadata.songId() if metadata.externalArtUrl is not None: best_picture_url(key, metadata.externalArtUrl) # Get album data if album is set if metadata.artist is not None and \ metadata.albumTitle is not None: albumdata = albumInfo(metadata.artist, metadata.albumTitle) found_album_cover = False if albumdata is not None: url = bestImage(albumdata) if url is not None: metadata.externalArtUrl = best_picture_url(key, url) logging.info("Got album cover for %s/%s from Last.FM: %s", metadata.artist, metadata.albumTitle, metadata.externalArtUrl) found_album_cover = True if metadata.albummbid is None: try: metadata.albummbid = albumdata["album"]["mbid"] logging.debug("added albummbid from Last.FM") except KeyError: # mbid might not be available pass if metadata.albumArtist is None: try: metadata.albumartist = albumdata["album"]["artist"] logging.debug("added album artist from Last.FM") except KeyError: # mbid might not be available pass # get track data if (metadata.artist is not None and metadata.title is not None) or \ metadata.mbid is not None: trackdata = trackInfo(metadata.artist, metadata.title, metadata.mbid, userparam) # Update track with more information if trackdata is not None and "track" in trackdata: trackdata = trackdata["track"] if metadata.artistmbid is None: if "artist" in trackdata and "mbid" in trackdata["artist"]: metadata.artistmbid = trackdata["artist"]["mbid"] logging.debug("artistmbid=%s", metadata.artistmbid) if metadata.albummbid is None: if "album" in trackdata and "mbid" in trackdata["album"]: metadata.albummbid = trackdata["album"]["mbid"] logging.debug("albummbid=%s", metadata.albummbid) if not (found_album_cover): url = bestImage(trackdata) if url is not None: metadata.externalArtUrl = best_picture_url(key, url) logging.info("Got track cover for %s/%s/%s from Last.FM: %s", metadata.artist, metadata.title, metadata.albumTitle, metadata.externalArtUrl) if metadata.playCount is None and "userplaycount" in trackdata: metadata.playCount = trackdata["userplaycount"] if metadata.mbid is None and "mbid" in trackdata: metadata.mbid = trackdata["mbid"] logging.debug("mbid=%s", metadata.mbid) if metadata.loved is None and "userloved" in trackdata: metadata.loved = (int(trackdata["userloved"]) > 0) # Workaround for "missing attribute wiki" bug try: _ = metadata.wiki except AttributeError: metadata.wiki = None if metadata.wiki is None and "wiki" in trackdata: metadata.wiki = trackdata["wiki"] logging.debug("found Wiki entry") if "toptags" in trackdata and "tag" in trackdata["toptags"]: for tag in trackdata["toptags"]["tag"]: metadata.add_tag(tag["name"]) logging.debug("adding tag from Last.FM: %s", tag["name"]) else: logging.info("no track data for %s/%s on Last.FM", metadata.artist, metadata.title) if metadata.artistmbid is None and metadata.artist is not None: artistdata = artistInfo(metadata.artist) if artistdata is not None: try: metadata.artistmbid = artistdata["artist"]["mbid"] logging.debug("added artistmbid from Last.FM") except KeyError: # mbid might not be available pass