[rygel] server: Also serve subtitles as additional <res>
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] server: Also serve subtitles as additional <res>
- Date: Sun, 12 Jan 2020 18:51:17 +0000 (UTC)
commit c227c5d11babe62da609b07ed8f1d27e25fba4ca
Author: Jens Georg <mail jensge org>
Date: Sun Jan 12 19:49:57 2020 +0100
server: Also serve subtitles as additional <res>
src/librygel-server/rygel-subtitle.vala | 31 ++++++++++++++++++++--
src/librygel-server/rygel-video-item.vala | 44 +++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 2 deletions(-)
---
diff --git a/src/librygel-server/rygel-subtitle.vala b/src/librygel-server/rygel-subtitle.vala
index d81e9698..887e47e7 100644
--- a/src/librygel-server/rygel-subtitle.vala
+++ b/src/librygel-server/rygel-subtitle.vala
@@ -31,13 +31,16 @@ public class Rygel.Subtitle {
public string uri;
public string mime_type;
public string caption_type;
+ public string file_extension;
public int64 size = -1; // Size in bytes
- public Subtitle (string mime_type = "text/plain",
- string caption_type = "srt") {
+ public Subtitle (string mime_type = "text/srt",
+ string caption_type = "srt",
+ string file_extension = "srt") {
this.mime_type = mime_type;
this.caption_type = caption_type;
+ this.file_extension = file_extension;
}
internal void add_didl_node (DIDLLiteItem didl_item) {
@@ -64,4 +67,28 @@ public class Rygel.Subtitle {
sec_node->new_ns_prop (sec_ns, "type", this.caption_type);
}
+
+ internal virtual MediaResource get_resource (string protocol, int index) {
+ var name = "%s_subtitle_%2d".printf (protocol, index);
+
+ var res = new MediaResource (name);
+
+ res.size = this.size;
+ res.mime_type = "text/srt"; this.mime_type;
+ res.protocol = protocol;
+
+ // Note: These represent best-case. The MediaServer/HTTPServer can
+ // dial these back
+ res.dlna_flags |= DLNAFlags.INTERACTIVE_TRANSFER_MODE |
+ DLNAFlags.BACKGROUND_TRANSFER_MODE |
+ DLNAFlags.CONNECTION_STALL |
+ DLNAFlags.DLNA_V15;
+ res.dlna_operation = DLNAOperation.RANGE;
+ res.dlna_conversion = DLNAConversion.TRANSCODED;
+ res.extension = this.file_extension;
+
+ res.uri = this.uri;
+
+ return res;
+ }
}
diff --git a/src/librygel-server/rygel-video-item.vala b/src/librygel-server/rygel-video-item.vala
index 7c967ae7..78248225 100644
--- a/src/librygel-server/rygel-video-item.vala
+++ b/src/librygel-server/rygel-video-item.vala
@@ -190,19 +190,63 @@ public class Rygel.VideoItem : AudioItem, VisualItem {
// Work-around bgo#753382 - add subtitle to all resources
var resources = didl_item.get_resources ();
foreach (var resource in resources) {
+ // Don't add subtitles to subtitles
+ if (resource.protocol_info.mime_type == main_subtitle.mime_type) {
+ continue;
+ }
+
resource.subtitle_file_type =
main_subtitle.caption_type.up ();
resource.subtitle_file_uri = main_subtitle.uri;
}
}
+
}
return didl_item;
}
+ internal virtual void add_subtitle_resources (HTTPServer http_server) {
+ if (this.place_holder) {
+ return;
+ }
+
+ for (var i = 0; i < this.subtitles.size; i++) {
+ var subtitle = this.subtitles.get (i);
+ // Add the defined thumbnail uri unconditionally
+ // (it will be filtered out if the request is remote)
+ string protocol;
+ try {
+ protocol = this.get_protocol_for_uri (subtitle.uri);
+ } catch (Error e) {
+ message (_("Could not determine protocol for URI %s"),
+ subtitle.uri);
+
+ continue;
+ }
+
+ var subtitle_resource = subtitle.get_resource (protocol, i);
+ subtitle_resource.uri = subtitle.uri;
+ this.get_resource_list ().add (subtitle_resource);
+ if (http_server.need_proxy (subtitle.uri)) {
+ var http_sub_res = subtitle.get_resource
+ (http_server.get_protocol (), i);
+
+ // Make a http uri for the thumbnail
+ http_sub_res.uri = http_server.create_uri_for_object
+ (this,
+ -1,
+ i,
+ null);
+ this.get_resource_list ().add (http_sub_res);
+ }
+ }
+ }
+
internal override void add_additional_resources (HTTPServer server) {
base.add_additional_resources (server);
this.add_thumbnail_resources (server);
+ this.add_subtitle_resources (server);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]