예제 #1
0
파일: allmusic_com.c 프로젝트: meh/glyr
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;
}
예제 #2
0
파일: musicbrainz.c 프로젝트: sahib/glyr
/* Returns only a parseable memcache */
GlyrMemCache * generic_musicbrainz_parse (cb_object * capo, gint * last_mbid, const gchar * include)
{
    gsize offset = 0;
    const gchar * mbid = NULL;
    GlyrMemCache * info = NULL;

    while (offset < capo->cache->size && info==NULL && (mbid = get_mbid_from_xml (capo->s,capo->cache,last_mbid) ) )
    {
        if (mbid != NULL)
        {
            const gchar * type = NULL;
            switch (please_what_type (capo->s) )
            {
            case GLYR_TYPE_TAG_TITLE:
                type = "track";
                break;
            case GLYR_TYPE_TAG_ALBUM:
                type = "release";
                break;
            case GLYR_TYPE_TAG_ARTIST:
                type = "artist";
                break;
            }

            gchar * info_page_url = g_strdup_printf ("http://musicbrainz.org/ws/1/%s/%s?type=xml&inc=%s",type,mbid,include);
            if (info_page_url)
            {
                info = download_single (info_page_url,capo->s,NULL);
                g_free (info_page_url);
            }
            g_free ( (gchar*) mbid);
        }
    }
    return info;
}
예제 #3
0
파일: metallum.c 프로젝트: meh/glyr
static GList * review_metallum_parse(cb_object * capo)
{
	GList * result_items = NULL;

	gsize nodelen = strlen(NODE_START);
	gchar * node  = capo->cache->data;
	gint node_ctr = 0;

	while((node = strstr(node+nodelen,NODE_START)) != NULL)
	{
		/* Only take the album url, not the other urls */
		if(++node_ctr % 2 == 0)
		{
			node += nodelen;
			gchar * content_url = copy_value(node,strstr(node,NODE_END));
			if(content_url != NULL)
			{
				gchar * review_url = strreplace(content_url,"/albums/","/reviews/");
				if(review_url != NULL)
				{
					parse_review_site(capo->s, download_single(review_url,capo->s,NULL), &result_items);
					g_free(review_url);
				}
				g_free(content_url);
			}
		}
	}
	return result_items;
}
예제 #4
0
파일: lyrix_at.c 프로젝트: hihihippp/glyr
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);
    }
}
예제 #5
0
static GList * lyrics_metallum_parse (cb_object * capo)
{
    GList * result_items = NULL;
    gchar * id_start = strstr (capo->cache->data,ID_START);
    if (id_start != NULL)
    {
        id_start += strlen (ID_START);
        gchar * ID_string = copy_value (id_start,strstr (id_start,ID_END) );
        if (ID_string != NULL)
        {
            gchar * content_url = g_strdup_printf (SUBST_URL,ID_string);
            if (content_url != NULL)
            {
                GlyrMemCache * content_cache = download_single (content_url,capo->s,NULL);
                if (content_cache != NULL && strstr (content_cache->data,BAD_STRING) == NULL)
                {
                    result_items = g_list_prepend (result_items, content_cache);
                }
                g_free (content_url);
            }
            g_free (ID_string);
        }
    }
    return result_items;
}
예제 #6
0
파일: allmusic_com.c 프로젝트: meh/glyr
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;
}
예제 #7
0
파일: allmusic_com.c 프로젝트: meh/glyr
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;
}
예제 #8
0
파일: lyricstime.c 프로젝트: meh/glyr
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;
}
예제 #9
0
파일: lyrdb.c 프로젝트: WangCrystal/glyr
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;
}
예제 #10
0
파일: chartlyrics.c 프로젝트: meh/glyr
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;
}
예제 #11
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;
}
예제 #12
0
파일: lyricswiki.c 프로젝트: meh/glyr
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;
}
예제 #13
0
파일: mbid_lookup.c 프로젝트: lejenome/glyr
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;
}
예제 #14
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;
}
예제 #15
0
파일: picsearch.c 프로젝트: 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;
}
예제 #16
0
파일: chordie_com.c 프로젝트: sahib/glyr
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;
}
예제 #17
0
파일: musicbrainz.c 프로젝트: lejenome/glyr
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;
}
예제 #18
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;
}