From e30f7f811568091b2d70714c4d4e6569f28f3597 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 12 Jul 2016 14:36:40 -0400 Subject: [PATCH] core/tags/album: Add support for importing album artwork This is needed so the user can manually set album artwork in the cases where either we don't fetch the right image or no image is found. Signed-off-by: Anna Schumaker --- core/tags/album.c | 15 +++++++++++++++ include/core/tags/album.h | 3 +++ tests/core/tags/album.c | 10 +++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/tags/album.c b/core/tags/album.c index 778c4269..7e784ea4 100644 --- a/core/tags/album.c +++ b/core/tags/album.c @@ -293,6 +293,21 @@ gchar *album_artwork_path(struct album *album) return ret; } +bool album_artwork_import(struct album *album, gchar *path) +{ + struct cache_file file; + bool ret = false; + + __album_init_file(album, &file); + if (path && cache_file_open(&file, OPEN_WRITE)) { + ret = cache_file_import(&file, path); + cache_file_close(&file); + } + __album_deinit_file(&file); + + return ret; +} + #ifdef CONFIG_TESTING const struct db_ops *test_album_ops() { return &album_ops; } #endif /* CONFIG_TESTING */ diff --git a/include/core/tags/album.h b/include/core/tags/album.h index 1d663350..82a80eae 100644 --- a/include/core/tags/album.h +++ b/include/core/tags/album.h @@ -55,6 +55,9 @@ bool album_artwork_exists(struct album *); */ gchar *album_artwork_path(struct album *); +/* Called to manually set artwork for a given album. */ +bool album_artwork_import(struct album *, gchar *); + #ifdef CONFIG_TESTING const struct db_ops *test_album_ops(); #endif /* CONFIG_TESTING */ diff --git a/tests/core/tags/album.c b/tests/core/tags/album.c index fc846880..8181bc96 100644 --- a/tests/core/tags/album.c +++ b/tests/core/tags/album.c @@ -101,7 +101,7 @@ static void test_album_db() static void test_album_artwork() { - struct album *ocarina, *majora, *wind; + struct album *ocarina, *majora, *wind, *ocarina_3d; gchar *o_path, *m_path, *w_path; struct artist *koji; const gchar *cache; @@ -137,6 +137,14 @@ static void test_album_artwork() test_str_equal(album_artwork_path(majora), m_path); test_str_equal(album_artwork_path(wind), w_path); + /* Import the original Ocarina of Time album art. */ + ocarina_3d = album_find("Ocarina of Time 3D", 2011); + test_equal(album_artwork_exists(ocarina_3d), (bool)false); + album_artwork_import(ocarina_3d, NULL); + test_equal(album_artwork_exists(ocarina_3d), (bool)false); + album_artwork_import(ocarina_3d, o_path); + test_equal(album_artwork_exists(ocarina_3d), (bool)true); + g_free(o_path); g_free(m_path); g_free(w_path);