[rygel] server: Support SAMI(smi) subtitles



commit 2710535e33cb8a8e7229d23684767c5c185fa246
Author: Choe Hwanjin <choe hwanjin gmail com>
Date:   Thu Dec 20 00:30:30 2012 +0900

    server: Support SAMI(smi) subtitles
    
    https://bugzilla.gnome.org/show_bug.cgi?id=690533

 src/librygel-server/rygel-subtitle-manager.vala |   49 +++++++++++++++--------
 src/librygel-server/rygel-subtitle.vala         |   13 ++++++
 src/librygel-server/rygel-video-item.vala       |    4 +-
 3 files changed, 47 insertions(+), 19 deletions(-)
---
diff --git a/src/librygel-server/rygel-subtitle-manager.vala b/src/librygel-server/rygel-subtitle-manager.vala
index cb0cf09..65d6941 100644
--- a/src/librygel-server/rygel-subtitle-manager.vala
+++ b/src/librygel-server/rygel-subtitle-manager.vala
@@ -22,6 +22,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+using Gee;
+
 internal errordomain SubtitleManagerError {
     NO_SUBTITLE
 }
@@ -40,36 +42,49 @@ internal class Rygel.SubtitleManager : GLib.Object {
         return manager;
     }
 
-    public Subtitle get_subtitle (string uri) throws Error {
+    public ArrayList<Subtitle> get_subtitles (string uri) throws Error {
         var video_file = File.new_for_uri (uri);
 
         var directory = video_file.get_parent ();
-        var filename = video_file.get_basename ();
-        var ext_index = filename.last_index_of_char ('.');
+        var basename = video_file.get_basename ();
+        var ext_index = basename.last_index_of_char ('.');
         if (ext_index >= 0) {
-            filename = filename[0:ext_index];
+            basename = basename[0:ext_index];
         }
+
         // FIXME: foreach ".eng.srt", ".ger.srt", ".srt"...
         // FIXME: case insensitive?
-        filename += ".srt";
+        string[] exts = { "srt", "smi" };
+
+        var subtitles = new ArrayList<Subtitle> ();
+        foreach (string ext in exts) {
+            string filename = basename + "." + ext;
 
-        var srt_file = directory.get_child (filename);
+            var subtitle_file = directory.get_child (filename);
 
-        var info = srt_file.query_info (FileAttribute.ACCESS_CAN_READ + "," +
-                                        FileAttribute.STANDARD_SIZE,
-                                        FileQueryInfoFlags.NONE,
-                                        null);
+            try {
+                var info = subtitle_file.query_info (FileAttribute.ACCESS_CAN_READ + "," +
+                                                     FileAttribute.STANDARD_SIZE + "," +
+                                                     FileAttribute.STANDARD_CONTENT_TYPE,
+                                                     FileQueryInfoFlags.NONE,
+                                                     null);
 
-        if (!info.get_attribute_boolean (FileAttribute.ACCESS_CAN_READ)) {
+                if (info.get_attribute_boolean (FileAttribute.ACCESS_CAN_READ)) {
+                    string content_type = info.get_attribute_string (FileAttribute.STANDARD_CONTENT_TYPE);
+                    var subtitle = new Subtitle (content_type, ext);
+                    subtitle.uri = subtitle_file.get_uri ();
+                    subtitle.size = (int64) info.get_attribute_uint64
+                                                    (FileAttribute.STANDARD_SIZE);
+                    subtitles.add(subtitle);
+                }
+            } catch (Error err) { }
+        }
+
+        if (subtitles.size == 0) {
             throw new SubtitleManagerError.NO_SUBTITLE
                                         (_("No subtitle available"));
         }
 
-        var subtitle = new Subtitle ();
-        subtitle.uri = srt_file.get_uri ();
-        subtitle.size = (int64) info.get_attribute_uint64
-                                        (FileAttribute.STANDARD_SIZE);
-
-        return subtitle;
+        return subtitles;
     }
 }
diff --git a/src/librygel-server/rygel-subtitle.vala b/src/librygel-server/rygel-subtitle.vala
index 0e4ff4f..5f806ef 100644
--- a/src/librygel-server/rygel-subtitle.vala
+++ b/src/librygel-server/rygel-subtitle.vala
@@ -45,6 +45,19 @@ public class Rygel.Subtitle {
         Xml.Node *root_node = item_node->doc->get_root_element ();
 
         weak Xml.Ns sec_ns = root_node->new_ns ("http://www.sec.co.kr/";, "sec");
+        // sec_ns apparently already existed. Search for the namespace node
+        if (sec_ns == null) {
+            weak Xml.Ns it = root_node->ns_def;
+            while (it != null) {
+                if (it.prefix == "sec") {
+                    sec_ns = it;
+
+                    break;
+                }
+                it = it.next;
+            }
+        }
+
         Xml.Node *sec_node = item_node->new_child (sec_ns,
                                                    "CaptionInfoEx",
                                                    this.uri);
diff --git a/src/librygel-server/rygel-video-item.vala b/src/librygel-server/rygel-video-item.vala
index 38082c0..9a056f0 100644
--- a/src/librygel-server/rygel-video-item.vala
+++ b/src/librygel-server/rygel-video-item.vala
@@ -93,8 +93,8 @@ public class Rygel.VideoItem : AudioItem, VisualItem {
 
         if (subtitle_manager != null) {
             try {
-                var subtitle = subtitle_manager.get_subtitle (uri);
-                this.subtitles.add (subtitle);
+                var subtitles = subtitle_manager.get_subtitles (uri);
+                this.subtitles.add_all (subtitles);
             } catch (Error err) {}
         }
     }



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