[rygel] core: Hide XBox album art handling



commit 25fdadad00a9d41377acd58692b208ed73ffa8a9
Author: Jens Georg <mail jensge org>
Date:   Thu Dec 8 19:37:18 2011 +0100

    core: Hide XBox album art handling
    
    Simply check the request in the hack constructor and rewrite the URL
    to our thumbnail request format.

 src/rygel/rygel-client-hacks.vala |   13 -------------
 src/rygel/rygel-http-get.vala     |   18 +-----------------
 src/rygel/rygel-xbox-hacks.vala   |   19 +++++++++++++++++++
 tests/rygel-http-get-test.vala    |    4 ----
 tests/rygel-http-post-test.vala   |   13 +++++++++++++
 5 files changed, 33 insertions(+), 34 deletions(-)
---
diff --git a/src/rygel/rygel-client-hacks.vala b/src/rygel/rygel-client-hacks.vala
index 6b84e86..a79c69b 100644
--- a/src/rygel/rygel-client-hacks.vala
+++ b/src/rygel/rygel-client-hacks.vala
@@ -53,19 +53,6 @@ internal abstract class Rygel.ClientHacks : 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 static ClientHacks create (Message? message)
                                       throws ClientHacksError {
         try {
diff --git a/src/rygel/rygel-http-get.vala b/src/rygel/rygel-http-get.vala
index cbc8d6c..9e5f942 100644
--- a/src/rygel/rygel-http-get.vala
+++ b/src/rygel/rygel-http-get.vala
@@ -84,23 +84,7 @@ internal class Rygel.HTTPGet : HTTPRequest {
         }
 
         if (this.hack != null) {
-            if (this.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;
-            } else {
-                this.hack.apply (this.item);
-            }
+            this.hack.apply (item);
         }
 
         if (this.uri.thumbnail_index >= 0) {
diff --git a/src/rygel/rygel-xbox-hacks.vala b/src/rygel/rygel-xbox-hacks.vala
index 95e11c9..07f4cfc 100644
--- a/src/rygel/rygel-xbox-hacks.vala
+++ b/src/rygel/rygel-xbox-hacks.vala
@@ -37,6 +37,25 @@ internal class Rygel.XBoxHacks : ClientHacks {
         base (AGENT, message);
 
         this.object_id = CONTAINER_ID;
+        // Rewrite request URI to be a thumbnail request if it matches those
+        // weird XBox thumbnail requests
+        if (message == null) {
+            return;
+        }
+
+        unowned Soup.URI uri = message.get_uri ();
+        unowned string query = uri.query;
+        if (query == null) {
+            return;
+        }
+        var params = Soup.Form.decode (query);
+        var album_art = params.lookup ("albumArt");
+
+        if ((album_art == null) || !bool.parse (album_art)) {
+            return;
+        }
+
+        uri.set_path (uri.get_path () + "/th/0");
     }
 
     public void apply_on_device (RootDevice device,
diff --git a/tests/rygel-http-get-test.vala b/tests/rygel-http-get-test.vala
index d57028e..ce73dc6 100644
--- a/tests/rygel-http-get-test.vala
+++ b/tests/rygel-http-get-test.vala
@@ -38,10 +38,6 @@ public class Rygel.ClientHacks {
         throw new ClientHacksError.NA ("");
     }
 
-    public bool is_album_art_request (Message message) {
-        return false;
-    }
-
     public void apply (MediaItem item) {
     }
 }
diff --git a/tests/rygel-http-post-test.vala b/tests/rygel-http-post-test.vala
index 19e2d7b..7abdf87 100644
--- a/tests/rygel-http-post-test.vala
+++ b/tests/rygel-http-post-test.vala
@@ -29,6 +29,19 @@ public errordomain Rygel.TestError {
     TIMEOUT
 }
 
+public errordomain Rygel.ClientHacksError {
+    NA
+}
+
+public class Rygel.ClientHacks {
+    public static ClientHacks create (Message? message) throws Error {
+        throw new ClientHacksError.NA ("");
+    }
+
+    public void apply (MediaItem item) {
+    }
+}
+
 public class Rygel.HTTPPostTest : GLib.Object {
     protected HTTPServer server;
     protected HTTPClient client;



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