summaryrefslogtreecommitdiff
path: root/src/librygel-renderer
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2017-04-30 19:59:56 +0200
committerJens Georg <mail@jensge.org>2017-04-30 21:58:17 +0200
commitec7e5dd971d1aed2df8688fe34d80176824ef8c7 (patch)
tree11533cde89ff6b6aa673d4fc9fddc1dc2a92872e /src/librygel-renderer
parent56e4fd19fb17eeba2b3e7ccd3c9ee8fee9efbfaf (diff)
downloadrygel-ec7e5dd971d1aed2df8688fe34d80176824ef8c7.tar.gz
renderer: Factor out M3U parsing
Diffstat (limited to 'src/librygel-renderer')
-rw-r--r--src/librygel-renderer/rygel-av-transport.vala70
1 files changed, 40 insertions, 30 deletions
diff --git a/src/librygel-renderer/rygel-av-transport.vala b/src/librygel-renderer/rygel-av-transport.vala
index 865e18eb..ded24355 100644
--- a/src/librygel-renderer/rygel-av-transport.vala
+++ b/src/librygel-renderer/rygel-av-transport.vala
@@ -720,6 +720,45 @@ internal class Rygel.AVTransport : Service {
this.changelog.log ("CurrentPlayMode", this.controller.play_mode);
}
+ private MediaCollection? parse_m3u_playlist (uint8[]? data) throws Error {
+ if (data == null) {
+ return null;
+ }
+
+ var collection = new MediaCollection ();
+ var m_stream = new MemoryInputStream.from_data (data, null);
+ var stream = new DataInputStream (m_stream);
+
+ debug ("Trying to parse m3u playlist");
+ size_t length;
+ 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);
+ }
+
+ return collection;
+ }
+
private async void handle_playlist (ServiceAction action,
string uri,
string metadata,
@@ -741,38 +780,9 @@ internal class Rygel.AVTransport : Service {
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);
- }
+ collection = parse_m3u_playlist (message.response_body.data);
} catch (Error error) {
warning (_("Problem parsing playlist: %s"), error.message);
// FIXME: Return a more sensible error here.