core: Hide XBox album art handling
authorJens Georg <mail@jensge.org>
Thu, 8 Dec 2011 18:37:18 +0000 (19:37 +0100)
committerJens Georg <mail@jensge.org>
Wed, 14 Dec 2011 12:55:52 +0000 (13:55 +0100)
Simply check the request in the hack constructor and rewrite the URL
to our thumbnail request format.

src/rygel/rygel-client-hacks.vala
src/rygel/rygel-http-get.vala
src/rygel/rygel-xbox-hacks.vala
tests/rygel-http-get-test.vala
tests/rygel-http-post-test.vala

index 6b84e86..a79c69b 100644 (file)
@@ -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 {
index cbc8d6c..9e5f942 100644 (file)
@@ -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) {
index 95e11c9..07f4cfc 100644 (file)
@@ -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,
index d57028e..ce73dc6 100644 (file)
@@ -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) {
     }
 }
index 19e2d7b..7abdf87 100644 (file)
@@ -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;