[rygel/wip/dvd: 101/103] wip: Working playlist container



commit 07b92185dac3355ec30d46c989cdab44001304ff
Author: Jens Georg <mail jensge org>
Date:   Wed Sep 16 13:18:09 2015 +0200

    wip: Working playlist container

 .../rygel-media-export-dvd-container.vala          |   92 ++++++++++++++++++++
 .../rygel-media-export-dvd-parser.vala             |   17 ++--
 .../rygel-media-export-item-factory.vala           |   21 +++--
 3 files changed, 111 insertions(+), 19 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
new file mode 100644
index 0000000..df7fda6
--- /dev/null
+++ b/src/plugins/media-export/rygel-media-export-dvd-container.vala
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2015 Jens Georg <mail jensge org>.
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using Rygel;
+using Gee;
+
+internal class Rygel.DVDContainer : MediaContainer {
+    public new const string UPNP_CLASS = MediaContainer.PLAYLIST + ".DVD";
+    public string path { get; construct set; }
+
+    private GUPnP.XMLDoc doc;
+
+    public DVDContainer (string          id,
+                         MediaContainer? parent,
+                         string          title,
+                         string          path) {
+        Object (id : id,
+                upnp_class : DVDContainer.UPNP_CLASS,
+                title : title,
+                parent : parent,
+                child_count : 0,
+                path : path);
+    }
+
+    public override void constructed () {
+        base.constructed ();
+
+        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 == "title") {
+                this.title = it->children->content;
+            } else if (it->name == "track") {
+                child_count++;
+            }
+
+            it = it->next;
+        }
+
+        warning ("Found title %s, got %d children", this.title, child_count);
+    }
+
+    public override async MediaObjects? get_children (
+                                                     uint         offset,
+                                                     uint         max_count,
+                                                     string       sort_criteria,
+                                                     Cancellable? cancellable)
+                                                     throws Error {
+        return new MediaObjects ();
+    }
+
+    public override async MediaObject? find_object (string id,
+                                                    Cancellable? cancellable)
+                                                    throws Error {
+        return null;
+    }
+
+    private string get_cache_path (string image_path) {
+        unowned string user_cache = Environment.get_user_cache_dir ();
+        var id = Checksum.compute_for_string (ChecksumType.MD5, image_path);
+        var cache_folder = Path.build_filename (user_cache,
+                                                "rygel",
+                                                "dvd-content");
+        DirUtils.create_with_parents (cache_folder, 0700);
+        return Path.build_filename (cache_folder, id);
+    }
+
+}
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 f188db7..88a3ff2 100644
--- a/src/plugins/media-export/rygel-media-export-dvd-parser.vala
+++ b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
@@ -29,22 +29,24 @@ internal class Rygel.DVDParser : GLib.Object {
     public File file { public get; construct; }
 
     private File cache_file;
-    private string id;
 
     public DVDParser (File file) {
         Object (file : file);
     }
 
-    public override void constructed () {
+    public static string get_cache_path (string image_path) {
         unowned string user_cache = Environment.get_user_cache_dir ();
-        this.id = this.get_id (this.file);
+        var id = Checksum.compute_for_string (ChecksumType.MD5, image_path);
         var cache_folder = Path.build_filename (user_cache,
                                                 "rygel",
                                                 "dvd-content");
         DirUtils.create_with_parents (cache_folder, 0700);
-        var cache_path = Path.build_filename (cache_folder, this.id);
+        return Path.build_filename (cache_folder, id);
+    }
 
-        this.cache_file = File.new_for_path (cache_path);
+    public override void 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 {
@@ -78,9 +80,4 @@ internal class Rygel.DVDParser : GLib.Object {
                                      Xml.ParserOption.NOERROR |
                                      Xml.ParserOption.NOWARNING);
     }
-
-    private string get_id (File file) {
-        return Checksum.compute_for_string (ChecksumType.MD5,
-                                            file.get_uri ());
-    }
 }
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 311f3ac..4c84b4e 100644
--- a/src/plugins/media-export/rygel-media-export-item-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-item-factory.vala
@@ -100,10 +100,10 @@ namespace Rygel.MediaExport.ItemFactory {
         }
     }
 
-    static MediaFileItem? create_from_variant (MediaContainer parent,
-                                               File           file,
-                                               Variant        v)
-                                               throws Error {
+    static MediaObject? create_from_variant (MediaContainer parent,
+                                             File           file,
+                                             Variant        v)
+                                             throws Error {
         ItemFactory.check_variant_type (v,"(smvmvmvmvmvmv)");
 
         Variant? upnp_class,
@@ -151,8 +151,10 @@ namespace Rygel.MediaExport.ItemFactory {
         }
 
         MediaFileItem item = null;
-        warning ("upnp_class.get_string () ==================== %s",
-                upnp_class.get_string ());
+        MediaObject object = null;
+        warning ("upnp_class.get_string () ==================== %s - %s",
+                upnp_class.get_string (),
+                DVDContainer.UPNP_CLASS);
         switch (upnp_class.get_string ()) {
             case Rygel.PhotoItem.UPNP_CLASS:
                 item = new PhotoItem (id, parent, "");
@@ -166,10 +168,11 @@ namespace Rygel.MediaExport.ItemFactory {
             case Rygel.PlaylistItem.UPNP_CLASS:
                 item = ItemFactory.create_playlist_item (file, parent, "");
                 break;
-            case Rygel.MediaContainer.PLAYLIST + ".DVD":
+            case DVDContainer.UPNP_CLASS:
+                object = new DVDContainer (id, parent, "", file.get_path ());
+                object.add_uri (file.get_uri ());
                 warning ("=> Fkjdhkdsjhfkjdshdskjf ");
-                return null;
-                break;
+                return object;
             default:
                 return null;
         }


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