Esempio n. 1
0
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;
}
Esempio n. 2
0
int
main (int argc, char **argv)
{
  nxml_t *data;
  nxml_error_t ret;
  nxml_data_t *element, *tmp;
  nxml_doctype_t *doctype;

  if (argc != 2)
    {
      fprintf (stderr,
	       "Usage:\n\t%s url_xml\n\nExample:\n\t%s [file.xml|http://server/file.xml]\n\n",
	       argv[0], argv[0]);
      return 1;
    }

  ret = nxml_new (&data);

  if (ret != NXML_OK)
    {
      puts (nxml_strerror (ret));
      return 1;
    }

  ret = nxml_set_func (data, my_printf);

  if (ret != NXML_OK)
    {
      puts (nxml_strerror (ret));
      return 1;
    }

  if (!strncmp (argv[1], "http://", 7))
    ret = nxml_parse_url (data, argv[1]);
  else
    ret = nxml_parse_file (data, argv[1]);

  if (ret != NXML_OK)
    {
      puts (nxml_strerror (ret));
      return 1;
    }

  nxml_root_element (data, &element);
  printf ("Root element: %p: -%s-\n", element, element ? element->value : "");

  if (element)
    {
      tmp = element->children;
      while (tmp)
	{
	  printf ("  subelement: %p: -%s-\n", tmp, tmp ? tmp->value : "");
	  tmp = tmp->next;
	}
    }

  nxml_find_element (data, element, "body", &element);
  if (element && nxml_find_element (data, element, "div", &element) == NXML_OK
      && element)
    {
      printf ("\ndiv element: -%p-\n", element);
    }

  nxml_doctype_element (data, &doctype);

  if (doctype)
    printf ("\nDoctype: -%s-%s-\n", doctype->name, doctype->value);

  nxml_free (data);

  return 0;
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
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;
}