[rygel] server: Port media-art lookup to libmediaart



commit 1903a5e73499cbe365f116d6b41970971d9e2e35
Author: Jens Georg <mail jensge org>
Date:   Sat Jun 14 19:31:22 2014 +0200

    server: Port media-art lookup to libmediaart
    
    Signed-off-by: Jens Georg <mail jensge org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710387

 configure.ac                                   |    7 +-
 src/librygel-server/Makefile.am                |    3 +-
 src/librygel-server/libmediaart-1.0.vapi       |   35 ++++++
 src/librygel-server/rygel-media-art-store.vala |  139 ++----------------------
 4 files changed, 53 insertions(+), 131 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d5ef5a6..f0e44cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,6 +46,7 @@ GEE_REQUIRED=0.8.0
 UUID_REQUIRED=1.41.3
 LIBSOUP_REQUIRED=2.44.0
 GTK_REQUIRED=3.0
+MEDIAART_REQUIRED=0.4.0
 
 dnl Additional requirements for media-export plugin
 GSTREAMER_TAG_REQUIRED=1.0
@@ -67,7 +68,11 @@ LIBRYGEL_CORE_DEPS_VALAFLAGS="$RYGEL_BASE_MODULES_VALAFLAGS --pkg gssdp-1.0 --pk
 AC_SUBST([LIBRYGEL_CORE_DEPS_VALAFLAGS])
 
 RYGEL_COMMON_MODULES="$RYGEL_BASE_MODULES gupnp-av-1.0 >= $GUPNP_AV_REQUIRED"
-PKG_CHECK_MODULES([LIBRYGEL_SERVER_DEPS], [$RYGEL_COMMON_MODULES uuid >= $UUID_REQUIRED gssdp-1.0 >= 
$GSSDP_REQUIRED gio-2.0 >= $GIO_REQUIRED gmodule-2.0 libxml-2.0 >= $LIBXML_REQUIRED libsoup-2.4 >= 
$LIBSOUP_REQUIRED])
+PKG_CHECK_MODULES([LIBRYGEL_SERVER_DEPS], [$RYGEL_COMMON_MODULES uuid >=
+                   $UUID_REQUIRED gssdp-1.0 >= $GSSDP_REQUIRED gio-2.0 >=
+                   $GIO_REQUIRED gmodule-2.0 libxml-2.0 >= $LIBXML_REQUIRED
+                   libsoup-2.4 >= $LIBSOUP_REQUIRED libmediaart-1.0 >=
+                   $MEDIAART_REQUIRED])
 RYGEL_COMMON_MODULES_VALAFLAGS="$RYGEL_BASE_MODULES_VALAFLAGS --pkg gupnp-av-1.0"
 LIBRYGEL_SERVER_DEPS_VALAFLAGS="$RYGEL_COMMON_MODULES_VALAFLAGS --pkg gssdp-1.0 --pkg gio-2.0 --pkg 
libsoup-2.4 --pkg gmodule-2.0"
 AC_SUBST([LIBRYGEL_SERVER_DEPS_VALAFLAGS])
diff --git a/src/librygel-server/Makefile.am b/src/librygel-server/Makefile.am
index 4781ef1..6426f5e 100644
--- a/src/librygel-server/Makefile.am
+++ b/src/librygel-server/Makefile.am
@@ -16,7 +16,8 @@ librygel_server_2_2_la_VALAFLAGS = \
        -H rygel-server.h --library=rygel-server-2.2 \
        $(LIBRYGEL_SERVER_DEPS_VALAFLAGS) \
        $(RYGEL_COMMON_LIBRYGEL_CORE_VALAFLAGS) \
-       $(RYGEL_COMMON_VALAFLAGS)
+       $(RYGEL_COMMON_VALAFLAGS) \
+       $(srcdir)/libmediaart-1.0.vapi
 
 librygel_server_2_2_la_CFLAGS = \
        $(LIBRYGEL_SERVER_DEPS_CFLAGS) \
