static gboolean lyrics_process_lyrics_node (LYRICS_NODE *ptr) { LYRICS_NODE *node = ptr; char *url = NULL; char *str = NULL; gboolean ret = FALSE; nxml_t *nxml = NULL; nxml_data_t *nroot = NULL; nxml_data_t *ndata = NULL; nxml_data_t *nndata = NULL; nxml_error_t e; if (node == NULL) return ret; url = g_strdup_printf ("%s%s", LYRICS_URL, node->hid); //printf ("%s\n", url); e = nxml_new (&nxml); nxml_set_timeout (nxml, 20); gimmix_lyrics_plugin_proxy_init (nxml); nxml_parse_url (nxml, url); nxml_root_element (nxml, &nroot); nxml_find_element (nxml, nroot, "lyric", &ndata); nxml_find_element (nxml, ndata, "text", &nndata); nxml_get_string (nndata, &str); if (str) { node->lyrics = g_strdup_printf (str); g_free (str); ret = TRUE; } nxml_free (nxml); g_free (url); return ret; }
static LYRICS_NODE* lyrics_perform_search (const char *url) { char *str = NULL; nxml_t *nxml = NULL; nxml_data_t *nroot = NULL; nxml_data_t *child = NULL; LYRICS_NODE *lnode = NULL; nxml_new (&nxml); nxml_set_timeout (nxml, 20); gimmix_lyrics_plugin_proxy_init (nxml); nxml_parse_url (nxml, (char*)url); nxml_root_element (nxml, &nroot); nxml_find_element (nxml, nroot, "response", &child); nxml_get_string (child, &str); if (str!=NULL) { lnode = (LYRICS_NODE*) malloc (sizeof(LYRICS_NODE)); memset (lnode, 0, sizeof(LYRICS_NODE)); if (!strcmp(str,"SUCCESS")) { nxml_data_t *temp = NULL; nxml_attr_t *attr = NULL; nxml_find_element (nxml, nroot, "searchResults", &child); nxml_find_element (nxml, child, "result", &temp); nxml_find_attribute (temp, "exactMatch", &attr); if (attr) { if (!strcmp(attr->value,"true")) lnode->match = TRUE; } nxml_find_attribute (temp, "hid", &attr); if (attr) { strncpy (lnode->hid, attr->value, strlen(attr->value)); } nxml_find_element (nxml, child, "title", &temp); if (temp) { strncpy (lnode->title, temp->value, strlen(temp->value)); } nxml_find_element (nxml, child, "artist", &temp); if (temp) { nxml_data_t *ar = NULL; nxml_find_element (nxml, temp, "name", &ar); if (ar) strncpy (lnode->title, ar->value, strlen(ar->value)); } /* if match not found */ if (!lnode->match) { /* compare artist */ if (!g_ascii_strcasecmp(lnode->artist, search_artist) && !g_ascii_strcasecmp(lnode->title, search_title)) { lnode->match = TRUE; } else if (!g_ascii_strcasecmp(lnode->artist, search_artist)) { /* try to match a part of song */ if (!g_ascii_strncasecmp(lnode->title, search_title, 5)) { lnode->match = TRUE; } } } if (lnode->match) { lyrics_process_lyrics_node (lnode); } else { g_free (lnode); lnode = NULL; } } g_free (str); } nxml_free (nxml); return lnode; }
static CoverNode* gimmix_covers_plugin_get_metadata (char *arg1, char *arg1d, char *arg2, char *arg2d) { char *url = NULL; CoverNode *node = NULL; char *u_artist = NULL; char *u_title = NULL; nxml_t *nxml = NULL; nxml_data_t *nroot = NULL; nxml_data_t *ndata = NULL; nxml_data_t *nndata = NULL; char *str = NULL; char *location = NULL; nxml_error_t e; u_artist = gimmix_url_encode (arg1d); u_title = gimmix_url_encode (arg2d); location = cfg_get_key_value (conf, "coverart_location"); if (!arg1 && !arg1d) { url = g_strdup_printf (AMAZON_URL1, location, AMAZON_KEY, arg2, u_title); } else { url = g_strdup_printf (AMAZON_URL2, location, AMAZON_KEY, arg1, u_artist, arg2, u_title); } //g_print ("%s\n", url); e = nxml_new (&nxml); nxml_set_timeout (nxml, 20); gimmix_covers_plugin_proxy_init (nxml); nxml_parse_url (nxml, url); nxml_root_element (nxml, &nroot); nxml_find_element (nxml, nroot, "Items", &ndata); nxml_find_element (nxml, ndata, "Item", &nndata); if (nndata) { nxml_data_t *child = NULL; nxml_data_t *d = NULL; nxml_data_t *t = NULL; child = nndata; node = gimmix_cover_node_new (); /* large image */ nxml_find_element (nxml, child, "LargeImage", &d); nxml_find_element (nxml, d, "URL", &t); nxml_get_string (t, &str); if (str!=NULL) { node->img_large = g_strdup (str); free (str); } /* medium image */ nxml_find_element (nxml, child, "MediumImage", &d); nxml_find_element (nxml, d, "URL", &t); nxml_get_string (t, &str); if (str!=NULL) { node->img_medium = g_strdup (str); free (str); str = NULL; } /* small image */ nxml_find_element (nxml, child, "SmallImage", &d); nxml_find_element (nxml, d, "URL", &t); nxml_get_string (t, &str); if (str!=NULL) { node->img_small = g_strdup (str); free (str); str = NULL; } /* editorial reviews */ nxml_find_element (nxml, child, "EditorialReviews", &d); nxml_find_element (nxml, d, "EditorialReview", &t); nxml_find_element (nxml, t, "Content", &d); nxml_get_string (d, &str); if (str!=NULL) { g_print ("%s\n", str); node->album_info = g_strdup (str); free (str); } } nxml_free (nxml); g_free (url); return node; }
mrss_error_t mrss_parse_url_with_options_and_error (char *url, mrss_t ** ret, mrss_options_t * options, CURLcode * code) { nxml_t *doc; mrss_error_t err; char *buffer; size_t size; if (!url || !ret) return MRSS_ERR_DATA; if (nxml_new (&doc) != NXML_OK) return MRSS_ERR_POSIX; if (options) { if (options->timeout >= 0) nxml_set_timeout (doc, options->timeout); if (options->proxy) nxml_set_proxy (doc, options->proxy, options->proxy_authentication); if (options->authentication) nxml_set_authentication (doc, options->authentication); if (options->user_agent) nxml_set_user_agent (doc, options->user_agent); nxml_set_certificate (doc, options->certfile, options->password, options->cacert, options->verifypeer); } if (!(buffer = __mrss_download_file (doc, url, &size, &err, code))) return err; if (nxml_parse_buffer (doc, buffer, size) != NXML_OK) { free (buffer); nxml_free (doc); return MRSS_ERR_PARSER; } if (!(err = __mrss_parser (doc, ret))) { if (!((*ret)->file = strdup (url))) { free (buffer); mrss_free (*ret); nxml_free (doc); return MRSS_ERR_POSIX; } (*ret)->size = size; } free (buffer); nxml_free (doc); return err; }