diff options
author | Jens Georg <mail@jensge.org> | 2014-11-10 22:10:12 +0100 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2014-11-10 22:28:43 +0100 |
commit | f6fb662b1ab99dd90e60187c3422274d9b9424a2 (patch) | |
tree | 49d0a5e221d592510949e7d3fb3b54cdde1e9859 | |
parent | 903444992eb4c9dec0a772b033cf8a89103dbd59 (diff) | |
download | rygel-f6fb662b1ab99dd90e60187c3422274d9b9424a2.tar.gz |
server: Clean up MediaArtStore
Signed-off-by: Jens Georg <mail@jensge.org>
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/librygel-server/rygel-media-art-store.vala | 85 | ||||
-rw-r--r-- | src/librygel-server/rygel-music-item.vala | 10 | ||||
-rw-r--r-- | src/plugins/media-export/rygel-media-export-item-factory.vala | 2 |
4 files changed, 42 insertions, 57 deletions
diff --git a/configure.ac b/configure.ac index 57cd8ad2..70dde1ae 100644 --- a/configure.ac +++ b/configure.ac @@ -184,7 +184,7 @@ AS_IF([test "x$with_media_engine" = "xgstreamer"], sqlite3 >= $LIBSQLITE3_REQUIRED libmediaart-2.0 >= $MEDIAART_REQUIRED uuid]) - RYGEL_PLUGIN_MEDIA_EXPORT_DEPS_VALAFLAGS="$RYGEL_COMMON_MODULES_VALAFLAGS --pkg gupnp-dlna-2.0 --pkg gupnp-dlna-gst-2.0 --pkg gstreamer-tag-1.0 --pkg gstreamer-app-1.0 --pkg gstreamer-pbutils-1.0 --pkg sqlite3" + RYGEL_PLUGIN_MEDIA_EXPORT_DEPS_VALAFLAGS="$RYGEL_COMMON_MODULES_VALAFLAGS --pkg gupnp-dlna-2.0 --pkg gupnp-dlna-gst-2.0 --pkg gstreamer-tag-1.0 --pkg gstreamer-app-1.0 --pkg gstreamer-pbutils-1.0 --pkg sqlite3 --pkg libmediaart-2.0" AC_SUBST([RYGEL_PLUGIN_MEDIA_EXPORT_DEPS_VALAFLAGS]) ]) diff --git a/src/librygel-server/rygel-media-art-store.vala b/src/librygel-server/rygel-media-art-store.vala index cb91c1ef..b022716f 100644 --- a/src/librygel-server/rygel-media-art-store.vala +++ b/src/librygel-server/rygel-media-art-store.vala @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Jens Georg <mail@jensge.org>. + * Copyright (C) 2010-2014 Jens Georg <mail@jensge.org>. * Copyright (C) 2012 Intel Corporation. * * Author: Jens Georg <mail@jensge.org> @@ -34,8 +34,8 @@ internal errordomain MediaArtStoreError { public class Rygel.MediaArtStore : GLib.Object { private static MediaArtStore media_art_store; private static bool first_time = true; + private const string[] types = { "track", "album", "artist", "podcast", "radio", "video" }; - private string directory; private MediaArt.Process? media_art_process; public static MediaArtStore? get_default () { @@ -53,13 +53,15 @@ public class Rygel.MediaArtStore : GLib.Object { return media_art_store; } - public Thumbnail? find_media_art (MusicItem item, - bool simple = false) throws Error { - string[] types = { "track", "album", "artist", "podcast", "radio" }; + public Thumbnail? lookup_media_art (MusicItem item) throws Error { File file = null; - foreach (var type in types) { - file = this.get_media_art_file (type, item, simple); + foreach (var type in MediaArtStore.types) { + MediaArt.get_file (item.artist, + type == "album" ? item.album : item.title, + type, + out file); + if (file != null && file.query_exists (null)) { break; } else { @@ -86,62 +88,41 @@ public class Rygel.MediaArtStore : GLib.Object { return thumb; } - public Thumbnail? find_media_art_any (MusicItem item) throws Error { - var thumb = this.find_media_art (item); - - return thumb; - } - - public File? get_media_art_file (string type, - MusicItem item, - bool simple = false) { - File file; - - MediaArt.get_file (item.artist, - type == "album" ? item.album : item.title, - type, - out file); - - return file; - } - - public void add (MusicItem item, File file, uint8[]? data, string? mime) { + public void add (MusicItem item, File file, uint8[] data, string mime) { if (this.media_art_process == null) { return; } try { - if (data != null) { - this.media_art_process.buffer (MediaArt.Type.ALBUM, - MediaArt.ProcessFlags.NONE, - file, - data, - mime, - item.artist, - item.album); - } else { - this.media_art_process.file (MediaArt.Type.ALBUM, - MediaArt.ProcessFlags.NONE, - file, - item.artist, - item.album); - } + this.media_art_process.buffer (MediaArt.Type.ALBUM, + MediaArt.ProcessFlags.NONE, + file, + data, + mime, + item.artist, + item.album); } catch (Error error) { - warning ("%s", error.message); + warning (_("Failed to add album art for %s: %s"), + file.get_uri (), + error.message); } } - private MediaArtStore () throws MediaArtStoreError { - var dir = Path.build_filename (Environment.get_user_cache_dir (), - "media-art"); - var file = File.new_for_path (dir); - - if (!file.query_exists (null)) { - DirUtils.create_with_parents (dir, 0750); + public void search_media_art_for_file (MusicItem item, File file) { + try { + this.media_art_process.file (MediaArt.Type.ALBUM, + MediaArt.ProcessFlags.NONE, + file, + item.artist, + item.album); + } catch (Error error) { + warning (_("Failed to find media art for %s: %s"), + file.get_uri (), + error.message); } + } - this.directory = dir; - + private MediaArtStore () throws MediaArtStoreError { try { this.media_art_process = new MediaArt.Process (); } catch (Error error) { diff --git a/src/librygel-server/rygel-music-item.vala b/src/librygel-server/rygel-music-item.vala index a26d0180..a7963cb1 100644 --- a/src/librygel-server/rygel-music-item.vala +++ b/src/librygel-server/rygel-music-item.vala @@ -47,7 +47,9 @@ public class Rygel.MusicItem : AudioItem { } public void lookup_album_art () { - assert (this.album_art == null); + if (this.album_art != null) { + return; + } var media_art_store = MediaArtStore.get_default (); if (media_art_store == null) { @@ -55,8 +57,10 @@ public class Rygel.MusicItem : AudioItem { } try { - this.album_art = media_art_store.find_media_art_any (this); - } catch (Error err) {}; + this.album_art = media_art_store.lookup_media_art (this); + } catch (Error error) { + debug ("Failed to look up album art: %s", error.message); + }; } internal override void add_resources (DIDLLiteItem didl_item, diff --git a/src/plugins/media-export/rygel-media-export-item-factory.vala b/src/plugins/media-export/rygel-media-export-item-factory.vala index 8434fc95..a04b4557 100644 --- a/src/plugins/media-export/rygel-media-export-item-factory.vala +++ b/src/plugins/media-export/rygel-media-export-item-factory.vala @@ -278,7 +278,7 @@ namespace Rygel.MediaExport.ItemFactory { } if (sample == null) { - store.add (item, file, null, null); + store.search_media_art_for_file (item, file); return item; } |