From 15de2eca7b2689070e80ff980bc766cab9c2ac55 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Fri, 14 Feb 2014 14:22:58 +0100 Subject: artwork: try to substitute album name for artist, if artist is missing or cover not found (this allows to load some game music covers from lastfm) --- plugins/artwork/artwork.c | 4 ++++ plugins/artwork/lastfm.c | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'plugins/artwork') diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index 35bcbedb..5362a5df 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -1264,6 +1264,10 @@ get_album_art (const char *fname, const char *artist, const char *album, int siz artist = ""; } + if (*album && !(*artist)) { + artist = album; + } + if (!*artist || !*album) { trace ("artist or album is empty, give up\n"); diff --git a/plugins/artwork/lastfm.c b/plugins/artwork/lastfm.c index 63483406..83bda9cb 100644 --- a/plugins/artwork/lastfm.c +++ b/plugins/artwork/lastfm.c @@ -45,11 +45,17 @@ int fetch_from_lastfm (const char *artist, const char *album, const char *dest) { char url [1024]; - char *artist_url = uri_escape (artist, 0); - char *album_url = uri_escape (album, 0); + char *artist_url = NULL; + char *album_url = NULL; + +retry: + artist_url = uri_escape (artist, 0); + album_url = uri_escape (album, 0); snprintf (url, sizeof (url), BASE_URL "?method=album.getinfo&api_key=" API_KEY "&artist=%s&album=%s", artist_url, album_url); free (artist_url); + artist_url = NULL; free (album_url); + album_url = NULL; DB_FILE *fp = deadbeef->fopen (url); if (!fp) { @@ -78,6 +84,11 @@ fetch_from_lastfm (const char *artist, const char *album, const char *dest) char *end = strstr (img, ""); if (!end || end == img) { + if (artist != album) { + artist = album; + goto retry; + } + trace ("fetch_from_lastfm: bad xml (or image not found) from %s\n", url); return -1; } -- cgit v1.2.3