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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-07-12 14:36:40 -04:00
parent 80d921343d
commit e30f7f8115
3 changed files with 27 additions and 1 deletions

View File

@ -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 */

View File

@ -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 */

View File

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