diff options
author | 2010-04-04 16:45:49 +0200 | |
---|---|---|
committer | 2010-04-04 16:45:49 +0200 | |
commit | 71eca007f97a7b27a8d6029e5240501ab2db1519 (patch) | |
tree | 20240cb70cda9e6b2fb6c7a3e52dd1e070a01c43 /plugins/artwork | |
parent | f9deb99d0787de87cfe36cdab3f0cfd1aea53535 (diff) |
fetching cover art from last.fm and albumart.org is now disabled by default;
added configuration of cover art fetching methods
Diffstat (limited to 'plugins/artwork')
-rw-r--r-- | plugins/artwork/artwork.c | 200 |
1 files changed, 104 insertions, 96 deletions
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index b11df44e..3e4f36f2 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -335,122 +335,126 @@ fetcher_thread (void *none) // try to load embedded from id3v2 if (is_local_file (param->fname)) { - trace ("trying to load artwork from id3v2 tag for %s\n", param->fname); - DB_id3v2_tag_t tag; - memset (&tag, 0, sizeof (tag)); - DB_FILE *fp = deadbeef->fopen (param->fname); - int got_id3v2_pic = 0; - if (fp) { - int res = deadbeef->junk_id3v2_read_full (NULL, &tag, fp); - if (!res) { - for (DB_id3v2_frame_t *f = tag.frames; f; f = f->next) { - if (!strcmp (f->id, "APIC")) { - - if (f->size < 20) { - trace ("artwork: id3v2 APIC frame is too small\n"); - continue; - } - uint8_t *data = f->data; - uint8_t *end = f->data + f->size; - int enc = *data; - data++; // enc - data = id3v2_skip_str (enc, data, end); // mime-type - if (!data) { - trace ("artwork: corrupted id3v2 APIC frame\n"); - continue; - } - data++; // picture type - data = id3v2_skip_str (enc, data, end); // description - if (!data) { - trace ("artwork: corrupted id3v2 APIC frame\n"); - continue; - } - int sz = f->size - (data - f->data); - - char tmp_path[1024]; - char cache_path[1024]; - make_cache_path (cache_path, sizeof (cache_path), param->album, param->artist); - trace ("will write id3v2 APIC into %s\n", cache_path); - snprintf (tmp_path, sizeof (tmp_path), "%s.part", cache_path); - FILE *out = fopen (tmp_path, "w+b"); - if (!out) { - trace ("artwork: failed to open %s for writing\n", tmp_path); - break; - } - if (fwrite (data, 1, sz, out) != sz) { - trace ("artwork: failed to write id3v2 picture into %s\n", tmp_path); + if (deadbeef->conf_get_int ("artwork.enable_embedded", 1)) { + trace ("trying to load artwork from id3v2 tag for %s\n", param->fname); + DB_id3v2_tag_t tag; + memset (&tag, 0, sizeof (tag)); + DB_FILE *fp = deadbeef->fopen (param->fname); + int got_id3v2_pic = 0; + if (fp) { + int res = deadbeef->junk_id3v2_read_full (NULL, &tag, fp); + if (!res) { + for (DB_id3v2_frame_t *f = tag.frames; f; f = f->next) { + if (!strcmp (f->id, "APIC")) { + + if (f->size < 20) { + trace ("artwork: id3v2 APIC frame is too small\n"); + continue; + } + uint8_t *data = f->data; + uint8_t *end = f->data + f->size; + int enc = *data; + data++; // enc + data = id3v2_skip_str (enc, data, end); // mime-type + if (!data) { + trace ("artwork: corrupted id3v2 APIC frame\n"); + continue; + } + data++; // picture type + data = id3v2_skip_str (enc, data, end); // description + if (!data) { + trace ("artwork: corrupted id3v2 APIC frame\n"); + continue; + } + int sz = f->size - (data - f->data); + + char tmp_path[1024]; + char cache_path[1024]; + make_cache_path (cache_path, sizeof (cache_path), param->album, param->artist); + trace ("will write id3v2 APIC into %s\n", cache_path); + snprintf (tmp_path, sizeof (tmp_path), "%s.part", cache_path); + FILE *out = fopen (tmp_path, "w+b"); + if (!out) { + trace ("artwork: failed to open %s for writing\n", tmp_path); + break; + } + if (fwrite (data, 1, sz, out) != sz) { + trace ("artwork: failed to write id3v2 picture into %s\n", tmp_path); + fclose (out); + unlink (tmp_path); + break; + } fclose (out); + int err = rename (tmp_path, cache_path); + if (err != 0) { + trace ("Failed not move %s to %s: %s\n", tmp_path, cache_path, strerror (err)); + unlink (tmp_path); + break; + } unlink (tmp_path); + got_id3v2_pic = 1; break; } - fclose (out); - int err = rename (tmp_path, cache_path); - if (err != 0) { - trace ("Failed not move %s to %s: %s\n", tmp_path, cache_path, strerror (err)); - unlink (tmp_path); - break; - } - unlink (tmp_path); - got_id3v2_pic = 1; - break; } } - } - if (got_id3v2_pic) { - if (param->callback) { - param->callback (param->fname, param->artist, param->album, param->user_data); + if (got_id3v2_pic) { + if (param->callback) { + param->callback (param->fname, param->artist, param->album, param->user_data); + } + queue_pop (); + continue; } - queue_pop (); - continue; + deadbeef->junk_id3v2_free (&tag); + deadbeef->fclose (fp); } - deadbeef->junk_id3v2_free (&tag); - deadbeef->fclose (fp); } - /* Searching in track directory */ - strncpy (path, param->fname, sizeof (path)); - char *slash = strrchr (path, '/'); - if (slash) { - *slash = 0; // assuming at least one slash exist - } - trace ("scanning directory: %s\n", path); - files_count = scandir (path, &files, filter_jpg, alphasort); - - if (files_count > 0) { - trace ("found cover for %s - %s in local folder\n", param->artist, param->album); - if (check_dir (path, 0755)) { - strcat (path, "/"); - strcat (path, files[0]->d_name); - char cache_path[1024]; - char tmp_path[1024]; - make_cache_path (cache_path, sizeof (cache_path), param->album, param->artist); - snprintf (tmp_path, sizeof (tmp_path), "%s.part", cache_path); - copy_file (path, tmp_path); - int err = rename (tmp_path, cache_path); - if (err != 0) { - trace ("Failed not move %s to %s: %s\n", tmp_path, cache_path, strerror (err)); - unlink (tmp_path); - } - int i; - for (i = 0; i < files_count; i++) { - free (files [i]); - } - if (param->callback) { - param->callback (param->fname, param->artist, param->album, param->user_data); + if (deadbeef->conf_get_int ("artwork.enable_localfolder", 1)) { + /* Searching in track directory */ + strncpy (path, param->fname, sizeof (path)); + char *slash = strrchr (path, '/'); + if (slash) { + *slash = 0; // assuming at least one slash exist + } + trace ("scanning directory: %s\n", path); + files_count = scandir (path, &files, filter_jpg, alphasort); + + if (files_count > 0) { + trace ("found cover for %s - %s in local folder\n", param->artist, param->album); + if (check_dir (path, 0755)) { + strcat (path, "/"); + strcat (path, files[0]->d_name); + char cache_path[1024]; + char tmp_path[1024]; + make_cache_path (cache_path, sizeof (cache_path), param->album, param->artist); + snprintf (tmp_path, sizeof (tmp_path), "%s.part", cache_path); + copy_file (path, tmp_path); + int err = rename (tmp_path, cache_path); + if (err != 0) { + trace ("Failed not move %s to %s: %s\n", tmp_path, cache_path, strerror (err)); + unlink (tmp_path); + } + int i; + for (i = 0; i < files_count; i++) { + free (files [i]); + } + if (param->callback) { + param->callback (param->fname, param->artist, param->album, param->user_data); + } + queue_pop (); + continue; } - queue_pop (); - continue; } } } make_cache_path (path, sizeof (path), param->album, param->artist); - if (fetch_from_lastfm (param->artist, param->album, path)) { + if (deadbeef->conf_get_int ("artwork.enable_lastfm", 0) && fetch_from_lastfm (param->artist, param->album, path)) { trace ("art found on last.fm for %s %s\n", param->album, param->artist); } - else if (fetch_from_albumart_org (param->artist, param->album, path)) { + else if (deadbeef->conf_get_int ("artwork.enable_albumartorg", 0) && fetch_from_albumart_org (param->artist, param->album, path)) { trace ("art found on albumart.org for %s %s\n", param->album, param->artist); } else { @@ -597,6 +601,10 @@ artwork_plugin_stop (void) static const char settings_dlg[] = "property \"Cache update period (hr)\" entry artwork.cache.period 48;\n" + "property \"Fetch from embedded tags\" checkbox artwork.enable_embedded 1;\n" + "property \"Fetch from local folder\" checkbox artwork.enable_localfolder 1;\n" + "property \"Fetch from last.fm\" checkbox artwork.enable_lastfm 0;\n" + "property \"Fetch from albumart.org\" checkbox artwork.enable_albumartorg 0;\n" ; // define plugin interface static DB_artwork_plugin_t plugin = { |