Esempio n. 1
0
File: generic.c Progetto: meh/glyr
/* Simple finalizer template sufficient for most */
GList * generic_txt_finalizer(GlyrQuery * settings, GList * input_list, gboolean * stop_me, GLYR_DATA_TYPE type, GList ** result_list)
{
	gboolean add_to_list = TRUE;
	GList * almost_copied = NULL;
	for(GList * elem = input_list; elem; elem = elem->next)
	{
		GlyrMemCache * item = elem->data;
		if(is_in_result_list(item,result_list[0]) == FALSE && add_to_list == TRUE)
		{
			/* Set to some default type */
			if(item->type == GLYR_TYPE_NOIDEA)
			{
				item->type = type;
			}

			/* call user defined callback */
			GLYR_ERROR response = GLYRE_OK;
			if(settings->callback.download)
			{
				/* Call the usercallback */
				response = settings->callback.download(item,settings);
			}

			if(response != GLYRE_SKIP && response != GLYRE_STOP_PRE)
			{
				almost_copied = g_list_prepend(almost_copied,item);
			}
			else
			{
				DL_free(item);
				item = NULL;
			}

			if(response == GLYRE_STOP_POST || response == GLYRE_STOP_PRE)
			{
				add_to_list = FALSE;
				*stop_me = TRUE;
			}
		}
		else
		{
			settings->itemctr--;
			DL_free(item);
			item = NULL;
		}
	}
	return almost_copied;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
File: metallum.c Progetto: meh/glyr
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);
	}
}
Esempio n. 4
0
static GList * local_provider_parse(cb_object * capo)
{
	GList * converter_list = NULL;
	if(capo->s && capo->s->local_db != NULL)
	{
		gint counter = 0;
		GlyrMemCache * head = glyr_db_lookup(capo->s->local_db,capo->s);
		while(head != NULL)
		{
			if(counter < capo->s->number)
			{
				converter_list = g_list_prepend(converter_list,head);
				head->cached = TRUE;
				head = head->next;
				counter++;
			}
			else
			{
				GlyrMemCache * to_delete = head;
				head = head->next;
				DL_free(to_delete);
			}
		}
	}
	return converter_list;
}
Esempio n. 5
0
static void parse_lyrics_page (const gchar * url, GList ** result_list, cb_object * capo)
{
    GlyrMemCache * lyrcache = download_single (url,capo->s,"<!-- eBay Relevance Ad -->");
    if (lyrcache != NULL)
    {
        gchar * lyr_begin = strstr (lyrcache->data,LYRIC_BEGIN);
        if (lyr_begin != NULL)
        {
            gchar * lyr_endin = strstr (lyr_begin,"</div>");
            if (lyr_endin != NULL)
            {
                gchar * lyrics = copy_value (lyr_begin,lyr_endin);
                if (lyrics != NULL)
                {
                    GlyrMemCache * result = DL_init();
                    result->data = strreplace (lyrics,"<br />","");
                    result->size = strlen (result->data);
                    result->dsrc = g_strdup (url);
                    *result_list = g_list_prepend (*result_list,result);
                }
                g_free (lyrics);
            }
        }
        DL_free (lyrcache);
    }
}
Esempio n. 6
0
static GList * ainfo_allmusic_parse(cb_object * capo)
{
	GList * result_list = NULL;

	/* Are we already on the biopage? */
	if(strstr(capo->cache->data, "<!--Begin Biography -->"))
	{
		GlyrMemCache * info_long = find_long_version(capo->s,capo->cache);
		if(info_long != NULL)
		{
			result_list = g_list_prepend(result_list,info_long);
		}
		return result_list;
	}

	gchar * search_begin = NULL;

	/* Hello, anybody there? */
	if((search_begin = strstr(capo->cache->data, SEARCH_TREE_BEGIN)) == NULL)
	{
		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 * end_of_url = strstr(node,SEARCH_DELIM);
		if(approve_content(capo->s,end_of_url) == TRUE)
		{
			gchar * url = copy_value(node + nodelen, end_of_url);
			if(url != NULL)
			{
				gchar * biography_url = g_strdup_printf("%s/biography",url);
				GlyrMemCache * dl_cache = download_single(biography_url,capo->s,NULL);
				if(dl_cache != NULL)
				{
					GlyrMemCache * content = parse_bio_page(dl_cache,biography_url);
					if(content != NULL)
					{
						result_list = g_list_prepend(result_list,content);
					}
					DL_free(dl_cache);
				}
				g_free(biography_url);
				g_free(url);
			}
		}
	}
	return result_list;
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
static GList * lyrics_lyrdb_parse (cb_object * capo)
{
    gchar *slash = NULL;
    GList * result_list = NULL;

    if ( (slash = strchr (capo->cache->data,'\\') ) != NULL)
    {
        gchar * uID = copy_value (capo->cache->data,slash);
        if (uID != NULL)
        {
            gchar * lyr_url = g_strdup_printf ("http://webservices.lyrdb.com/getlyr.php?q=%s",uID);
            if (lyr_url != NULL)
            {
                GlyrMemCache * new_cache = download_single (lyr_url,capo->s,NULL);
                if (new_cache != NULL)
                {
                    gsize i = 0;
                    gchar * buffer = g_malloc0 (new_cache->size + 1);
                    for (i = 0; i < new_cache->size; i++)
                    {
                        buffer[i] = (new_cache->data[i] == '\r') ?
                                    ' ' :
                                    new_cache->data[i];
                    }
                    buffer[i] = 0;

                    if (i != 0)
                    {
                        GlyrMemCache * result = DL_init();
                        result->data = buffer;
                        result->size = i;
                        result->dsrc = g_strdup (lyr_url);

                        result_list = g_list_prepend (result_list,result);
                    }

                    DL_free (new_cache);
                }
                g_free (lyr_url);
            }
            g_free (uID);
        }
    }
    return result_list;
}
Esempio n. 9
0
static GList * lyrics_lyricstime_parse(cb_object * capo)
{
	GList * rList = NULL;
	char * start = capo->cache->data;
	if(start != NULL)
	{
		gchar * div_end = strstr(start,SEARCH_ENDIN);
		gchar * node = capo->cache->data;
		gchar * backpointer = node;
		gsize nlen = (sizeof NODE_BEGIN) - 1;

		while(continue_search(g_list_length(rList),capo->s) && (node = strstr(node+nlen,NODE_BEGIN)) != NULL)
		{
			if(div_end >= node)
				break;

			if(validate_artist(capo,backpointer) == TRUE)
			{
				gchar * end_of_url = strstr(node+nlen,NODE_ENDIN);
				if(end_of_url != NULL)
				{
					gchar * url = copy_value(node+nlen,end_of_url);
					if(url != NULL)
					{
						gchar * full_url = g_strdup_printf("http://www.lyricstime.com%s",url);
						GlyrMemCache * dl_cache = download_single(full_url,capo->s,NULL);
						if(dl_cache)
						{
							GlyrMemCache * parsed_cache = parse_page(dl_cache,capo);
							if(parsed_cache != NULL)
							{
								rList = g_list_prepend(rList,parsed_cache);
							}
							DL_free(dl_cache);
							g_free(full_url);
						}
						g_free(url);
					}
				}
			}
			backpointer = node;
		}
	}
	return rList;
}
Esempio n. 10
0
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;
}
Esempio n. 11
0
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;
}
Esempio n. 12
0
/* Wrap around the (a bit more) generic versions */
static GList * tags_musicbrainz_parse (cb_object * capo)
{
    GList * results = NULL;
    gint mbid_marker = 0;
    while (continue_search (g_list_length (results), capo->s) )
    {
        GlyrMemCache  * info = generic_musicbrainz_parse (capo,&mbid_marker,"tags");
        if (info == NULL)
        {
            break;
        }

        gint type_num = please_what_type (capo->s);
        gchar * tag_node = info->data;
        while ( (tag_node = strstr (tag_node + 1,"<tag") ) )
        {
            gchar * tag_begin = strchr (tag_node+1,'>');
            if (!tag_begin)
                continue;

            tag_begin++;
            gchar * tag_endin = strchr (tag_begin,'<');
            if (!tag_endin)
                continue;

            gchar * value = copy_value (tag_begin,tag_endin);
            if (value != NULL)
            {
                if (strlen (value) > 0)
                {
                    GlyrMemCache * tmp = DL_init();
                    tmp->data = value;
                    tmp->size = tag_endin - tag_begin;
                    tmp->type = type_num;
                    tmp->dsrc = g_strdup (info->dsrc);

                    results = g_list_prepend (results,tmp);
                }
            }
        }
        DL_free (info);
    }
    return results;
}
Esempio n. 13
0
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;
}
Esempio n. 14
0
char *mbid_lookup(const char *query, GLYR_DATA_TYPE type, GlyrQuery *qry)
{
    char *result_mbid = NULL;
    if(query == NULL) {
        return result_mbid;
    }

    const char *lookup_entity = "";
    const char *compre_entity = qry->artist;
    const char *find_entity = "name";

    switch(type) {
    case GLYR_TYPE_TAG_ARTIST:
        lookup_entity = "artist";
        compre_entity = qry->artist;
        break;
    case GLYR_TYPE_TAG_ALBUM:
        lookup_entity = "release";
        compre_entity = qry->album;
        find_entity = "title";
        break;
    case GLYR_TYPE_TAG_TITLE:
        lookup_entity = "work";
        compre_entity = qry->title;
        break;
    default:
        lookup_entity = "artist";
        compre_entity = qry->artist;
        find_entity = "name";
        break;
    }

    char *lookup_url = g_strdup_printf(LOOKUP_QUERY, lookup_entity, lookup_entity, query);
    GlyrMemCache *parseable_data = download_single(lookup_url, qry, NULL);
    if(parseable_data != NULL) {
        result_mbid = mbid_parse_data(parseable_data, lookup_entity, find_entity, compre_entity, qry);
        DL_free(parseable_data);
    }

    g_free(lookup_url);
    return result_mbid;
}
Esempio n. 15
0
static GList * cover_coverartarchive_parse (cb_object * capo)
{
    GList *result_list = NULL;
    char * mbid = mbid_parse_data (capo->cache, "release", "title", capo->s->album, capo->s);
    if (mbid != NULL)
    {
        char * full_url = g_strdup_printf (API_ROOT, mbid);
        if (full_url != NULL)
        {
            GlyrMemCache * json_data = download_single (full_url, capo->s, NULL);
            if (json_data != NULL)
            {
                result_list = parse_archive_json (json_data, capo->s);
                DL_free (json_data);
            }
            g_free (full_url);
        }
    }
    return result_list;
}
Esempio n. 16
0
File: picsearch.c Progetto: meh/glyr
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;
}
Esempio n. 17
0
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;
}
Esempio n. 18
0
/* 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;
}
Esempio n. 19
0
static GList *tracklist_musicbrainz_parse(cb_object *capo)
{
    GList *result_list = NULL;

    gchar *rel_id_begin = strstr(capo->cache->data, REL_ID_BEGIN);
    if(rel_id_begin != NULL) {
        gchar *release_ID = get_search_value(rel_id_begin, REL_ID_BEGIN, REL_ID_ENDIN);
        if(release_ID != NULL) {
            gchar *release_page_info_url = g_strdup_printf(REL_ID_FORM, release_ID);
            GlyrMemCache *dlData = download_single(release_page_info_url, capo->s, NULL);
            if(dlData != NULL) {
                result_list = traverse_xml(dlData->data, capo->url, capo);
                if(result_list != NULL) {
                    result_list = g_list_reverse(result_list);
                }
                DL_free(dlData);
            }
            g_free(release_page_info_url);
            g_free(release_ID);
        }
    }
    return result_list;
}
Esempio n. 20
0
/* Take the first link we find.
 * coverhunt sadly offers  no way to check if the
 * image is really related to the query we're searching for
 */
