示例#1
0
文件: lastfm.c 项目: WangCrystal/glyr
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;
}
示例#2
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;
}
示例#3
0
文件: picsearch.c 项目: meh/glyr
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;
}
示例#4
0
文件: amazon.c 项目: lejenome/glyr
static GList *review_amazon_parse(cb_object *capo)
{
    gchar *node = capo->cache->data;
    gsize conlen = (sizeof TheContent) - 1;
    GList *result_list = NULL;
    while(continue_search(g_list_length(result_list), capo->s) && (node = strstr(node + conlen, TheContent)) != NULL) {
        gchar *endOfText = strstr(node + conlen, TheEndofCt);
        gchar *text = copy_value(node + conlen, endOfText);
        if(text != NULL) {
            /* Ignore reviews with 350 chars
             * as mostly just advertisement */
            if((endOfText - (node + conlen)) > 350) {
                GlyrMemCache *result = DL_init();
                result->data = text;
                result->size = result->data ? strlen(result->data) : 0;
                result_list = g_list_prepend(result_list, result);
            }
        }
    }
    return result_list;
}
示例#5
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;
}
示例#6
0
文件: allmusic_com.c 项目: meh/glyr
static GlyrMemCache * parse_cover_page(GlyrMemCache * dl_cache)
{
	GlyrMemCache * result = NULL;
	if(dl_cache != NULL)
	{
		gchar * img_url = get_search_value(dl_cache->data,IMG_BEGIN,IMG_ENDIN);
		if(img_url != NULL)
		{
			if(strcmp(img_url,BAD_URL) != 0)
			{
				result = DL_init();
				result->data = img_url;
				result->size = strlen(img_url);
			}
			else
			{
				g_free(img_url);
			}
		}
	}
	return result;
}
示例#7
0
文件: lastfm.c 项目: lejenome/glyr
static GList *photos_lastfm_parse(cb_object *capo)
{
    gchar *root = capo->cache->data;
    GList *result_list = NULL;

    while(continue_search(g_list_length(result_list), capo->s) && (root = strstr(root, SIZE_FO)) != NULL) {
        gchar *begin = root + strlen(SIZE_FO);
        if(size_fits(capo->s, &begin) == TRUE) {
            gchar *endin = strstr(begin, URL_ENDIN);
            if(endin != NULL) {
                gchar *urlb = copy_value(begin, endin);
                if(urlb != NULL) {
                    GlyrMemCache *cache = DL_init();
                    cache->data = urlb;
                    cache->size = strlen(urlb);
                    result_list = g_list_prepend(result_list, cache);
                }
            }
        }
        root += (sizeof SIZE_FO) - 1;
    }
    return result_list;
}
示例#8
0
文件: lyricsvip.c 项目: lejenome/glyr
static GList *lyrics_lyricsvip_parse(cb_object *capo)
{
    gchar *start = NULL;
    gchar *end = NULL;
    gchar *content = NULL;
    GList *result_list  = NULL;

    if((start = strstr(capo->cache->data, BEG)) != NULL) {
        if((end = strstr(start, END)) != NULL) {
            if(ABS(end - start) > 0) {
                * (end) = 0;

                content = strreplace(start, "<br />", "");
                if(content) {
                    GlyrMemCache *result = DL_init();
                    result->data = content;
                    result->size = strlen(content);
                    result_list = g_list_prepend(result_list, result);
                }
            }
        }
    }
    return result_list;
}
示例#9
0
static GList * cover_jamendo_parse (cb_object *capo)
{
    // A nice parser with zero memory overhead..

    GList * result_list = NULL;
    gchar * line = capo->cache->data;

    while (continue_search (g_list_length (result_list),capo->s) )
    {
        char * line_end;

        if ( (line_end = strchr (line,'\n') ) != NULL)
        {
            *line_end = 0;

            char * line_split[3] = {0,0,0};
            do_line_split (line_split,line);

            if (check_values (capo->s,line_split[2],line_split[1]) )
            {
                char * url =  g_strdup_printf (RESULT_URL,line_split[0],get_cover_size (capo->s) );
                GlyrMemCache * result = DL_init();
                result->data = url;
                result->size = strlen (url);
                result_list = g_list_prepend (result_list,result);
            }

            line = ++line_end;
        }
        else
        {
            break;
        }
    }
    return result_list;
}
示例#10
0
static GlyrMemCache *parse_page(GlyrMemCache *dl, cb_object *capo)
{
    GlyrMemCache *result = NULL;
    if(dl != NULL) {
        gchar *begin = strstr(dl->data, LYR_BEGIN);
        if(begin != NULL) {
            begin += (sizeof LYR_BEGIN) - 1;
            gchar *end = strstr(begin, LYR_ENDIN);
            if(end != NULL) {
                * (end) = 0;
                gchar *no_br_tags = strreplace(begin, "<br />", NULL);
                if(no_br_tags != NULL) {
                    result = DL_init();
                    result->data = beautify_string(no_br_tags);
                    result->size = (result->data) ? strlen(result->data) : 0;
                    result->dsrc = g_strdup(dl->dsrc);

                    g_free(no_br_tags);
                }
            }
        }
    }
    return result;
}
示例#11
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;
}