From 02502f649e269ec34cf22f6a620f7ffcafec69c5 Mon Sep 17 00:00:00 2001 From: waker Date: Sat, 27 Oct 2012 19:58:55 +0200 Subject: artwork: added experimental worldofspectrum.org downloader (loading screens) --- plugins/artwork/Makefile.am | 2 +- plugins/artwork/artwork.c | 20 +++++-- plugins/artwork/wos.c | 126 ++++++++++++++++++++++++++++++++++++++++++++ plugins/artwork/wos.h | 29 ++++++++++ 4 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 plugins/artwork/wos.c create mode 100644 plugins/artwork/wos.h (limited to 'plugins/artwork') diff --git a/plugins/artwork/Makefile.am b/plugins/artwork/Makefile.am index dc46f7d9..3437e85e 100644 --- a/plugins/artwork/Makefile.am +++ b/plugins/artwork/Makefile.am @@ -1,7 +1,7 @@ if HAVE_ARTWORK artworkdir = $(libdir)/$(PACKAGE) pkglib_LTLIBRARIES = artwork.la -artwork_la_SOURCES = artwork.c artwork.h albumartorg.c albumartorg.h lastfm.c lastfm.h escape.c escape.h +artwork_la_SOURCES = artwork.c artwork.h albumartorg.c albumartorg.h lastfm.c lastfm.h wos.c wos.h escape.c escape.h artwork_la_LDFLAGS = -module diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index 5a5a9800..f65a8863 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -20,6 +20,7 @@ #include "artwork.h" #include "lastfm.h" #include "albumartorg.h" +#include "wos.h" #ifdef USE_IMLIB2 #include @@ -75,6 +76,7 @@ static int artwork_enable_embedded; static int artwork_enable_local; static int artwork_enable_lfm; static int artwork_enable_aao; +static int artwork_enable_wos; static time_t artwork_reset_time; static char artwork_filemask[200]; @@ -1115,10 +1117,17 @@ fetcher_thread (void *none) } if (!got_pic) { - if (artwork_enable_lfm && !fetch_from_lastfm (param->artist, param->album, cache_path)) { + if (artwork_enable_wos) { + + char *dot = strrchr (param->fname, '.'); + if (dot && !strcasecmp (dot, ".ay") && !fetch_from_wos (param->album, cache_path)) { + got_pic = 1; + } + } + if (!got_pic && artwork_enable_lfm && !fetch_from_lastfm (param->artist, param->album, cache_path)) { got_pic = 1; } - else if (artwork_enable_aao && !fetch_from_albumart_org (param->artist, param->album, cache_path)) { + else if (!got_pic && artwork_enable_aao && !fetch_from_albumart_org (param->artist, param->album, cache_path)) { got_pic = 1; } } @@ -1181,7 +1190,7 @@ find_image (const char *path) { char* get_album_art (const char *fname, const char *artist, const char *album, int size, artwork_callback callback, void *user_data) { -// trace ("get_album_art: %s (%s - %s)\n", fname, artist, album); + trace ("get_album_art: %s (%s - %s)\n", fname, artist, album); char path [1024]; if (!album) { @@ -1193,6 +1202,7 @@ get_album_art (const char *fname, const char *artist, const char *album, int siz if (!*artist || !*album) { + trace ("artist or album is empty, give up\n"); //give up if (callback) { callback (NULL, NULL, NULL, user_data); @@ -1314,6 +1324,7 @@ artwork_configchanged (void) { int new_artwork_enable_local = deadbeef->conf_get_int ("artwork.enable_localfolder", 1); int new_artwork_enable_lfm = deadbeef->conf_get_int ("artwork.enable_lastfm", 0); int new_artwork_enable_aao = deadbeef->conf_get_int ("artwork.enable_albumartorg", 0); + int new_artwork_enable_wos = deadbeef->conf_get_int ("artwork.enable_wos", 0); char new_artwork_filemask[200]; deadbeef->conf_get_str ("artwork.filemask", DEFAULT_FILEMASK, new_artwork_filemask, sizeof (new_artwork_filemask)); @@ -1322,12 +1333,14 @@ artwork_configchanged (void) { || new_artwork_enable_local != artwork_enable_local || new_artwork_enable_lfm != artwork_enable_lfm || new_artwork_enable_aao != artwork_enable_aao + || new_artwork_enable_wos != artwork_enable_wos || strcmp (new_artwork_filemask, artwork_filemask)) { trace ("artwork config changed, invalidating cache...\n"); artwork_enable_embedded = new_artwork_enable_embedded; artwork_enable_local = new_artwork_enable_local; artwork_enable_lfm = new_artwork_enable_lfm; artwork_enable_aao = new_artwork_enable_aao; + artwork_enable_wos = new_artwork_enable_wos; artwork_reset_time = time (NULL); strcpy (artwork_filemask, new_artwork_filemask); deadbeef->conf_set_int64 ("artwork.cache_reset_time", artwork_reset_time); @@ -1424,6 +1437,7 @@ static const char settings_dlg[] = "property \"Local cover file mask\" entry artwork.filemask \"" DEFAULT_FILEMASK "\";\n" "property \"Fetch from last.fm\" checkbox artwork.enable_lastfm 0;\n" "property \"Fetch from albumart.org\" checkbox artwork.enable_albumartorg 0;\n" + "property \"Fetch from worldofspectrum.org (AY only)\" checkbox artwork.enable_wos 0;\n" "property \"Scale artwork towards longer side\" checkbox artwork.scale_towards_longer 1;\n" ; diff --git a/plugins/artwork/wos.c b/plugins/artwork/wos.c new file mode 100644 index 00000000..9262345d --- /dev/null +++ b/plugins/artwork/wos.c @@ -0,0 +1,126 @@ +/* + world of spectrum game cover downloader for the Deadbeef Artwork plugin + Copyright (C) 2009-2012 Alexey Yakovenko and other contributors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifdef HAVE_CONFIG_H +# include +#endif +#include +#include +#include +#include +#include +#include + +#include "artwork.h" +#include "escape.h" + +//#define trace(...) { fprintf(stderr, __VA_ARGS__); } +#define trace(...) + +extern DB_functions_t *deadbeef; + +#define BASE_URL "http://www.worldofspectrum.org/showscreen.cgi?screen=screens/load" +#define min(x,y) ((x)<(y)?(x):(y)) + +void +strcopy_escape (char *dst, int d_len, const char *src, int n) { + char *e = dst + d_len - 1; + const char *se = src + n; + while (dst < e && *src && src < se) { + if (*src != ' ' && *src != '!') { + *dst++ = *src; + } + src++; + } + *dst = 0; +} + +int +fetch_from_wos (const char *title, const char *dest) +{ + // extract game title from title + char t[100]; + char *dash = strstr (title, " -"); + if (!dash) { + strcopy_escape (t, sizeof (t), title, strlen (title)); + } + else { + strcopy_escape(t, sizeof (t), title, dash-title); + } + char *sp; + while (sp = strchr(t, ' ')) { + *sp = '_'; + } + char *title_url = uri_escape (t, 0); + char url [1024]; + snprintf (url, sizeof (url), BASE_URL "/%c/gif/%s.gif", tolower (title_url[0]), title_url); + free (title_url); + trace ("WOS request: %s\n", url); + + DB_FILE *fp = NULL; + + fp = deadbeef->fopen (url); + if (!fp) { + trace ("fetch_from_wos: failed to open %s\n", url); + return -1; + } + current_file = fp; + + char temp[PATH_MAX]; + snprintf (temp, sizeof (temp), "%s.part", dest); + FILE *out = fopen (temp, "w+b"); + if (!out) { + trace ("fetch_from_lastfm: failed to open %s for writing\n", temp); + deadbeef->fclose (fp); + current_file = NULL; + return -1; + } + + char *writebuffer[4096]; + int len; + int error = 0; + while ((len = deadbeef->fread (writebuffer, 1, sizeof (writebuffer), fp)) > 0) { + if (fwrite (writebuffer, 1, len, out) != len) { + trace ("fetch_from_lastfm: failed to write to %s\n", dest); + error = 1; + break; + } + } + + fclose (out); + current_file = NULL; + deadbeef->fclose (fp); + + if (error) { + unlink (temp); + return -1; + } + + if (rename (temp, dest) != 0) { + unlink (temp); + unlink (dest); + return -1; + } + + return 0; +} diff --git a/plugins/artwork/wos.h b/plugins/artwork/wos.h new file mode 100644 index 00000000..62fbe61a --- /dev/null +++ b/plugins/artwork/wos.h @@ -0,0 +1,29 @@ +/* + world of spectrum game cover downloader for the Deadbeef Artwork plugin + Copyright (C) 2009-2012 Alexey Yakovenko and other contributors + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ +#ifndef __WOS_H +#define __WOS_H + +int +fetch_from_wos (const char *title, const char *dest); + +#endif // __WOS_H -- cgit v1.2.3