[rygel] media-export: Port DVD parser to new Extractor



commit f854450c95a8e1d44ecca744b21c83b9be72c2f2
Author: Jens Georg <mail jensge org>
Date:   Sun Jun 26 22:52:43 2016 +0200

    media-export: Port DVD parser to new Extractor
    
    Signed-off-by: Jens Georg <mail jensge org>

 .../rygel-media-export-dvd-parser.vala             |   63 ++++++++++++++++++--
 .../media-export/rygel-media-export-extract.vala   |    2 +-
 .../media-export/rygel-media-export-extractor.vala |    1 +
 3 files changed, 60 insertions(+), 6 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-dvd-parser.vala 
b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
index eede661..a455377 100644
--- a/src/plugins/media-export/rygel-media-export-dvd-parser.vala
+++ b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
@@ -25,10 +25,7 @@ internal errordomain DVDParserError {
     NOT_AVAILABLE;
 }
 
-internal class Rygel.DVDParser : GLib.Object {
-    /// URI to the image / toplevel directory
-    public File file { public get; construct; }
-
+internal class Rygel.MediaExport.DVDParser : Extractor {
     private File cache_file;
     private static string? lsdvd_binary_path;
 
@@ -53,15 +50,20 @@ internal class Rygel.DVDParser : GLib.Object {
                                                 "rygel",
                                                 "dvd-content");
         DirUtils.create_with_parents (cache_folder, 0700);
+
         return Path.build_filename (cache_folder, id);
     }
 
     public override void constructed () {
+        base.constructed ();
+
         var path = DVDParser.get_cache_path (this.file.get_path ());
         this.cache_file = File.new_for_path (path);
     }
 
-    public async void run () throws Error {
+    public async override void run () throws Error {
+        yield base.run ();
+
         if (DVDParser.lsdvd_binary_path == null) {
             throw new DVDParserError.NOT_AVAILABLE ("No DVD extractor found");
         }
@@ -71,6 +73,57 @@ internal class Rygel.DVDParser : GLib.Object {
             throw new DVDParserError.GENERAL ("Failed to read cache file");
         }
 
+        var context = new Xml.XPath.Context (doc);
+        var xpo = context.eval ("/lsdvd/track");
+        if ((xpo != null) &&
+            (xpo->type == Xml.XPath.ObjectType.NODESET) &&
+            (xpo->nodesetval->length () == 1)) {
+            this.serialized_info.insert ("UPnPClass", "s", UPNP_CLASS_VIDEO);
+            this.serialized_info.insert ("MimeType", "s", "video/mpeg");
+
+            var node = xpo->nodesetval->item (0);
+
+            var it = node->children;
+            while (it != null) {
+                if (it->name == "length") {
+                    var duration =  (int) double.parse (it->children->content);
+
+                    this.serialized_info.insert ("Duration",
+                                                 "i",
+                                                 duration);
+                } else if (it->name == "width") {
+                    var width = int.parse (it->children->content);
+                    this.serialized_info.insert ("VideoWidth",
+                                                 "i",
+                                                 width);
+                } else if (it->name == "height") {
+                    var height = int.parse (it->children->content);
+                    this.serialized_info.insert ("VideoHeight",
+                                                 "i",
+                                                 height);
+                } else if (it->name == "format") {
+                    var dlna_profile = "MPEG_PS_" + it->children->content;
+                    this.serialized_info.insert ("DLNAProfile",
+                                                 "s",
+                                                 dlna_profile);
+                }
+                // TODO: Japanese formats...
+
+                it = it->next;
+            }
+        } else {
+            this.serialized_info.insert ("UPnPClass",
+                                         "s",
+                                         UPNP_CLASS_PLAYLIST_CONTAINER_DVD);
+            this.serialized_info.insert ("MimeType",
+                                         "s",
+                                         "application/x-cd-image");
+        }
+
+        if (xpo != null) {
+            delete xpo;
+        }
+
         delete doc;
     }
 
diff --git a/src/plugins/media-export/rygel-media-export-extract.vala 
b/src/plugins/media-export/rygel-media-export-extract.vala
index 445a9f3..dbd6926 100644
--- a/src/plugins/media-export/rygel-media-export-extract.vala
+++ b/src/plugins/media-export/rygel-media-export-extract.vala
@@ -86,7 +86,7 @@ async void run () {
                         var is_text = parts[1].has_prefix ("text/") ||
                                       parts[1].has_suffix ("xml");
                         if (parts[1] == "application/x-cd-image") {
-                            extractor = new Extractor (file);
+                            extractor = new DVDParser (file);
                         } else if (!is_text) {
                             extractor = new GenericExtractor (file);
                         } else {
diff --git a/src/plugins/media-export/rygel-media-export-extractor.vala 
b/src/plugins/media-export/rygel-media-export-extractor.vala
index 89aef91..db487e5 100644
--- a/src/plugins/media-export/rygel-media-export-extractor.vala
+++ b/src/plugins/media-export/rygel-media-export-extractor.vala
@@ -47,6 +47,7 @@ public class Rygel.MediaExport.Extractor : Object {
     private static Regex[] video_suffix_regexes;
 
     public File file { get; construct set; }
+
     protected VariantDict serialized_info;
 
     public Extractor (File file) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]