[gnac/devel] Added support for ASX playlists



commit f42bc1a37ee97f11da64e032ab114b7583553da2
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date:   Sun Apr 22 12:56:22 2012 +0100

    Added support for ASX playlists

 src/gnac-playlist.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 src/gnac-ui.c       |    1 +
 2 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/src/gnac-playlist.c b/src/gnac-playlist.c
index b46f9bd..5ad72c1 100755
--- a/src/gnac-playlist.c
+++ b/src/gnac-playlist.c
@@ -38,11 +38,13 @@ typedef struct {
   void        (*handler)(GFile *file);
 } GnacPlaylistMimeHandler;
 
+static void gnac_playlist_parse_asx(GFile *file);
 static void gnac_playlist_parse_m3u(GFile *file);
 static void gnac_playlist_parse_pls(GFile *file);
 static void gnac_playlist_parse_xspf(GFile *file);
 
 static GnacPlaylistMimeHandler mime_playlist[] = {
+  { "audio/x-ms-asx"      , &gnac_playlist_parse_asx  },
   { "audio/x-mpegurl"     , &gnac_playlist_parse_m3u  },
   { "audio/x-scpls"       , &gnac_playlist_parse_pls  },
   { "application/xspf+xml", &gnac_playlist_parse_xspf },
@@ -125,6 +127,48 @@ gnac_playlist_parse(GFile       *file,
 
 
 static void
+gnac_playlist_parse_asx(GFile *file)
+{
+  GFile *parent = g_file_get_parent(file);
+  gchar *contents = gnac_playlist_read_file(file);
+  if (!contents) return;
+
+  gchar **lines = g_strsplit(contents, "\n", -1);
+
+  guint i;
+  for (i = 0; lines[i]; i++) {
+    /* skip empty lines */
+    if (!*lines[i]) continue;
+
+    gchar *line = g_strstrip(lines[i]);
+
+    gchar *lc_line = g_utf8_strdown(line, -1);
+
+    if (g_str_has_prefix(lc_line, "<ref href")) {
+      gchar **tmp1 = g_strsplit(line, "\"", -1);
+      gchar *tmp2 = g_strdup(tmp1[1]);
+      guint j;
+      for (j = 2; tmp1[j]; j++) {
+        gchar *tmp3 = g_strconcat(tmp2, tmp1[j], NULL);
+        g_free(tmp2);
+        tmp2 = g_strdup(tmp3);
+        g_free(tmp3);
+      }
+      line = tmp2;
+      gnac_playlist_resolve_uri_and_add(parent, line);
+      g_free(tmp2);
+      g_strfreev(tmp1);
+    }
+
+    g_free(lc_line);
+  }
+
+  g_strfreev(lines);
+  g_free(contents);
+}
+
+
+static void
 gnac_playlist_parse_m3u(GFile *file)
 {
   GFile *parent = g_file_get_parent(file);
diff --git a/src/gnac-ui.c b/src/gnac-ui.c
index bcd5dbc..76f6401 100644
--- a/src/gnac-ui.c
+++ b/src/gnac-ui.c
@@ -157,6 +157,7 @@ gnac_ui_file_chooser_get_filters_model(void)
   };
 
   const gchar *playlists_mime[][2] = {
+    { "audio/x-ms-asx"      , _("Microsoft ASX playlist") },
     { "audio/x-mpegurl"     , _("MP3 audio (streamed)")   },
     { "audio/x-scpls"       , _("MP3 ShoutCast playlist") },
     { "application/xspf+xml", _("XSPF playlist")          },



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