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);