static GList * lyrics_chartlyrics_parse(cb_object * capo) { GList * result_list = NULL; gchar * node = capo->cache->data; gint nodelen = (sizeof LYRIC_NODE) - 1; while(continue_search(g_list_length(result_list),capo->s) && (node = strstr(node + nodelen, LYRIC_NODE)) != NULL) { node += nodelen; gchar * artist = get_search_value(node,ARTIST_BEG,ARTIST_END); gchar * title = get_search_value(node,SONG_BEG,SONG_END); if(levenshtein_strnormcmp(capo->s,artist,capo->s->artist) <= capo->s->fuzzyness && levenshtein_strnormcmp(capo->s,title,capo->s->title) <= capo->s->fuzzyness) { gchar * lyric_id = get_search_value(node,LYRIC_ID_BEG,LYRIC_ID_END); gchar * lyric_checksum = get_search_value(node,LYRIC_CHECKSUM_BEG,LYRIC_CHECKSUM_END); if(lyric_id && lyric_checksum && strcmp(lyric_id,"0") != 0) { gchar * content_url = g_strdup_printf(CL_API_GET,lyric_id,lyric_checksum); GlyrMemCache * result = get_lyrics_from_results(capo->s,content_url); if(result != NULL) { result_list = g_list_prepend(result_list,result); } g_free(content_url); } g_free(lyric_id); g_free(lyric_checksum); } g_free(artist); g_free(title); } return result_list; }
static bool check_values (GlyrQuery * query, char * artist, char * album) { if (levenshtein_strnormcmp (query, query->artist, artist) <= query->fuzzyness && levenshtein_strnormcmp (query, query->album,album) <= query->fuzzyness) { return true; } return false; }
static GList * cover_lastfm_parse (cb_object *capo) { /* Handle size requirements (Default to large) */ const gchar * tag_ssize = NULL ; const gchar * tag_esize = "</image>"; /* find desired size */ if ( size_is_okay (300,capo->s->img_min_size,capo->s->img_max_size) ) tag_ssize = "<image size=\"extralarge\">"; else if ( size_is_okay (125,capo->s->img_min_size,capo->s->img_max_size) ) tag_ssize = "<image size=\"large\">"; else if ( size_is_okay (64, capo->s->img_min_size,capo->s->img_max_size) ) tag_ssize = "<image size=\"middle\">"; else if ( size_is_okay (34, capo->s->img_min_size,capo->s->img_max_size) ) tag_ssize = "<image size=\"small\">"; else if ( true || false ) tag_ssize = "<image size=\"extralarge\">"; /* The result (perhaps) */ GList * result_list = NULL; gchar * find = capo->cache->data; while (continue_search (g_list_length (result_list),capo->s) && (find = strstr (find + sizeof(ALBUM_NODE), ALBUM_NODE) ) != NULL) { 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) { 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; }
static gboolean validate_artist(cb_object * capo, gchar * backpointer) { gboolean i_shall_continue = false; if(backpointer != NULL) { char * span = strstr(backpointer,SPAN_BEGIN); if(span != NULL) { gchar * artist_beg = strstr(span,ARTIST_BEG); if(artist_beg != NULL) { artist_beg += (sizeof ARTIST_BEG) - 1; gchar * artist_end = strstr(artist_beg,ARTIST_END); if(artist_end != NULL) { gchar * artist_val = copy_value(artist_beg,artist_end); if(artist_val != NULL) { if(levenshtein_strnormcmp(capo->s,artist_val,capo->s->artist) <= capo->s->fuzzyness) { i_shall_continue = true; } g_free(artist_val); } } } } } return i_shall_continue; }
static GList * backdrops_htbackdrops_parse (cb_object * capo) { GList * result_list = NULL; gchar * img_list_start = strstr (capo->cache->data,"<images>"); if (img_list_start != NULL) { gchar * node = img_list_start; while (continue_search (g_list_length (result_list),capo->s) && (node = strstr (node,NODE) ) ) { node += sizeof NODE; gchar * dimensions = get_search_value (node,"<dimensions>","</dimensions>"); if (check_size (capo->s,dimensions) == TRUE) { gchar * validate_artist = get_search_value (node,"<mb_name>","</mb_name>"); if (levenshtein_strnormcmp (capo->s,validate_artist,capo->s->artist) <= capo->s->fuzzyness) { gchar * id = get_search_value (node,"<id>","</id>"); if (id != NULL) { GlyrMemCache * result = DL_init(); result->data = g_strdup_printf ("http://htbackdrops.org/api/"API_KEY_HTBACK"/download/%s/fullsize",id); result->size = strlen (result->data); result_list = g_list_prepend (result_list,result); g_free (id); } } g_free (validate_artist); } g_free (dimensions); } } return result_list; }
char *mbid_parse_data(GlyrMemCache *data, const char *lookup_entity, const char *find_entity, const char *compre_entity, GlyrQuery *qry) { char *key = g_strdup_printf("<%s ", lookup_entity); size_t keylen = strlen(key); char *node = data->data; char *result = NULL; char *find_ent_start = g_strdup_printf("<%s>", find_entity); char *find_ent_end = g_strdup_printf("</%s>", find_entity); while((node = strstr(node + keylen, key))) { char *name = get_search_value(node, find_ent_start, find_ent_end); if(name && levenshtein_strnormcmp(qry, name, compre_entity) <= qry->fuzzyness) { result = get_search_value(node, "id=\"", "\""); g_free(name); break; } g_free(name); } g_free(find_ent_start); g_free(find_ent_end); g_free(key); return result; }
static GList *add_result(GList *results, cb_object *capo, char *url, char *summary, char *release) { if(levenshtein_strnormcmp(capo->s, capo->s->album, release) <= capo->s->fuzzyness) { if(strlen(summary) >= 125) { GlyrMemCache *result = DL_init(); result->data = g_strdup_printf("%s\n \n \nRead more on: %s\n", summary, url); result->size = strlen(result->data); result->size -= strip_escapes(result->data, result->size); return g_list_prepend(results, result); } } return results; }
static gboolean check_title_value (GlyrQuery * s, const gchar * to_check) { gboolean result = FALSE; if (to_check != NULL) { gchar * artist = g_strrstr (to_check,"("); if (artist != NULL) { artist[0] = 0; artist++; gchar * end_bracket = strchr (artist,')'); if (end_bracket) { end_bracket[0] = 0; } result = (levenshtein_strnormcmp (s,artist,s->artist) <= s->fuzzyness && levenshtein_strnormcmp (s,to_check,s->title) <= s->fuzzyness); } } return result; }
static GList * cover_allmusic_parse(cb_object * capo) { GList * result_list = NULL; if(strstr(capo->cache->data,TITLE_TAG) != NULL) { /* Horray, directly hit the page */ GlyrMemCache * result = parse_cover_page(capo->cache); result_list = g_list_prepend(result_list, result); return result_list; } gchar * search_begin = NULL; if((search_begin = strstr(capo->cache->data, SEARCH_TREE_BEGIN)) == NULL) { /* No page. Crap. */ return NULL; } gsize nodelen = (sizeof SEARCH_NODE) - 1; gchar * node = search_begin; while(continue_search(g_list_length(result_list),capo->s) && (node = strstr(node + nodelen,SEARCH_NODE))) { gchar * url = get_search_value(node,SEARCH_NODE,SEARCH_DELM); if(url != NULL) { /* We have the URL - now check the artist to be the one */ gchar * artist = get_search_value(node + nodelen,ARTIST_PART, ARTIST_END); if(artist != NULL) { if(levenshtein_strnormcmp(capo->s,capo->s->artist,artist) <= capo->s->fuzzyness) { GlyrMemCache * dl_cache = download_single(url,capo->s,"<div class=\"artist\">"); if(dl_cache != NULL) { GlyrMemCache * result = parse_cover_page(dl_cache); if(result != NULL && result->data) { result->dsrc = g_strdup(url); result_list = g_list_prepend(result_list,result); } DL_free(dl_cache); } } g_free(artist); } g_free(url); } } return result_list; }
// Compare response, so lyricswiki's search did not fool us static gboolean lv_cmp_content(const gchar * to_artist, const gchar * to_title, cb_object * capo) { gboolean res = false; if(to_artist && to_title && capo) { gchar * tmp_artist = copy_value(to_artist,strstr(to_artist,"</artist>")); if(tmp_artist != NULL) { gchar * tmp_title = copy_value(to_title, strstr(to_title ,"</song>" )); if(tmp_title != NULL) { /* levenshtein_strnormcmp takes care of those brackets */ if((levenshtein_strnormcmp(capo->s,capo->s->artist,tmp_artist) <= capo->s->fuzzyness && levenshtein_strnormcmp(capo->s,capo->s->title, tmp_title) <= capo->s->fuzzyness )) { res = true; } g_free(tmp_title); } g_free(tmp_artist); } } return res; }
static GList * cover_albumart_parse (cb_object * capo) { GList * result_list = NULL; gchar * node = strstr (capo->cache->data,NODE_START); if (node != NULL) { /* Decide what size we want */ gsize size_it = 2; if (capo->s->img_max_size < 450 && capo->s->img_max_size != -1 && capo->s->img_min_size < 160) { size_it = 1; } /* Go through all nodes */ while (continue_search (g_list_length (result_list),capo->s) && (node = strstr (node + (sizeof NODE_NEXT) - 1,NODE_NEXT) ) ) { gchar * img_tag = node; gchar * img_end = NULL; gchar * album_name = get_search_value (node,"title=\"","\""); if (levenshtein_strnormcmp (capo->s,album_name,capo->s->album) <= capo->s->fuzzyness) { for (gsize it = 0; it < size_it; it++, img_tag += (sizeof AMZ) - 1) { if ( (img_tag = strstr (img_tag,AMZ) ) == NULL) { break; } } if ( (img_end = strstr (img_tag,IMG_FORMAT) ) != NULL) { gchar * img_url = copy_value (img_tag,img_end); if (img_url != NULL) { GlyrMemCache * result = DL_init(); result->data = g_strdup_printf (AMZ"%s"IMG_FORMAT, img_url); result->size = strlen (result->data); result_list = g_list_prepend (result_list,result); g_free (img_url); } } } g_free (album_name); } } return result_list; }
static gboolean approve_content(GlyrQuery * query, gchar * ref) { gboolean result = FALSE; if(ref != NULL) { gchar * artist_html = get_search_value(ref,SEARCH_DELIM,END_OF_ARTIST); if(artist_html != NULL) { if(levenshtein_strnormcmp(query,artist_html,query->artist) <= query->fuzzyness) { result = TRUE; } g_free(artist_html); } } return result; }
GList * lyrics_lyrixat_parse (cb_object * capo) { /* lyrix.at does not offer any webservice -> use the searchfield to get some results */ GList * result_list = NULL; gchar * search_begin_tag = capo->cache->data; gint ctr = 0; while (continue_search (g_list_length (result_list),capo->s) && (search_begin_tag = strstr (search_begin_tag+1,SEARCH_START_TAG) ) && MAX_TRIES >= ctr++) { gchar * url_tag = search_begin_tag; url_tag = strstr (url_tag,URL_TAG_BEGIN); if (url_tag != NULL) { gchar * title_tag = strstr (url_tag,URL_TAG_ENDIN); if (title_tag) { gchar * title_end = strstr (title_tag,TITLE_END); if (title_end != NULL) { gsize tag_end_len = (sizeof URL_TAG_ENDIN) - 1; gchar * title = copy_value (title_tag + tag_end_len,title_end); if (title != NULL) { if (levenshtein_strnormcmp (capo->s,title,capo->s->title) <= capo->s->fuzzyness) { gchar * url_part = copy_value (url_tag+strlen (URL_TAG_BEGIN),title_tag); if (url_part != NULL) { gchar * url = g_strdup_printf ("http://lyrix.at/de%s",url_part); parse_lyrics_page (url,&result_list,capo); g_free (url); g_free (url_part); } } g_free (title); } } } } } return result_list; }
size_t glyr_levenshtein_strnormcmp(const char * string, const char * other) { return levenshtein_strnormcmp(NULL,string,other); }
static bool check_artist_album(GlyrQuery *q, const char *artist) { return levenshtein_strnormcmp(q, q->artist, artist) <= q->fuzzyness; }
const gchar * get_mbid_from_xml (GlyrQuery * s, GlyrMemCache * c, gint * offset) { if (c==NULL || s==NULL || offset==NULL) return NULL; const gchar * searchterm = NULL; const gchar * checkstring = NULL; const gchar * comparestr = NULL; switch (please_what_type (s) ) { case GLYR_TYPE_TAG_TITLE: checkstring = "<title>"; searchterm = "<track "; comparestr = s->title; break; case GLYR_TYPE_TAG_ALBUM: checkstring = "<title>"; searchterm = "<release "; comparestr = s->album; break; case GLYR_TYPE_TAG_ARTIST: checkstring = "<name>"; searchterm = "<artist "; comparestr = s->artist; break; default: glyr_message (1,s,"Warning: (tags/musicbrainz.c) Unable to determine type.\n"); } const gchar * mbid = NULL; if (searchterm != NULL) { gchar * node = c->data + *offset; gchar * search_check = NULL; gsize nlen = (sizeof ID_BEGIN) - 1; gsize clen = strlen (checkstring); while (node && (node = strstr (node,searchterm) ) && mbid == NULL) { if (! (node = strstr (node,ID_BEGIN) ) ) break; if (! (search_check = strstr (node,checkstring) ) ) break; search_check += clen; gchar * to_compare = copy_value (search_check,strstr (search_check,"</") ); if (to_compare != NULL) { if (levenshtein_strnormcmp (s,to_compare,comparestr) <= s->fuzzyness) { mbid = (gchar*) copy_value (node+nlen,strchr (node+nlen,'"') ); } g_free (to_compare); } node += (sizeof ID_BEGIN) - 1; } *offset = node - c->data; } return mbid; }
static GList * gt_guitaretabs_parse (cb_object * capo) { GList * result_list = NULL; gchar * begin_search = strstr (capo->cache->data,SEARCH_RESULTS_BEGIN); if (begin_search != NULL) { /* End need to assure we don't get over the search results */ gchar * endin_search = strstr (begin_search,SEARCH_RESULTS_ENDIN); if (endin_search != NULL) { /* Go through all search results */ gchar * node = begin_search; gsize nodelen = (sizeof SEARCH_NODE) - 1; while (continue_search (g_list_length (result_list),capo->s) && (node = strstr (node + nodelen, SEARCH_NODE) ) != NULL && node <= endin_search) { gchar * artist = get_search_value (node,ARTIST_BEGIN,ARTIST_END); node = strstr (node + nodelen, SEARCH_NODE); if (node != NULL) { gchar * url = get_search_value (node,SEARCH_NODE,URL_END); gchar * title = get_search_value (node,TITLE_BEGIN,TITLE_ENDIN); if (title != NULL) { gchar * delim = g_strrstr (title," chords"); if (delim == NULL) { delim = g_strrstr (title," tab"); } if (delim != NULL) { delim[0] = 0; } } /* Check if this is the item we actually search */ if (levenshtein_strnormcmp (capo->s,title, capo->s->title ) <= capo->s->fuzzyness && levenshtein_strnormcmp (capo->s,artist,capo->s->artist) <= capo->s->fuzzyness) { /* Build resulting url */ gchar * result_url = g_strdup_printf ("%s%s",GT_BASE,url); /* Go and parse it */ GlyrMemCache * result = parse_single_page (capo->s,result_url); if (result != NULL) { result_list = g_list_prepend (result_list,result); } g_free (result_url); } g_free (url); g_free (title); } g_free (artist); } } } return result_list; }