static GList * cover_coverhunt_parse (cb_object *capo)
{
    GList * result_list = NULL;

    /* navigate to start of search results */
    gchar * table_start;
    if ( (table_start = strstr (capo->cache->data,SEARCH_RESULT_BEGIN) ) == NULL)
    {
        /* Whoops, nothing to see here */
        return NULL;
    }

    while (continue_search (g_list_length (result_list),capo->s) && (table_start = strstr (table_start + 1,NODE_BEGIN) ) )
    {
        gchar * table_end = NULL;
        if ( (table_end = strstr (table_start,"\">") ) != NULL)
        {
            gchar * go_url = copy_value (table_start + strlen (NODE_BEGIN),table_end);
            if (go_url)
            {
                gchar * real_url = g_strdup_printf ("http://www.coverhunt.com/go/%s",go_url);
                if (real_url != NULL)
                {
                    GlyrMemCache * search_buf = download_single (real_url,capo->s,"<div id=\"right\">");
                    if (search_buf != NULL)
                    {
                        gchar * artwork = strstr (search_buf->data, "<div class=\"artwork\">");
                        if (artwork != NULL)
                        {
                            if (check_size (artwork,"height=",capo) && check_size (artwork,"width=",capo) )
                            {
                                gchar * img_start = strstr (artwork,IMG_START);
                                if (img_start != NULL)
                                {
                                    img_start += (sizeof IMG_START) - 1;
                                    gchar * img_end = strstr (img_start,"\" ");
                                    if (img_end != NULL)
                                    {
                                        gchar * url = copy_value (img_start,img_end);
                                        if (url != NULL)
                                        {
                                            GlyrMemCache * shell = DL_init();
                                            shell->data = url;
                                            shell->size = img_end - img_start;
                                            shell->dsrc = g_strdup (real_url);
                                            result_list = g_list_prepend (result_list,shell);
                                        }
                                    }
                                }
                            }
                        }
                        DL_free (search_buf);
                    }
                    g_free (real_url);
                }
                g_free (go_url);
            }
        }
    }
    return result_list;
}