[totem-pl-parser] plparser: Add support for some GNOME XSPF extensions



commit df7355f270574696d2bbb7487d3178051f828cfc
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Mar 8 18:01:25 2013 +0100

    plparser: Add support for some GNOME XSPF extensions
    
    That should allow Totem to save all its metadata in the playlist
    file rather than using side storage.

 plparse/totem-pl-parser-xspf.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)
---
diff --git a/plparse/totem-pl-parser-xspf.c b/plparse/totem-pl-parser-xspf.c
index 02c5217..d532e0b 100644
--- a/plparse/totem-pl-parser-xspf.c
+++ b/plparse/totem-pl-parser-xspf.c
@@ -201,12 +201,25 @@ totem_pl_parser_save_xspf (TotemPlParser    *parser,
 }
 
 static gboolean
+parse_bool_str (const char *str)
+{
+       if (str == NULL)
+               return FALSE;
+       if (g_ascii_strcasecmp (str, "true") == 0)
+               return TRUE;
+       if (g_ascii_strcasecmp (str, "false") == 0)
+               return FALSE;
+       return atoi (str);
+}
+
+static gboolean
 parse_xspf_track (TotemPlParser *parser, GFile *base_file, xmlDocPtr doc,
                xmlNodePtr parent)
 {
        xmlNodePtr node;
        xmlChar *title, *uri, *image_uri, *artist, *album, *duration, *moreinfo;
-       xmlChar *download_uri, *id, *genre, *filesize;
+       xmlChar *download_uri, *id, *genre, *filesize, *subtitle, *mime_type;
+       xmlChar *playing;
        GFile *resolved;
        char *resolved_uri;
        TotemPlParserResult retval = TOTEM_PL_PARSER_RESULT_ERROR;
@@ -222,6 +235,9 @@ parse_xspf_track (TotemPlParser *parser, GFile *base_file, xmlDocPtr doc,
        id = NULL;
        genre = NULL;
        filesize = NULL;
+       subtitle = NULL;
+       mime_type = NULL;
+       playing = NULL;
 
        for (node = parent->children; node != NULL; node = node->next)
        {
@@ -266,6 +282,21 @@ parse_xspf_track (TotemPlParser *parser, GFile *base_file, xmlDocPtr doc,
                                                break;
                                        }
                                }
+                       } else if (app != NULL && g_ascii_strcasecmp ((char *) app, "http://www.gnome.org";) 
== 0) {
+                               xmlNodePtr child;
+                               for (child = node->xmlChildrenNode ; child; child = child->next) {
+                                       if (child->name == NULL)
+                                               continue;
+                                       if (g_ascii_strcasecmp ((char *)child->name, "playing") == 0) {
+                                               xmlChar *str;
+                                               str = xmlNodeListGetString (doc, child->xmlChildrenNode, 0);
+                                               playing = parse_bool_str ((char *) str) ? (xmlChar *) "true" 
: NULL;
+                                       } else if (g_ascii_strcasecmp ((char *)child->name, "subtitle") == 0) 
{
+                                               subtitle = xmlNodeListGetString (doc, child->xmlChildrenNode, 
0);
+                                       } else if (g_ascii_strcasecmp ((char *)child->name, "mime-type") == 
0) {
+                                               mime_type = xmlNodeListGetString (doc, 
child->xmlChildrenNode, 0);
+                                       }
+                               }
                        } else if (app != NULL && g_ascii_strcasecmp ((char *) app, "http://www.last.fm";) == 
0) {
                                xmlNodePtr child;
                                for (child = node->xmlChildrenNode ; child; child = child->next) {
@@ -321,6 +352,9 @@ parse_xspf_track (TotemPlParser *parser, GFile *base_file, xmlDocPtr doc,
                                         TOTEM_PL_PARSER_FIELD_ID, id,
                                         TOTEM_PL_PARSER_FIELD_GENRE, genre,
                                         TOTEM_PL_PARSER_FIELD_FILESIZE, filesize,
+                                        TOTEM_PL_PARSER_FIELD_SUBTITLE_URI, subtitle,
+                                        TOTEM_PL_PARSER_FIELD_PLAYING, playing,
+                                        TOTEM_PL_PARSER_FIELD_CONTENT_TYPE, mime_type,
                                         NULL);
        } else {
                resolved = g_file_new_for_uri (resolved_uri);
@@ -338,6 +372,9 @@ parse_xspf_track (TotemPlParser *parser, GFile *base_file, xmlDocPtr doc,
                                         TOTEM_PL_PARSER_FIELD_ID, id,
                                         TOTEM_PL_PARSER_FIELD_GENRE, genre,
                                         TOTEM_PL_PARSER_FIELD_FILESIZE, filesize,
+                                        TOTEM_PL_PARSER_FIELD_SUBTITLE_URI, subtitle,
+                                        TOTEM_PL_PARSER_FIELD_PLAYING, playing,
+                                        TOTEM_PL_PARSER_FIELD_CONTENT_TYPE, mime_type,
                                         NULL);
                g_object_unref (resolved);
        }


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