[rygel] core: Serve video thumbnails to XBox 360



commit 2cdbbf07663d6fee81207bc184b1cfd04becf0d0
Author: Jens Georg <mail jensge org>
Date:   Sat May 7 19:06:22 2011 +0200

    core: Serve video thumbnails to XBox 360

 src/rygel/rygel-http-get.vala   |   19 +++++++++++++++++++
 src/rygel/rygel-xbox-hacks.vala |   22 ++++++++++++++++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/src/rygel/rygel-http-get.vala b/src/rygel/rygel-http-get.vala
index 89feb75..a8fc006 100644
--- a/src/rygel/rygel-http-get.vala
+++ b/src/rygel/rygel-http-get.vala
@@ -83,6 +83,25 @@ internal class Rygel.HTTPGet : HTTPRequest {
                                                   this.item.id);
         }
 
+        try {
+            var hack = new XBoxHacks.for_headers (this.msg.request_headers);
+            if (hack.is_album_art_request (this.msg) &&
+                this.item is VisualItem) {
+                var visual_item = this.item as VisualItem;
+
+                if (visual_item.thumbnails.size <= 0) {
+                    throw new HTTPRequestError.NOT_FOUND ("No Thumbnail " +
+                                                          "available for " +
+                                                          "item '%s'",
+                                                          visual_item.id);
+                }
+
+                this.thumbnail = visual_item.thumbnails.get (0);
+
+                return;
+            }
+        } catch (XBoxHacksError error) {}
+
         if (this.uri.thumbnail_index >= 0) {
             if (this.item is MusicItem) {
                 var music = this.item as MusicItem;
diff --git a/src/rygel/rygel-xbox-hacks.vala b/src/rygel/rygel-xbox-hacks.vala
index 8899d55..227cc70 100644
--- a/src/rygel/rygel-xbox-hacks.vala
+++ b/src/rygel/rygel-xbox-hacks.vala
@@ -38,6 +38,15 @@ internal class Rygel.XBoxHacks : GLib.Object {
 
     public XBoxHacks.for_action (ServiceAction action) throws XBoxHacksError {
         unowned MessageHeaders headers = action.get_message ().request_headers;
+        this.check_headers (headers);
+    }
+
+    public XBoxHacks.for_headers (MessageHeaders headers)
+                                  throws XBoxHacksError {
+        this.check_headers (headers);
+    }
+
+    private void check_headers (MessageHeaders headers) throws XBoxHacksError {
         var agent = headers.get_one ("User-Agent");
         if (agent == null ||
             !(agent.contains ("Xbox")) &&
@@ -46,6 +55,19 @@ internal class Rygel.XBoxHacks : GLib.Object {
         }
     }
 
+    public bool is_album_art_request (Soup.Message message) {
+        unowned string query = message.get_uri ().query;
+
+        if (query == null) {
+            return false;
+        }
+
+        var params = Soup.Form.decode (query);
+        var album_art = params.lookup ("albumArt");
+
+        return (album_art != null) && bool.parse (album_art);
+    }
+
     public void apply_on_device (RootDevice device,
                                  string     template_path) throws Error {
         if (!device.get_device_type ().has_prefix (DMS)) {



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