[rygel] media-export: Export single title DVDs as video
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Export single title DVDs as video
- Date: Sat, 13 Feb 2016 20:04:59 +0000 (UTC)
commit 47d55aeb6c5568db68c4557a5003bddffb3c7ce9
Author: Jens Georg <mail jensge org>
Date: Sat Feb 13 20:17:21 2016 +0100
media-export: Export single title DVDs as video
If the DVD has only one title, don't bother with adding a container, just add
the title directly as a video
Signed-off-by: Jens Georg <mail jensge org>
.../rygel-media-export-dvd-container.vala | 39 ++++-------
.../media-export/rygel-media-export-dvd-track.vala | 73 ++++++++++---------
.../rygel-media-export-info-serializer.vala | 6 +-
.../rygel-media-export-item-factory.vala | 25 +++++--
.../rygel-media-export-object-factory.vala | 3 +
5 files changed, 75 insertions(+), 71 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-dvd-container.vala
b/src/plugins/media-export/rygel-media-export-dvd-container.vala
index 6c05896..6c85777 100644
--- a/src/plugins/media-export/rygel-media-export-dvd-container.vala
+++ b/src/plugins/media-export/rygel-media-export-dvd-container.vala
@@ -45,24 +45,28 @@ internal class Rygel.MediaExport.DVDContainer : SimpleContainer, UpdatableObject
public override void constructed () {
base.constructed ();
+ this.add_uri (File.new_for_path (path).get_uri ());
+
var cache_path = this.get_cache_path (this.path);
var doc = Xml.Parser.read_file (cache_path,
null,
Xml.ParserOption.NOERROR |
Xml.ParserOption.NOWARNING);
this.doc = new GUPnP.XMLDoc (doc);
- var it = doc->get_root_element ()->children;
- var child_count = 0;
- while (it != null) {
- if (it->name == "track") {
- child_count++;
+ var context = new Xml.XPath.Context (this.doc.doc);
+ var xpo = context.eval ("/lsdvd/track");
+ if (xpo->type != Xml.XPath.ObjectType.NODESET) {
+ warning ("No tracks found in DVD");
+ } else {
+ for (int i = 0; i < xpo->nodesetval->length (); i++) {
+ var node = xpo->nodesetval->item (i);
+ var item = this.get_item_for_xml (i, node);
+ this.add_child_item (item);
}
-
- it = it->next;
}
- this.child_count = child_count;
+ delete xpo;
}
public override async MediaObjects? get_children (
@@ -73,23 +77,6 @@ internal class Rygel.MediaExport.DVDContainer : SimpleContainer, UpdatableObject
throws Error {
var children = new MediaObjects ();
- var context = new Xml.XPath.Context (this.doc.doc);
- var xpo = context.eval ("/lsdvd/track");
- if (xpo->type != Xml.XPath.ObjectType.NODESET) {
- delete xpo;
- warning ("No tracks found in DVD");
-
- return children;
- }
-
- for (int i = 0; i < xpo->nodesetval->length (); i++) {
- var node = xpo->nodesetval->item (i);
- var item = this.get_item_for_xml (i, node);
- children.add (item);
- }
-
- delete xpo;
-
return children;
}
@@ -150,7 +137,7 @@ internal class Rygel.MediaExport.DVDContainer : SimpleContainer, UpdatableObject
private MediaFileItem get_item_for_xml (int track, Xml.Node *node) {
var item = new DVDTrack (this.get_track_id (track),
this,
- track,
+ _("Title %d").printf (track + 1),
node);
item.parent_ref = this;
diff --git a/src/plugins/media-export/rygel-media-export-dvd-track.vala
b/src/plugins/media-export/rygel-media-export-dvd-track.vala
index 0542843..e57d615 100644
--- a/src/plugins/media-export/rygel-media-export-dvd-track.vala
+++ b/src/plugins/media-export/rygel-media-export-dvd-track.vala
@@ -28,54 +28,57 @@ internal class Rygel.MediaExport.DVDTrack : Rygel.VideoItem {
public DVDTrack (string id,
MediaContainer parent,
- int track,
+ string title,
Xml.Node* node) {
Object (id : id,
parent : parent,
node : node,
- title : _("Title %d").printf (track + 1),
- upnp_class : Rygel.VideoItem.UPNP_CLASS,
- track : track);
+ title : title,
+ upnp_class : Rygel.VideoItem.UPNP_CLASS);
}
public override void constructed () {
base.constructed ();
- var uri = new Soup.URI (this.parent.get_uris ()[0]);
- uri.set_scheme ("dvd");
- uri.set_query ("title=%d".printf (track + 1));
- this.add_uri (uri.to_string (false));
+ // If we are created with a null node, then we are created from the
+ // database and all the information is already there.
+ if (this.node != null) {
+ var uri = new Soup.URI (this.parent.get_primary_uri ());
+ uri.set_scheme ("dvd");
+ uri.set_query ("title=%d".printf (track + 1));
+ this.add_uri (uri.to_string (false));
- this.dlna_profile = "MPEG_PS";
- this.mime_type = "video/mpeg";
+ this.dlna_profile = "MPEG_PS";
+ this.mime_type = "video/mpeg";
- var it = node->children;
- while (it != null) {
- if (it->name == "length") {
- this.duration = (int)double.parse (it->children->content);
- } else if (it->name == "width") {
- this.width = int.parse (it->children->content);
- } else if (it->name == "height") {
- this.height = int.parse (it->children->content);
- } else if (it->name == "PAL") {
- this.dlna_profile = "MPEG_PS_PAL";
- } else if (it->name == "NTSC") {
- this.dlna_profile = "MPEG_PS_NTSC";
+ var it = node->children;
+ while (it != null) {
+ if (it->name == "length") {
+ this.duration = (int) double.parse (it->children->content);
+ } else if (it->name == "width") {
+ this.width = int.parse (it->children->content);
+ } else if (it->name == "height") {
+ this.height = int.parse (it->children->content);
+ } else if (it->name == "PAL") {
+ this.dlna_profile = "MPEG_PS_PAL";
+ } else if (it->name == "NTSC") {
+ this.dlna_profile = "MPEG_PS_NTSC";
+ }
+ // TODO: Japanese formats...
+ it = it->next;
}
- // TODO: Japanese formats...
- it = it->next;
- }
- var media_engine = MediaEngine.get_default ();
- media_engine.get_resources_for_item.begin (this,
- (obj, res) => {
- var added_resources = media_engine
- .get_resources_for_item.end (res);
- debug ("Adding %d resources to this source %s",
- added_resources.size,
- this.get_primary_uri ());
- this.get_resource_list ().add_all (added_resources);
- });
+ var media_engine = MediaEngine.get_default ();
+ media_engine.get_resources_for_item.begin (this,
+ (obj, res) => {
+ var added_resources = media_engine
+ .get_resources_for_item.end (res);
+ debug ("Adding %d resources to this source %s",
+ added_resources.size,
+ this.get_primary_uri ());
+ this.get_resource_list ().add_all (added_resources);
+ });
+ }
}
public override MediaResource get_primary_resource () {
diff --git a/src/plugins/media-export/rygel-media-export-info-serializer.vala
b/src/plugins/media-export/rygel-media-export-info-serializer.vala
index c8cb786..e8d4568 100644
--- a/src/plugins/media-export/rygel-media-export-info-serializer.vala
+++ b/src/plugins/media-export/rygel-media-export-info-serializer.vala
@@ -109,12 +109,12 @@ internal class Rygel.InfoSerializer : GLib.Object {
}
private Variant serialize_file_info (FileInfo info) {
- return new Variant ("(sstt)",
+ return new Variant ("(stst)",
info.get_display_name (),
- ContentType.get_mime_type
- (info.get_content_type ()),
info.get_attribute_uint64
(FileAttribute.TIME_MODIFIED),
+ ContentType.get_mime_type
+ (info.get_content_type ()),
info.get_size ());
}
diff --git a/src/plugins/media-export/rygel-media-export-item-factory.vala
b/src/plugins/media-export/rygel-media-export-item-factory.vala
index 2520203..2acd9f1 100644
--- a/src/plugins/media-export/rygel-media-export-item-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-item-factory.vala
@@ -192,12 +192,23 @@ namespace Rygel.MediaExport.ItemFactory {
item = ItemFactory.create_playlist_item (file, parent, "");
break;
case DVDContainer.UPNP_CLASS:
- object = new DVDContainer ("dvd:" + id, parent, "", file.get_path ());
- object.add_uri (file.get_uri ());
+ var container = new DVDContainer ("dvd:" + id, parent, "", file.get_path ());
+ object = container;
if (file_info != null) {
apply_file_info (object, file_info);
- object.title = strip_invalid_entities (object.title);
+ object.title = strip_invalid_entities (object.title);
+ }
+
+ // If the DVD has a single track, just export that as a plain
+ // video. Copy over all important information such as
+ // modified, the uri and the title.
+ if (container.child_count == 1) {
+ object = container.children.get (0);
+ object.title = container.title;
+ object.modified = container.modified;
+ object.get_uris ().clear ();
+ object.add_uri (container.get_primary_uri ());
}
return object;
@@ -335,16 +346,17 @@ namespace Rygel.MediaExport.ItemFactory {
private static void apply_file_info (MediaObject object, Variant v)
throws Error {
- ItemFactory.check_variant_type (v, "(sstt)");
+ ItemFactory.check_variant_type (v, "(stst)");
var it = v.iterator ();
- Variant display_name;
- display_name = it.next_value ();
+ var display_name = it.next_value ();
if (object.title == null || object.title == "") {
object.title = display_name.dup_string ();
}
+ object.modified = (int64) it.next_value ().get_uint64 ();
+
if (object is MediaFileItem) {
var item = object as MediaFileItem;
@@ -353,7 +365,6 @@ namespace Rygel.MediaExport.ItemFactory {
item.mime_type = mime.dup_string ();
}
- item.modified = (int64) it.next_value ().get_uint64 ();
if (item.date == null) {
TimeVal tv = { (long) item.modified, 0 };
item.date = tv.to_iso8601 ();
diff --git a/src/plugins/media-export/rygel-media-export-object-factory.vala
b/src/plugins/media-export/rygel-media-export-object-factory.vala
index 8b55abe..a7a22ec 100644
--- a/src/plugins/media-export/rygel-media-export-object-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-object-factory.vala
@@ -99,6 +99,9 @@ internal class Rygel.MediaExport.ObjectFactory : Object {
case Rygel.AudioItem.UPNP_CLASS:
return new MusicItem (id, parent, title);
case Rygel.VideoItem.UPNP_CLASS:
+ if (id.has_prefix ("dvd-track")) {
+ return new DVDTrack (id, parent, title, null);
+ }
return new VideoItem (id, parent, title);
case Rygel.PhotoItem.UPNP_CLASS:
case Rygel.ImageItem.UPNP_CLASS:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]