totem-pl-parser r55 - in trunk: . plparse



Author: hadess
Date: Sat Feb 23 15:49:19 2008
New Revision: 55
URL: http://svn.gnome.org/viewvc/totem-pl-parser?rev=55&view=rev

Log:
2008-02-23  Bastien Nocera  <hadess hadess net>

	* plparse/totem-pl-parser-xspf.c (totem_pl_parser_write_xspf),
	(parse_xspf_track):
	* plparse/totem-pl-parser.c (totem_pl_parser_class_init):
	* plparse/totem-pl-parser.h: Give out much more metadata when parsing
	XSPF playlists, as used on the new last.fm streaming system
	(Helps: #518231)



Modified:
   trunk/ChangeLog
   trunk/plparse/totem-pl-parser-xspf.c
   trunk/plparse/totem-pl-parser.c
   trunk/plparse/totem-pl-parser.h

Modified: trunk/plparse/totem-pl-parser-xspf.c
==============================================================================
--- trunk/plparse/totem-pl-parser-xspf.c	(original)
+++ trunk/plparse/totem-pl-parser-xspf.c	Sat Feb 23 15:49:19 2008
@@ -40,6 +40,8 @@
 
 #ifndef TOTEM_PL_PARSER_MINI
 
+#define SAFE_FREE(x) { if (x != NULL) xmlFree (x); }
+
 static xmlDocPtr
 totem_pl_parser_parse_xml_file (const char *url)
 {
@@ -179,12 +181,18 @@
 		xmlNodePtr parent)
 {
 	xmlNodePtr node;
-	xmlChar *title, *url;
-	gchar *fullpath;
+	xmlChar *title, *url, *image_url, *artist, *album, *duration, *moreinfo;
+	char *fullpath;
 	TotemPlParserResult retval = TOTEM_PL_PARSER_RESULT_ERROR;
 	
+	fullpath = NULL;
 	title = NULL;
 	url = NULL;
+	image_url = NULL;
+	artist = NULL;
+	album = NULL;
+	duration = NULL;
+	moreinfo = NULL;
 
 	for (node = parent->children; node != NULL; node = node->next)
 	{
@@ -196,22 +204,61 @@
 
 		if (g_ascii_strcasecmp ((char *)node->name, "title") == 0)
 			title = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
+
+		if (g_ascii_strcasecmp ((char *)node->name, "image") == 0)
+			image_url = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
+
+		/* Last.fm uses creator for the artist */
+		if (g_ascii_strcasecmp ((char *)node->name, "creator") == 0)
+			artist = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
+
+		if (g_ascii_strcasecmp ((char *)node->name, "duration") == 0)
+			duration = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
+
+		if (g_ascii_strcasecmp ((char *)node->name, "link") == 0) {
+			xmlChar *rel;
+
+			rel = xmlGetProp (node, (const xmlChar *) "rel");
+			if (rel != NULL) {
+				if (g_ascii_strcasecmp ((char *) rel, "http://www.last.fm/trackpage";) == 0)
+					moreinfo = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
+				xmlFree (rel);
+			} else {
+				/* If we don't have a rel="", then it's not a last.fm playlist */
+				moreinfo = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
+			}
+		}
+
+		if (g_ascii_strcasecmp ((char *)node->name, "album") == 0)
+			album = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
 	}
 
 	if (url == NULL) {
-		if (title)
-			xmlFree (title);
-		return TOTEM_PL_PARSER_RESULT_ERROR;
+		retval = TOTEM_PL_PARSER_RESULT_ERROR;
+		goto bail;
 	}
 
 	fullpath = totem_pl_parser_resolve_url (base, (char *)url);
-	totem_pl_parser_add_one_url (parser, fullpath, (char *)title);
+	totem_pl_parser_add_url (parser,
+				 TOTEM_PL_PARSER_FIELD_URL, fullpath,
+				 TOTEM_PL_PARSER_FIELD_TITLE, title,
+				 TOTEM_PL_PARSER_FIELD_DURATION, duration,
+				 TOTEM_PL_PARSER_FIELD_IMAGE_URL, image_url,
+				 TOTEM_PL_PARSER_FIELD_AUTHOR, artist,
+				 TOTEM_PL_PARSER_FIELD_ALBUM, album,
+				 TOTEM_PL_PARSER_FIELD_MOREINFO, moreinfo,
+				 NULL);
+
 	retval = TOTEM_PL_PARSER_RESULT_SUCCESS;
 
-	if (title)
-		xmlFree (title);
-	if (url)
-		xmlFree (url);
+bail:
+	SAFE_FREE (title);
+	SAFE_FREE (url);
+	SAFE_FREE (image_url);
+	SAFE_FREE (artist);
+	SAFE_FREE (album);
+	SAFE_FREE (duration);
+	SAFE_FREE (moreinfo);
 	g_free (fullpath);
 
 	return retval;

Modified: trunk/plparse/totem-pl-parser.c
==============================================================================
--- trunk/plparse/totem-pl-parser.c	(original)
+++ trunk/plparse/totem-pl-parser.c	Sat Feb 23 15:49:19 2008
@@ -414,6 +414,10 @@
 				     "Genre of the item to be added", NULL,
 				     G_PARAM_READABLE & G_PARAM_WRITABLE);
 	g_param_spec_pool_insert (totem_pl_parser_pspec_pool, pspec, TOTEM_TYPE_PL_PARSER);
+	pspec = g_param_spec_string ("album", "album",
+				     "Album of the item to be added", NULL,
+				     G_PARAM_READABLE & G_PARAM_WRITABLE);
+	g_param_spec_pool_insert (totem_pl_parser_pspec_pool, pspec, TOTEM_TYPE_PL_PARSER);
 	pspec = g_param_spec_string ("base", "base",
 				     "Base URL of the item to be added", NULL,
 				     G_PARAM_READABLE & G_PARAM_WRITABLE);

Modified: trunk/plparse/totem-pl-parser.h
==============================================================================
--- trunk/plparse/totem-pl-parser.h	(original)
+++ trunk/plparse/totem-pl-parser.h	Sat Feb 23 15:49:19 2008
@@ -95,6 +95,12 @@
  **/
 #define TOTEM_PL_PARSER_FIELD_AUTHOR		"author"
 /**
+ * TOTEM_PL_PARSER_FIELD_ALBUM:
+ *
+ * Metadata field for an entry's album.
+ **/
+#define TOTEM_PL_PARSER_FIELD_ALBUM		"album"
+/**
  * TOTEM_PL_PARSER_FIELD_BASE:
  *
  * Metadata field for an entry's base path.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]