Permalink
Browse files

Fixed albumlist; Fixed partly broken lastfm

  • Loading branch information...
sahib committed Oct 19, 2012
1 parent dbddb9f commit ff3626fb7739e9dcfb9c3e4dae6dfcdc1c35a61a
Showing with 112 additions and 27 deletions.
  1. +1 −1 lib/config.h
  2. +61 −10 lib/intern/albumlist/musicbrainz.c
  3. +29 −15 lib/intern/cover/lastfm.c
  4. BIN spec/capi/libtest_common.a
  5. +21 −1 spec/provider/runner.py
View
@@ -1,7 +1,7 @@
/**
* SECTION:config
* @short_description: Compiletime Information
- * @title: Config
+ * @title: Config
* @section_id:
* @stability: Stable
* @include: glyr/config.h
@@ -23,13 +23,19 @@
static const gchar * albumlist_musicbrainz_url (GlyrQuery * sets)
{
- return "http://musicbrainz.org/ws/1/release/?type=xml&artist=${artist}&releasetypes=\"Official\"";
+ return "http://musicbrainz.org/ws/1/release/?type=xml&artist=${artist}&limit=100";
}
/////////////////////////////////////////////////////////////
-#define ALBUM_BEGIN "<release type=\"Album Official\""
-#define ALBUM_ENDIN "\" id=\""
+//#define ALBUM_BEGIN "<release type=\"Album Official\""
+#define ALBUM_BEGIN "<release "
+#define TYPE_BEGIN "type=\""
+#define TYPE_ENDIN "\" "
+
+
+#define ARTIST_BEGIN "<name>"
+#define ARTIST_ENDIN "</name>"
#define TITLE_BEGIN "<title>"
#define TITLE_ENDIN "</title>"
@@ -57,21 +63,66 @@ static bool is_in_list (GList * list, const char * to_cmp)
/////////////////////////////////////////////////////////////
+static bool type_is_valid (const char * type)
+{
+ bool result = FALSE;
+ if (type == NULL)
+ return result;
+
+ static const char * valid_types[] = {
+ "Single Official",
+ "Album Official",
+ NULL
+ };
+
+ int check_idx = 0;
+ while(valid_types[check_idx]) {
+ if (g_strcmp0(valid_types[check_idx], type) == 0) {
+ result = TRUE;
+ break;
+ }
+ check_idx++;
+ }
+
+ return result;
+}
+
+/////////////////////////////////////////////////////////////
+
static GList * albumlist_musicbrainz_parse (cb_object * capo)
{
GList * result_list = NULL;
gchar * node = capo->cache->data;
- while (continue_search (g_list_length (result_list),capo->s) && (node = strstr (node+1,ALBUM_BEGIN) ) != NULL)
+ while (continue_search (g_list_length (result_list),capo->s) &&
+ (node = strstr (node + 1, ALBUM_BEGIN) ) != NULL)
{
- gchar * name = get_search_value (node,TITLE_BEGIN,TITLE_ENDIN);
- if (name != NULL && is_in_list (result_list,name) == false)
+ gchar * type = get_search_value (node, TYPE_BEGIN, TYPE_ENDIN);
+ if (type_is_valid (type))
{
- GlyrMemCache * result = DL_init();
- result->data = name;
- result->size = (result->data) ? strlen (result->data) : 0;
- result_list = g_list_prepend (result_list,result);
+ gchar * artist = get_search_value (node,ARTIST_BEGIN, ARTIST_ENDIN);
+ if (artist != NULL &&
+ levenshtein_strnormcmp (capo->s, capo->s->artist, artist) <= capo->s->fuzzyness) {
+
+
+ gchar * name = get_search_value (node,TITLE_BEGIN,TITLE_ENDIN);
+
+ if (name != NULL && is_in_list (result_list,name) == false)
+ {
+ GlyrMemCache * result = DL_init();
+ result->data = name;
+ result->size = (result->data) ? strlen (result->data) : 0;
+ result_list = g_list_prepend (result_list,result);
+ }
+ else
+ {
+ g_free (name);
+ }
+ }
+ g_free (artist);
}
+
+ g_free (type);
}
return result_list;
}
View
@@ -30,6 +30,7 @@ static const char * cover_lastfm_url (GlyrQuery * sets)
/////////////////////////////////
+#define ALBUM_NODE "<album>"
#define BAD_DEFAULT_IMAGE "http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png"
static GList * cover_lastfm_parse (cb_object *capo)
@@ -53,26 +54,39 @@ static GList * cover_lastfm_parse (cb_object *capo)
/* The result (perhaps) */
GList * result_list = NULL;
gchar * find = capo->cache->data;
- gsize tag_len = strlen (tag_ssize);
-
- while (continue_search (g_list_length (result_list),capo->s) && (find = strstr (find + tag_len, tag_ssize) ) != NULL)
+ while (continue_search (g_list_length (result_list),capo->s) && (find = strstr (find + sizeof(ALBUM_NODE), ALBUM_NODE) ) != NULL)
{
- gchar * url = get_search_value (find, (gchar*) tag_ssize, (gchar*) tag_esize);
- if (url != NULL)
- {
- if (strcmp (url,BAD_DEFAULT_IMAGE) != 0)
- {
- GlyrMemCache * result = DL_init();
- result->data = url;
- result->size = strlen (url);
- result_list = g_list_prepend (result_list,result);
- }
- else
+ gchar * artist = get_search_value (find, "<artist>", "</artist>");
+ gchar * album = get_search_value (find, "<name>", "</name>");
+
+ if (levenshtein_strnormcmp (capo->s, artist, capo->s->artist) <= capo->s->fuzzyness &&
+ levenshtein_strnormcmp (capo->s, album, capo->s->album) <= capo->s->fuzzyness) {
+
+ gchar * img_start = strstr(find, tag_ssize);
+
+ if (img_start != NULL)
{
- g_free (url);
+ gchar * url = get_search_value (find, (gchar*) tag_ssize, (gchar*) tag_esize);
+ if (url != NULL)
+ {
+ if (strcmp (url,BAD_DEFAULT_IMAGE) != 0)
+ {
+ GlyrMemCache * result = DL_init();
+ result->data = url;
+ result->size = strlen (url);
+ result_list = g_list_prepend (result_list,result);
+ }
+ else
+ {
+ g_free (url);
+ }
+ }
}
}
+
+ g_free (artist);
+ g_free (album);
}
return result_list;
}
View
Binary file not shown.
View
@@ -26,6 +26,21 @@
import executor
TESTS_DIR = 'tests'
+USAGE = '''
+Usage: runner.py [--help|-h] [--only|-o]
+
+--help | -h Print this text and exit.
+--only | -o Restrict test to certain providers and getters.
+
+ Example:
+
+ --only 'cover'
+ --only 'cover|albumlist'
+ --only 'cover:google'
+ --only 'cover:google,lastfm'
+
+With no arguments all tests are run.
+'''
def parse_only_argument(argument):
@@ -50,6 +65,11 @@ def main():
"""
Import all testfiles and run some of them.
"""
+
+ if '--help' in sys.argv or '-h' in sys.argv:
+ print(USAGE)
+ sys.exit(0)
+
test_modules = []
allowed_modules = {}
@@ -70,7 +90,7 @@ def main():
sys.exit(-1)
# Parse --only string, and pass it further
- if len(sys.argv) > 2 and sys.argv[1] == '--only':
+ if len(sys.argv) > 2 and ('--only' in sys.argv or '-o' in sys.argv):
allowed_modules = parse_only_argument(sys.argv[2])
# Now run through them, and execute all specified ones.

0 comments on commit ff3626f

Please sign in to comment.