diff --git a/src/librygel-server/libmediaart-1.0.vapi b/src/librygel-server/libmediaart-1.0.vapi
new file mode 100644
index 0000000..8433ba2
--- /dev/null
+++ b/src/librygel-server/libmediaart-1.0.vapi
@@ -0,0 +1,35 @@
+/* libmediaart-1.0.vapi generated by vapigen, do not modify. */
+
+[CCode (cprefix = "MediaArt", gir_namespace = "MediaArt", gir_version = "1.0", lower_case_cprefix = 
"media_art_")]
+namespace MediaArt {
+       [CCode (cheader_filename = "libmediaart/mediaart.h", cprefix = "MEDIA_ART_", has_type_id = false)]
+       public enum Type {
+               NONE,
+               ALBUM,
+               VIDEO
+       }
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static bool buffer_to_jpeg (uint8 buffer, ulong len, string buffer_mime, string target);
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static bool file_to_jpeg (string filename, string target);
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static void get_file (string artist, string title, string prefix, GLib.File? file, out 
GLib.File cache_file, out GLib.File local_file);
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static void get_path (string artist, string title, string prefix, string? uri, out string 
path, out string local_uri);
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static bool init ();
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static void plugin_init (int max_width);
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static void plugin_shutdown ();
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static bool process ([CCode (array_length_cname = "len", array_length_pos = 1.5, 
array_length_type = "gulong")] uint8[] buffer, string mime, MediaArt.Type type, string? artist, string? 
title, string uri);
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static bool process_file ([CCode (array_length_cname = "len", array_length_pos = 1.5, 
array_length_type = "gsize")] uint8[]? buffer, string mime, MediaArt.Type type, string artist, string title, 
GLib.File file);
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static bool remove (string artist, string? album);
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static void shutdown ();
+       [CCode (cheader_filename = "libmediaart/mediaart.h")]
+       public static string strip_invalid_entities (string original);
+}
diff --git a/src/librygel-server/rygel-media-art-store.vala b/src/librygel-server/rygel-media-art-store.vala
index 5160760..ed72480 100644
--- a/src/librygel-server/rygel-media-art-store.vala
+++ b/src/librygel-server/rygel-media-art-store.vala
@@ -28,21 +28,12 @@ internal errordomain MediaArtStoreError {
 
 /**
  * This maps RygelMusicItem objects to their cached cover art,
- * implementing the GNOME [[https://live.gnome.org/MediaArtStorageSpec|MediaArt storage specification]]
- * and the simplified version that Banshee uses.
+ * implementing the GNOME
+ * [[https://live.gnome.org/MediaArtStorageSpec|MediaArt storage specification]].
  */
 public class Rygel.MediaArtStore : GLib.Object {
-    private const string PLACEHOLDER_HASH = "7215ee9c7d9dc229d2921a40e899ec5f";
-    private const string INVALID_CHARS = "()[]<>{}_! #$^&*+=|\\/\"'?~";
-    private const string CONVERT_CHARS = "\t";
-    private const string BLOCK_PATTERN = "%s[^%s]*%s";
-    private const string[] BLOCKS = { "()", "{}", "[]", "<>" };
     private static MediaArtStore media_art_store;
     private static bool first_time = true;
-    private Regex char_remove_regex;
-    private Regex char_convert_regex;
-    private Regex space_compress_regex;
-    private Regex[] block_regexes;
 
     private string directory;
 
@@ -95,9 +86,6 @@ public class Rygel.MediaArtStore : GLib.Object {
 
     public Thumbnail? find_media_art_any (MusicItem item) throws Error {
         var thumb = this.find_media_art (item);
-        if (thumb == null) {
-            thumb = this.find_media_art (item, true);
-        }
 
         return thumb;
     }
@@ -105,21 +93,16 @@ public class Rygel.MediaArtStore : GLib.Object {
     public File get_media_art_file (string    type,
                                     MusicItem item,
                                     bool      simple = false) {
-        string hash;
-        string suffix;
-
-        if (simple) {
-            hash = this.get_simple_hash (type, item);
-            suffix = "jpg";
-        } else {
-            hash = this.get_hash (type, item);
-            suffix = "jpeg";
-        }
-        var file_path = "%s-%s.%s".printf (type, hash, suffix);
+        File file;
 
-        var path = Path.build_filename (this.directory, file_path);
+        MediaArt.get_file (item.artist,
+                           type == "album" ? item.album : item.title,
+                           type,
+                           null,
+                           out file,
+                           null);
 
-        return File.new_for_path (path);
+        return file;
     }
 
     private MediaArtStore () throws MediaArtStoreError {
@@ -132,107 +115,5 @@ public class Rygel.MediaArtStore : GLib.Object {
         }
 
         this.directory = dir;
-        try {
-            var regex_string = Regex.escape_string (INVALID_CHARS);
-            char_remove_regex = new Regex ("[%s]".printf (regex_string));
-            regex_string = Regex.escape_string (CONVERT_CHARS);
-            char_convert_regex = new Regex ("[%s]".printf (regex_string));
-            space_compress_regex = new Regex ("\\s+");
-            block_regexes = new Regex[0];
-
-            foreach (var block in BLOCKS) {
-                var block_re = BLOCK_PATTERN.printf (
-                                  Regex.escape_string ("%C".printf (block[0])),
-                                  Regex.escape_string ("%C".printf (block[1])),
-                                  Regex.escape_string ("%C".printf (block[1])));
-                block_regexes += new Regex (block_re);
-            }
-        } catch (RegexError error) {
-            assert_not_reached ();
-        }
-    }
-
-    private string get_simple_hash (string type, MusicItem item) {
-        string hash;
-        switch (type) {
-            case "artist":
-                case "radio":
-                hash = this.normalize_and_hash (item.artist);
-                break;
-            case "podcast":
-                hash = this.normalize_and_hash (item.title);
-                break;
-            case "album":
-                hash = this.normalize_and_hash (item.artist + "\t" +
-                                                item.album);
-                break;
-            case "track":
-                hash = this.normalize_and_hash (item.artist + "\t" +
-                                                item.album + "\t" +
-                                                item.title);
-                break;
-            default:
-                assert_not_reached ();
-        }
-
-        return hash;
-    }
-
-    private string get_hash (string type, MusicItem item) {
-        string b = null, c = null;
-        switch (type) {
-            case "track":
-                b = this.normalize_and_hash (item.artist, false) + "-" +
-                    this.normalize_and_hash (item.album, false);
-                c = this.normalize_and_hash (item.title, false);
-                break;
-            case "album":
-            case "artist":
-                b = this.normalize_and_hash (item.artist, false);
-                c = this.normalize_and_hash (item.album, false);
-                break;
-            case "radio":
-            case "podcast":
-                b = this.normalize_and_hash (item.title, false);
-                c = PLACEHOLDER_HASH;
-                break;
-        }
-
-        return "%s-%s".printf (b, c);
-    }
-
-    private string normalize_and_hash (string? input, bool utf8_only = true) {
-        string normalized = " ";
-        if (input != null && input != "") {
-            if (utf8_only) {
-                normalized = input;
-            } else {
-                normalized = this.strip_invalid_entities (input);
-                normalized = normalized.down ();
-            }
-            normalized = normalized.normalize (-1, NormalizeMode.ALL);
-        }
-
-        return Checksum.compute_for_string (ChecksumType.MD5, normalized);
-    }
-
-    string strip_invalid_entities (string original) {
-        string p;
-
-        p = original;
-
-        try {
-            foreach (var re in block_regexes) {
-                p = re.replace_literal (p, -1, 0, "");
-            }
-
-            p = char_remove_regex.replace_literal (p, -1, 0, "");
-            p = char_convert_regex.replace_literal (p, -1, 0, " ");
-            p = space_compress_regex.replace_literal (p, -1, 0, " ");
-
-            return p;
-        } catch (RegexError error) {
-            assert_not_reached ();
-        }
     }
 }


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