[rygel/wip/m3u: 1/2] Try to parse m3u playlists
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/m3u: 1/2] Try to parse m3u playlists
- Date: Sun, 17 Nov 2013 19:32:58 +0000 (UTC)
commit a64fd6e0e615e330ee72f2b93d94a0ea787f2dc9
Author: Jens Georg <jensg openismus com>
Date: Wed Nov 21 20:48:07 2012 +0100
Try to parse m3u playlists
src/librygel-renderer/rygel-av-transport.vala | 49 ++++++++++++++++++++++---
1 files changed, 43 insertions(+), 6 deletions(-)
---
diff --git a/src/librygel-renderer/rygel-av-transport.vala b/src/librygel-renderer/rygel-av-transport.vala
index 35c3dbb..dd11151 100644
--- a/src/librygel-renderer/rygel-av-transport.vala
+++ b/src/librygel-renderer/rygel-av-transport.vala
@@ -342,6 +342,12 @@ internal class Rygel.AVTransport : Service {
}
}
+ private bool is_playlist (string mime, string? features) {
+ return (mime == "text/xml" &&
+ features.has_prefix ("DLNA.ORG_PN=DIDL_S")) ||
+ mime == "audio/mpegurl";
+ }
+
private bool is_valid_mime_type (string? mime) {
if (mime == null) {
return false;
@@ -783,14 +789,45 @@ internal class Rygel.AVTransport : Service {
return;
}
- unowned string xml_string = (string) message.response_body.data;
+ var content_type = message.response_headers.get_content_type (null);
+
+ MediaCollection collection = null;
+ if (content_type == "audio/mpegurl") {
+ collection = new MediaCollection ();
+ var m_stream = new MemoryInputStream.from_data
+ (message.response_body.data, null);
+ var stream = new DataInputStream (m_stream);
+ size_t length;
+ debug ("Trying to parse playlist");
+ try {
+ var line = stream.read_line (out length);
+ while (line != null) {
+ while (line != null && line.has_prefix ("#")) {
+ line = stream.read_line (out length);
+ }
+ if (line == null) {
+ break;
+ }
- var collection = new MediaCollection.from_string (xml_string);
- if (collection.get_items ().length () == 0) {
- // FIXME: Return a more sensible error here.
- action.return_error (716, _("Resource not found"));
+ debug ("Adding uri with %s", line);
+ var item = collection.add_item ();
+ var resource = item.add_resource ();
+ resource.uri = line;
- return;
+ line = stream.read_line (out length);
+ }
+ } catch (Error error) {
+ debug ("Error in playlist: %s", error.message);
+ }
+ } else {
+ unowned string xml_string = (string) message.response_body.data;
+ collection = new MediaCollection.from_string (xml_string);
+ if (collection.get_items ().length () == 0) {
+ // FIXME: Return a more sensible error here.
+ action.return_error (716, _("Resource not found"));
+
+ return;
+ }
}
this.controller.set_playlist (collection);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]