core/tags/album: Query the Cover Art Archive for album art
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
570efda299
commit
940d2d1dc2
|
@ -7,4 +7,5 @@ res += SConscript("containers/Sconscript")
|
||||||
|
|
||||||
env.UsePackage("gstreamer-1.0")
|
env.UsePackage("gstreamer-1.0")
|
||||||
env.UsePackage("libmusicbrainz5");
|
env.UsePackage("libmusicbrainz5");
|
||||||
|
env.UsePackage("libcoverart");
|
||||||
Return("res")
|
Return("res")
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <core/string.h>
|
#include <core/string.h>
|
||||||
#include <core/version.h>
|
#include <core/version.h>
|
||||||
#include <core/tags/album.h>
|
#include <core/tags/album.h>
|
||||||
|
#include <coverart/caa_c.h>
|
||||||
#include <musicbrainz5/mb5_c.h>
|
#include <musicbrainz5/mb5_c.h>
|
||||||
|
|
||||||
static struct database album_db;
|
static struct database album_db;
|
||||||
|
@ -50,6 +51,56 @@ static Mb5Metadata __album_query_releaseid(struct album *album,
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool __album_fetch_cover(struct album *album, gchar *releaseid,
|
||||||
|
CaaCoverArt *caa)
|
||||||
|
{
|
||||||
|
struct cache_file file;
|
||||||
|
CaaImageData image;
|
||||||
|
gchar error[256];
|
||||||
|
|
||||||
|
image = caa_coverart_fetch_front(caa, releaseid);
|
||||||
|
if (!image) {
|
||||||
|
caa_coverart_get_lasterrormessage(caa, error, sizeof(error));
|
||||||
|
g_printf("Cover Art Archive: %s\n", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
__album_init_file(album, &file);
|
||||||
|
if (cache_file_open(&file, OPEN_WRITE)) {
|
||||||
|
cache_file_write(&file, caa_imagedata_data(image),
|
||||||
|
caa_imagedata_size(image));
|
||||||
|
cache_file_close(&file);
|
||||||
|
}
|
||||||
|
__album_deinit_file(&file);
|
||||||
|
|
||||||
|
caa_imagedata_delete(image);
|
||||||
|
return album_artwork_exists(album);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __album_foreach_fetch(struct album *album, Mb5Metadata metadata)
|
||||||
|
{
|
||||||
|
Mb5ReleaseList list = mb5_metadata_get_releaselist(metadata);
|
||||||
|
gchar releaseid[40];
|
||||||
|
Mb5Release release;
|
||||||
|
CaaCoverArt *caa;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
caa = caa_coverart_new(OCARINA_NAME);
|
||||||
|
if (!caa)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < mb5_release_list_size(list); i++) {
|
||||||
|
release = mb5_release_list_item(list, i);
|
||||||
|
if (!release)
|
||||||
|
break;
|
||||||
|
mb5_release_get_id(release, releaseid, sizeof(releaseid));
|
||||||
|
if (__album_fetch_cover(album, releaseid, caa))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
caa_coverart_delete(caa);
|
||||||
|
}
|
||||||
|
|
||||||
static bool __album_fetch_artwork(struct album *album)
|
static bool __album_fetch_artwork(struct album *album)
|
||||||
{
|
{
|
||||||
Mb5Metadata metadata;
|
Mb5Metadata metadata;
|
||||||
|
@ -64,8 +115,10 @@ static bool __album_fetch_artwork(struct album *album)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
metadata = __album_query_releaseid(album, mb5);
|
metadata = __album_query_releaseid(album, mb5);
|
||||||
if (metadata)
|
if (metadata) {
|
||||||
|
__album_foreach_fetch(album, metadata);
|
||||||
mb5_metadata_delete(metadata);
|
mb5_metadata_delete(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
ret = mb5_query_get_lasthttpcode(mb5) != 503;
|
ret = mb5_query_get_lasthttpcode(mb5) != 503;
|
||||||
mb5_query_delete(mb5);
|
mb5_query_delete(mb5);
|
||||||
|
|
|
@ -120,9 +120,9 @@ static void test_album_artwork()
|
||||||
|
|
||||||
while (idle_run_task()) {}
|
while (idle_run_task()) {}
|
||||||
|
|
||||||
test_equal(album_artwork_exists(ocarina), (bool)false);
|
test_equal(album_artwork_exists(ocarina), (bool)true);
|
||||||
test_equal(album_artwork_exists(majora), (bool)false);
|
test_equal(album_artwork_exists(majora), (bool)true);
|
||||||
test_equal(album_artwork_exists(wind), (bool)false);
|
test_equal(album_artwork_exists(wind), (bool)true);
|
||||||
|
|
||||||
album_db_deinit();
|
album_db_deinit();
|
||||||
artist_db_deinit();
|
artist_db_deinit();
|
||||||
|
|
Loading…
Reference in New Issue