[rygel] renderer: Support m3u playlists
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] renderer: Support m3u playlists
- Date: Sat, 28 Jun 2014 11:08:44 +0000 (UTC)
commit 42ddac4a1195d5308115c6837ea0099ea4cc2bda
Author: Jens Georg <mail jensge org>
Date: Wed Nov 21 20:48:07 2012 +0100
renderer: Support m3u playlists
Some internet radios use that as stream redirector and it's the preferred
playlist format of UPnP.
src/librygel-renderer/rygel-av-transport.vala | 62 +++++++++++++++++---
.../rygel-media-renderer-plugin.vala | 5 ++
2 files changed, 59 insertions(+), 8 deletions(-)
---
diff --git a/src/librygel-renderer/rygel-av-transport.vala b/src/librygel-renderer/rygel-av-transport.vala
index 361df7e..5d55612 100644
--- a/src/librygel-renderer/rygel-av-transport.vala
+++ b/src/librygel-renderer/rygel-av-transport.vala
@@ -696,14 +696,58 @@ 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.has_suffix ("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 m3u playlist");
+ try {
+ var line = stream.read_line (out length);
+ while (line != null) {
+
+ // Swallow comments
+ while (line != null && line.has_prefix ("#")) {
+ line = stream.read_line (out length);
+ }
+
+ // No more lines after comments
+ if (line == null) {
+ break;
+ }
+
+ debug ("Adding uri with %s", line);
+ var item = collection.add_item ();
+ item.upnp_class = "object.item.audioItem";
+
+ var resource = item.add_resource ();
+ var pi = new ProtocolInfo.from_string ("*:*:*:*");
+ resource.set_protocol_info (pi);
+ resource.uri = line.strip ();
+
+ line = stream.read_line (out length);
+ }
+ } catch (Error error) {
+ warning (_("Problem parsing playlist: %s"), error.message);
+ // FIXME: Return a more sensible error here.
+ action.return_error (716, _("Resource not found"));
- 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"));
+ return;
+ }
+ } 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;
+ return;
+ }
}
switch (action.get_name ()) {
@@ -721,8 +765,10 @@ internal class Rygel.AVTransport : Service {
}
private bool is_playlist (string? mime, string? features) {
- return mime == "text/xml" && features != null &&
- features.has_prefix ("DLNA.ORG_PN=DIDL_S");
+ return (mime != null && mime == "text/xml" &&
+ features != null &&
+ features.has_prefix ("DLNA.ORG_PN=DIDL_S")) ||
+ mime.has_suffix ("mpegurl");
}
bool head_faked;
diff --git a/src/librygel-renderer/rygel-media-renderer-plugin.vala
b/src/librygel-renderer/rygel-media-renderer-plugin.vala
index c6abf2c..4d27406 100644
--- a/src/librygel-renderer/rygel-media-renderer-plugin.vala
+++ b/src/librygel-renderer/rygel-media-renderer-plugin.vala
@@ -155,6 +155,11 @@ public class Rygel.MediaRendererPlugin : Rygel.Plugin {
var mime_types = player.get_mime_types ();
+ mime_types += "audio/mpegurl";
+ mime_types += "audio/x-mpegurl";
+ mime_types += "video/mpegurl";
+ mime_types += "video/x-mpegurl";
+
foreach (var protocol in protocols) {
if (protocols[0] != protocol ||
this.sink_protocol_info != "") {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]