summaryrefslogtreecommitdiff
path: root/plugins/artwork
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2010-11-06 20:01:04 +0100
committerGravatar waker <wakeroid@gmail.com>2010-11-06 20:01:04 +0100
commit84ef45390ea6aafc8db1fb568080eb762e90df13 (patch)
tree282db111f93e0f47be6dffb42160ea1dda17550e /plugins/artwork
parent5799d3e36063b44c4b2cc81cb42d75f408907652 (diff)
removed libcurl dependency from artwork plugin
Diffstat (limited to 'plugins/artwork')
-rw-r--r--plugins/artwork/Makefile.am4
-rw-r--r--plugins/artwork/albumartorg.c11
-rw-r--r--plugins/artwork/escape.c104
-rw-r--r--plugins/artwork/escape.h24
-rw-r--r--plugins/artwork/lastfm.c11
5 files changed, 142 insertions, 12 deletions
diff --git a/plugins/artwork/Makefile.am b/plugins/artwork/Makefile.am
index 403a30e2..b60c86cb 100644
--- a/plugins/artwork/Makefile.am
+++ b/plugins/artwork/Makefile.am
@@ -1,10 +1,10 @@
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
+artwork_la_SOURCES = artwork.c artwork.h albumartorg.c albumartorg.h lastfm.c lastfm.h escape.c escape.h
artwork_la_LDFLAGS = -module
-artwork_la_LIBADD = $(LDADD) $(ARTWORK_DEPS_LIBS) $(CURL_LIBS)
+artwork_la_LIBADD = $(LDADD) $(ARTWORK_DEPS_LIBS)
AM_CFLAGS = -std=c99 $(ARTWORK_DEPS_CFLAGS)
endif
diff --git a/plugins/artwork/albumartorg.c b/plugins/artwork/albumartorg.c
index d438cf9c..71b640de 100644
--- a/plugins/artwork/albumartorg.c
+++ b/plugins/artwork/albumartorg.c
@@ -17,10 +17,11 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdlib.h>
-#include <curl/curl.h>
#include <string.h>
#include <unistd.h>
+#include <limits.h>
#include "artwork.h"
+#include "escape.h"
extern DB_functions_t *deadbeef;
@@ -31,11 +32,11 @@ int
fetch_from_albumart_org (const char *artist, const char *album, const char *dest)
{
char url [1024];
- char *artist_url = curl_easy_escape (NULL, artist, 0);
- char *album_url = curl_easy_escape (NULL, album, 0);
+ char *artist_url = uri_escape (artist, 0);
+ char *album_url = uri_escape (album, 0);
snprintf (url, sizeof (url), "http://www.albumart.org/index.php?srchkey=%s+%s&itempage=1&newsearch=1&searchindex=Music", artist_url, album_url);
- curl_free (artist_url);
- curl_free (album_url);
+ free (artist_url);
+ free (album_url);
DB_FILE *fp = deadbeef->fopen (url);
if (!fp) {
diff --git a/plugins/artwork/escape.c b/plugins/artwork/escape.c
new file mode 100644
index 00000000..3e3653e4
--- /dev/null
+++ b/plugins/artwork/escape.c
@@ -0,0 +1,104 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+/* Escape and unescape URL encoding in strings. The functions return a new
+ * allocated string or NULL if an error occurred. */
+
+#include <ctype.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Portable character check (remember EBCDIC). Do not use isalnum() because
+ its behavior is altered by the current locale.
+ See http://tools.ietf.org/html/rfc3986#section-2.3
+*/
+static int Curl_isunreserved(unsigned char in)
+{
+ switch (in) {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ case 'a': case 'b': case 'c': case 'd': case 'e':
+ case 'f': case 'g': case 'h': case 'i': case 'j':
+ case 'k': case 'l': case 'm': case 'n': case 'o':
+ case 'p': case 'q': case 'r': case 's': case 't':
+ case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
+ case 'A': case 'B': case 'C': case 'D': case 'E':
+ case 'F': case 'G': case 'H': case 'I': case 'J':
+ case 'K': case 'L': case 'M': case 'N': case 'O':
+ case 'P': case 'Q': case 'R': case 'S': case 'T':
+ case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
+ case '-': case '.': case '_': case '~':
+ return 1;
+ default:
+ break;
+ }
+ return 0;
+}
+
+char *uri_escape(const char *string, int inlength)
+{
+ size_t alloc = (inlength?(size_t)inlength:strlen(string))+1;
+ char *ns;
+ char *testing_ptr = NULL;
+ unsigned char in; /* we need to treat the characters unsigned */
+ size_t newlen = alloc;
+ int strindex=0;
+ size_t length;
+
+ ns = malloc(alloc);
+ if(!ns)
+ return NULL;
+
+ length = alloc-1;
+ while(length--) {
+ in = *string;
+
+ if (Curl_isunreserved(in)) {
+ /* just copy this */
+ ns[strindex++]=in;
+ }
+ else {
+ /* encode it */
+ newlen += 2; /* the size grows with two, since this'll become a %XX */
+ if(newlen > alloc) {
+ alloc *= 2;
+ testing_ptr = realloc(ns, alloc);
+ if(!testing_ptr) {
+ free( ns );
+ return NULL;
+ }
+ else {
+ ns = testing_ptr;
+ }
+ }
+
+ snprintf(&ns[strindex], 4, "%%%02X", in);
+
+ strindex+=3;
+ }
+ string++;
+ }
+ ns[strindex]=0; /* terminate it */
+ return ns;
+}
diff --git a/plugins/artwork/escape.h b/plugins/artwork/escape.h
new file mode 100644
index 00000000..d87cf0a1
--- /dev/null
+++ b/plugins/artwork/escape.h
@@ -0,0 +1,24 @@
+/*
+ DeaDBeeF - ultimate music player for GNU/Linux systems with X11
+ Copyright (C) 2009-2010 Alexey Yakovenko <waker@users.sourceforge.net>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+#ifndef __ESCAPE_H
+#define __ESCAPE_H
+
+char *uri_escape(const char *string, int inlength);
+
+#endif
diff --git a/plugins/artwork/lastfm.c b/plugins/artwork/lastfm.c
index bf76ccca..ce95e9d4 100644
--- a/plugins/artwork/lastfm.c
+++ b/plugins/artwork/lastfm.c
@@ -1,10 +1,11 @@
#include <stdio.h>
#include <string.h>
-#include <curl/curl.h>
#include <stdlib.h>
#include <unistd.h>
+#include <limits.h>
#include "artwork.h"
+#include "escape.h"
#define BASE_URL "http://ws.audioscrobbler.com/2.0/"
#define API_KEY "b25b959554ed76058ac220b7b2e0a026"
@@ -18,11 +19,11 @@ int
fetch_from_lastfm (const char *artist, const char *album, const char *dest)
{
char url [1024];
- char *artist_url = curl_easy_escape (NULL, artist, 0);
- char *album_url = curl_easy_escape (NULL, album, 0);
+ char *artist_url = uri_escape (artist, 0);
+ char *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);
- curl_free (artist_url);
- curl_free (album_url);
+ free (artist_url);
+ free (album_url);
DB_FILE *fp = deadbeef->fopen (url);
if (!fp) {