static GList * photos_flickr_parse (cb_object * capo) { gchar * ph_begin = capo->cache->data; GList * result_list = NULL; while (continue_search (g_list_length (result_list),capo->s) && (ph_begin=strstr (ph_begin,LINE_BEGIN) ) != NULL) { gchar * ph_end = strstr (ph_begin,LINE_ENDIN); if (ph_end != NULL) { gchar * linebf = copy_value (ph_begin,ph_end); if (linebf != NULL) { gchar * ID = get_search_value (linebf, "id=\"","\""); gchar * SC = get_search_value (linebf, "secret=\"","\""); gchar * SV = get_search_value (linebf, "server=\"","\""); gchar * FR = get_search_value (linebf, "farm=\"","\""); GlyrMemCache * cache = DL_init(); cache->data = g_strdup_printf ("http://farm%s.static.flickr.com/%s/%s_%s.jpg",FR,SV,ID,SC); cache->size = strlen (cache->data); result_list = g_list_prepend (result_list,cache); g_free (ID); g_free (SC); g_free (SV); g_free (FR); g_free (linebf); } } } return result_list; }
static gboolean size_fits(GlyrQuery *s, gchar **ref) { gboolean result = FALSE; if(ref != NULL) { gchar *search_ptr = ref[0]; if(search_ptr != NULL) { search_ptr = strchr(search_ptr, '"'); gint ratio = 0; gchar *width_string = get_search_value(search_ptr, "width=\"", "\""); gchar *height_string = get_search_value(search_ptr, "height=\"", "\""); if(width_string && height_string) { ratio = (strtol(width_string, NULL, 10) + strtol(height_string, NULL, 10)) / 2; } g_free(width_string); g_free(height_string); gboolean original_size_allowed = TRUE; if(g_strstr_len(ref[0], 100, "original") != NULL) { /* Deny extremelly large images by default, except explicitely wanted */ if(!(ratio >= 1000 && s->img_min_size >= 1000 && s->img_max_size == -1)) { original_size_allowed = FALSE; } } if(size_is_okay(ratio, s->img_min_size, s->img_max_size) == TRUE && original_size_allowed == TRUE) { result = TRUE; } search_ptr = strchr(search_ptr, '>'); } ref[0] = search_ptr + 1; } return result; }
static GList *similar_song_lastfm_parse(cb_object *capo) { GList *results = NULL; gchar *begin = capo->cache->data; while(continue_search(g_list_length(results), capo->s) && (begin = strstr(begin, TRACK_BEGIN)) != NULL) { gchar *track = get_search_value(begin, NAME_BEGIN, NAME_ENDIN); gchar *match = get_search_value(begin, MATCH_BEGIN, MATCH_ENDIN); gchar *url = get_search_value(begin, URL_BEGIN, URL_ENDIN); gchar *artist = get_search_value(strstr(begin, ARTIST_BEGIN), NAME_BEGIN, NAME_ENDIN); if(artist && track) { GlyrMemCache *result = DL_init(); result->data = g_strdup_printf("%s\n%s\n%s\n%s\n", track, artist, match, url); result->size = strlen(result->data); results = g_list_prepend(results, result); } g_free(track); g_free(artist); g_free(match); g_free(url); begin += sizeof(TRACK_BEGIN) - 1; } return results; }
static GList *photos_discogs_parse(cb_object *capo) { GList *result_list = NULL; /* Jump to the very first node 'directly' */ gchar *node = capo->cache->data; while(continue_search(g_list_length(result_list), capo->s) && (node = strstr(node + (sizeof NODE) - 1, NODE)) != NULL) { char *artist_album = get_search_value(node, TITLE_SUBNODE, ENDOF_SUBNODE); if(artist_album && check_artist_album(capo->s, artist_album)) { char *thumb_url = get_search_value(node, THUMB_SUBDNOE, ENDOF_SUBNODE); if(thumb_url) { GlyrMemCache *p = transform_url(capo, thumb_url); if(p != NULL) { result_list = g_list_prepend(result_list, p); } g_free(thumb_url); } } g_free(artist_album); } return result_list; }
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; }
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 GList * guitartabs_chordie_parse (cb_object * capo) { GList * result_list = NULL; gchar * search_begin = strstr (capo->cache->data,RESULTS_BEGIN); if (search_begin != NULL) { gchar * search_ending = strstr (search_begin,RESULTS_ENDIN); if (search_ending != NULL) { gchar * node = search_begin; gsize nodelen = (sizeof NODE) - 1; while (continue_search (g_list_length (result_list),capo->s) && (node = strstr (node + nodelen, NODE) ) != NULL && node >= search_begin && node <= search_ending) { gchar * url = get_search_value (node,NODE,"\" "); if (url != NULL) { gchar * name_value = get_search_value (node,"\">","</a>"); if (check_title_value (capo->s, name_value) == TRUE) { gchar * content_url = g_strdup_printf ("%s%s",BASE_URL,url); GlyrMemCache * result = parse_result_page (capo->s,content_url); if (result != NULL) { result_list = g_list_prepend (result_list,result); } g_free (content_url); } g_free (name_value); g_free (url); } } } } 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 * 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 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; }
static GlyrMemCache * find_long_version(GlyrQuery * s, GlyrMemCache * to_parse) { GlyrMemCache * result = NULL; gchar * root = strstr(to_parse->data,ROOT); if(root != NULL) { gchar * url_id = get_search_value(root,ROOT_URL,END_OF_ROOT); if(url_id != NULL) { char * url = g_strdup_printf(ROOT_URL"%s",url_id); if(url != NULL) { GlyrMemCache * dl = download_single(url,s,NULL); if(dl != NULL) { result = parse_bio_page(dl,url); DL_free(dl); } g_free(url); } g_free(url_id); } } return result; }
static void parse_review_site(GlyrQuery * s, GlyrMemCache * cache, GList ** result_items) { if(cache != NULL) { gsize nodelen = (sizeof REVIEW_START) - 1; gchar * node = cache->data; while(continue_search(g_list_length(*result_items),s) && (node = strstr(node+nodelen,REVIEW_START)) != NULL) { gchar * data = get_search_value(node,REVIEW_START,REVIEW_END); if(data != NULL) { GlyrMemCache * item = DL_init(); gchar * kill_br = strreplace(data," <br />\n",""); item->data = strreplace(kill_br,". ",".\n"); item->size = strlen(item->data); item->dsrc = g_strdup(cache->dsrc); *result_items = g_list_prepend(*result_items, item); g_free(kill_br); g_free(data); } } DL_free(cache); } }
static GList * photos_rhapsody_parse (cb_object * capo) { GList * result_list = NULL; gchar * delim_beg = strstr (capo->cache->data,DELIM_BEG); gchar * delim_end = strstr (capo->cache->data,DELIM_END); if (delim_beg && delim_end) { gchar * node = delim_beg; gsize nd_len = (sizeof NODE) - 1; while (continue_search (g_list_length (result_list),capo->s) && (node = strstr (node + nd_len, NODE) ) && node < delim_end) { node += nd_len; if (check_size (capo->s,node) == TRUE) { gchar * url = get_search_value (node,"src=\"","\""); if (url != NULL) { GlyrMemCache * result = DL_init(); result->data = url; result->size = strlen (url); result_list = g_list_prepend (result_list,result); } } } } return result_list; }
GList * parse_result_page(GlyrQuery * query, GlyrMemCache * to_parse) { GList * result_list = NULL; gchar * node = to_parse->data; while(continue_search(g_list_length(result_list),query) && (node = strstr(node,LYR_NODE))) { node += (sizeof LYR_NODE); gchar * lyr = get_search_value(node,LYR_BEGIN,LYR_ENDIN); gchar * beautiness_test = beautify_string(lyr); if(beautiness_test != NULL && beautiness_test[0]) { if(lyr != NULL && strstr(lyr,BAD_STRING) == NULL && strstr(lyr,EXTERNAL_LINKS) == NULL) { GlyrMemCache * result = DL_init(); result->data = lyr; result->size = strlen(result->data); result->dsrc = g_strdup(to_parse->dsrc); result_list = g_list_prepend(result_list,result); } } else { g_free(lyr); } g_free(beautiness_test); } return result_list; }
static gboolean check_size(GlyrQuery * s, gchar * ref) { gboolean result = FALSE; if(ref != NULL) { gchar * width_str = get_search_value(ref,"width=\"","\""); gchar * height_str = get_search_value(ref,"height=\"","\""); if(width_str && height_str) { gint width = strtol(width_str, NULL,10); gint height = strtol(height_str,NULL,10); result = size_is_okay((width+height)/2,s->img_min_size,s->img_max_size); } g_free(width_str); g_free(height_str); } return result; }
static bool check_size (GlyrQuery * q, char * node) { bool rc = false; char * width = get_search_value (node,"width=\"", "\""); char * height = get_search_value (node,"height=\"","\""); if (width && height) { int w = strtol (width, NULL,10); int h = strtol (height,NULL,10); if (size_is_okay (w,q->img_min_size,q->img_max_size) && size_is_okay (h,q->img_min_size,q->img_max_size) ) rc = true; } g_free (width); g_free (height); return rc; }
/* Wrap around the (a bit more) generic versions */ static GList * relations_musicbrainz_parse (cb_object * capo) { GList * results = NULL; gint mbid_marker = 0; while (continue_search (g_list_length (results), capo->s) ) { GlyrMemCache * infobuf = generic_musicbrainz_parse (capo,&mbid_marker,"url-rels"); if (infobuf == NULL) { break; } gsize nlen = (sizeof RELATION_BEGIN_TYPE) - 1; gchar * node = strstr (infobuf->data,RELATION_TARGLYR_GET_TYPE); if (node != NULL) { gint ctr = 0; while (continue_search (ctr,capo->s) && (node = strstr (node+nlen,RELATION_BEGIN_TYPE) ) ) { node += nlen; gchar * target = get_search_value (node,"target=\"","\""); gchar * type = get_search_value (node,"type=\"","\""); if (type != NULL && target != NULL) { GlyrMemCache * tmp = DL_init(); tmp->data = g_strdup_printf ("%s:%s",type,target); tmp->size = strlen (tmp->data); tmp->dsrc = g_strdup (infobuf->dsrc); results = g_list_prepend (results,tmp); ctr++; g_free (type); g_free (target); } } } DL_free (infobuf); } return results; }
static GlyrMemCache * parse_bio_page(GlyrMemCache * to_parse, gchar * url) { GlyrMemCache * result = NULL; gchar * text = get_search_value(to_parse->data,IMG_BEGIN,IMG_ENDIN); if(text != NULL) { result = DL_init(); result->data = text; result->size = strlen(result->data); result->dsrc = g_strdup(url); } return result; }
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 GList * cover_rhapsody_parse(cb_object * capo) { GList * result_list = NULL; gchar * delim_beg = strstr(capo->cache->data,DELIM_BEG); gchar * delim_end = strstr(capo->cache->data,DELIM_END); GlyrMemCache * special_size = NULL; if(delim_beg && delim_end) { gchar * node = delim_beg; gsize nd_len = (sizeof NODE) - 1; while(continue_search(g_list_length(result_list),capo->s) && (node = strstr(node + nd_len, NODE)) && node < delim_end) { node += nd_len; if(check_size(capo->s,node) == TRUE) { gchar * url = get_search_value(node,"src=\"","\""); if(url != NULL) { GlyrMemCache * result = DL_init(); result->data = url; result->size = strlen(url); result_list = g_list_prepend(result_list,result); /* A very cool hack. Thanks Bansheeproject! */ if(strstr(result->data,HACK_SIZE) != NULL) { special_size = result; } } } } /* Awesome hack continues.. */ if(special_size != NULL) { /* Note: Prepend the large size at begin: * If only one item requested it will just * be thrown away (the small size) */ GlyrMemCache * result = DL_init(); result->data = strreplace(special_size->data,HACK_SIZE,HIGH_SIZE); result->size = strlen(result->data); result_list = g_list_prepend(result_list,result); } } 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; }
static GlyrMemCache * get_lyrics_from_results(GlyrQuery * s, const gchar * url) { GlyrMemCache * result = NULL; GlyrMemCache * dl_cache = download_single(url,s,NULL); if(dl_cache != NULL) { gchar * text = get_search_value(dl_cache->data,LYRIC_TEXT_BEG,LYRIC_TEXT_END); if(text != NULL) { result = DL_init(); result->data = text; result->size = strlen(text); result->dsrc = g_strdup(url); } DL_free(dl_cache); } return result; }
static GlyrMemCache * parse_single_page (GlyrQuery * s, const gchar * url) { GlyrMemCache * result = NULL; GlyrMemCache * tab_cache = download_single (url,s,NULL); if (tab_cache != NULL) { gchar * content = get_search_value (tab_cache->data,"<pre>","</pre>"); if (content != NULL) { result = DL_init(); result->data = content; result->size = strlen (content); result->dsrc = g_strdup (url); } DL_free (tab_cache); } return result; }
static GList * similar_lastfm_parse (cb_object * capo) { GList * results = NULL; gchar * find = capo->cache->data; while (continue_search (g_list_length (results),capo->s) && (find = strstr (find+1, "<artist>") ) != NULL) { gchar * name = get_search_value (find,NAME_BEGIN,NAME_ENDIN); gchar * match = get_search_value (find,MATCH_BEGIN,MATCH_ENDIN); gchar * url = get_search_value (find,URL_BEGIN,URL_ENDIN); gchar * img_s = get_search_value (find,IMAGE_S_BEGIN,IMAGE_ENDIN); gchar * img_m = get_search_value (find,IMAGE_M_BEGIN,IMAGE_ENDIN); gchar * img_l = get_search_value (find,IMAGE_L_BEGIN,IMAGE_ENDIN); gchar * img_e = get_search_value (find,IMAGE_E_BEGIN,IMAGE_ENDIN); gchar * img_x = get_search_value (find,IMAGE_X_BEGIN,IMAGE_ENDIN); gchar * composed = g_strdup_printf ("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",name,match,url,img_s,img_m,img_l,img_e,img_x); if (composed != NULL) { GlyrMemCache * result = DL_init(); result->data = composed; result->size = strlen (composed); results = g_list_prepend (results, result); } if (results != NULL) { results = g_list_reverse (results); } g_free (name); g_free (match); g_free (url); g_free (img_s); g_free (img_m); g_free (img_l); g_free (img_e); g_free (img_x); } return results; }
static GList * lyrics_lyricswiki_parse(cb_object * capo) { GList * result_list = NULL; if(strstr(capo->cache->data,NOT_FOUND) == NULL && lv_cmp_content(strstr(capo->cache->data,"<artist>"),strstr(capo->cache->data,"<song>"),capo)) { gchar * wiki_page_url = get_search_value(capo->cache->data,"<url>","</url>"); if(wiki_page_url != NULL) { GlyrMemCache * new_cache = download_single(wiki_page_url,capo->s,NULL); if(new_cache != NULL) { result_list = parse_result_page(capo->s,new_cache); DL_free(new_cache); } g_free(wiki_page_url); } } return result_list; }
static GList * cover_slothradio_parse (cb_object * capo) { GList * result_list = NULL; const char * bound_start = strstr (capo->cache->data,RESULT_LIST_START); if (bound_start == NULL) return NULL; const char * bound_end = strstr (bound_start,RESULT_LIST_END); if (bound_end == NULL) return NULL; char * node = (char*) bound_start; while ( (node = strstr (node + sizeof (RESULT_ITEM_START),RESULT_ITEM_START) ) != NULL) { if (node >= bound_end) break; char * url = get_search_value (node,"img src=\"","\""); if (url != NULL) { if (check_size (capo->s,node) ) { GlyrMemCache * result = DL_init(); result->dsrc = g_strdup (capo->url); result->data = url; result->size = strlen (url); result_list = g_list_prepend (result_list,result); } else { g_free (url); } } if (continue_search (g_list_length (result_list),capo->s) == false) break; } return result_list; }
GList * generic_picsearch_parse(cb_object * capo) { GList * result_list = NULL; gchar * node = capo->cache->data; gint nodelen = (sizeof NODE) - 1; node = strstr(node,"<div id=\"results_table\">"); int items = 0, tries = 0; const int MAX_TRIES = capo->s->number * 4; while(continue_search(items,capo->s) && (node = strstr(node, "<a href=\"")) && tries++ < MAX_TRIES) { node += nodelen; gchar * details_url = get_search_value(node,"<a href=\"","\" "); if(details_url != NULL && strncmp(details_url,NODE_NEEDS_TO_BEGIN,sizeof(NODE_NEEDS_TO_BEGIN)-1) == 0) { gchar * full_url = g_strdup_printf("www.picsearch.com%s",details_url); if(full_url != NULL) { GlyrMemCache * to_parse = download_single(full_url,capo->s,NULL); if(to_parse != NULL) { GlyrMemCache * result = parse_details_page(to_parse); if(result != NULL) { result_list = g_list_prepend(result_list,result); items++; } DL_free(to_parse); } g_free(full_url); } g_free(details_url); } } return result_list; }
GList * parse_result_page (GlyrQuery * query, GlyrMemCache * to_parse) { GList * result_list = NULL; gchar * node = to_parse->data; while (continue_search (g_list_length (result_list),query) && (node = strstr (node,LYR_NODE))) { node += (sizeof LYR_NODE); char *script_tag = strstr(node, LYR_SCRIPT_TAG); char *end_tag = strstr(node, LYR_ENDIN); if(script_tag && script_tag < end_tag) { node = script_tag + sizeof(LYR_SCRIPT_TAG) - 1; } bool is_instrumental = strstr(node, LYR_INSTRUMENTAL) != NULL; gchar * lyr = get_search_value (node,LYR_BEGIN,LYR_ENDIN); gchar * beautiness_test = beautify_string (lyr); if (is_instrumental || (beautiness_test != NULL && beautiness_test[0])) { if (is_instrumental || (lyr != NULL && strstr (lyr,BAD_STRING) == NULL && strstr (lyr,EXTERNAL_LINKS) == NULL)) { GlyrMemCache * result = DL_init(); if(is_instrumental) result->data = g_strdup("Instrumental"); else result->data = lyr; result->size = strlen (result->data); result->dsrc = g_strdup (to_parse->dsrc); result_list = g_list_prepend (result_list,result); } } else { g_free (lyr); } g_free (beautiness_test); } return result_list; }
static GlyrMemCache * parse_result_page (GlyrQuery * s, gchar * content_url) { GlyrMemCache * result = NULL; if (content_url != NULL) { GlyrMemCache * dl_cache = download_single (content_url,s,NULL); if (dl_cache != NULL) { gchar * content = get_search_value (dl_cache->data,"<div class=\"song\">","</div>"); if (content != NULL) { result = DL_init(); result->data = content; result->size = strlen (content); result->dsrc = g_strdup (content_url); } DL_free (dl_cache); } } return result; }
static GlyrMemCache * parse_details_page(GlyrMemCache * to_parse) { GlyrMemCache * result = NULL; if(to_parse != NULL) { char * start = strstr(to_parse->data,IMG_HOOK); if(start != NULL) { char * img_url = get_search_value(start,IMG_HOOK_BEGIN,IMG_HOOK_ENDIN); puts(img_url); if(img_url != NULL) { result = DL_init(); result->data = img_url; result->size = strlen(img_url); result->dsrc = g_strdup(to_parse->dsrc); } } } return result; }