summaryrefslogtreecommitdiff
path: root/plugins/artwork
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-02-14 14:22:58 +0100
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-02-14 14:22:58 +0100
commit15de2eca7b2689070e80ff980bc766cab9c2ac55 (patch)
treea6794dd86f2b9d9c026d649a28ce43ee2a8a945b /plugins/artwork
parent7a6f3f9e8b016c4c2b0fd2a5e30e8850465e3742 (diff)
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)
Diffstat (limited to 'plugins/artwork')
-rw-r--r--plugins/artwork/artwork.c4
-rw-r--r--plugins/artwork/lastfm.c15
2 files changed, 17 insertions, 2 deletions
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, "</image>");
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;
}