diff options
author | Tydus <Tydus@Tydus.org> | 2011-11-13 21:47:19 +0800 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-11-13 19:42:56 +0100 |
commit | 5c7e0dae227f8c2bf266a98031aa48de1490b12d (patch) | |
tree | 755d71917e1cab7c1894cc018050223dfa0260a3 /plugins/artwork | |
parent | d41860c39aac7dfc7858770fead513e2bcad842f (diff) |
Logic Correction in artwork fetching
Move APE and FLAC out of ID3 block
Diffstat (limited to 'plugins/artwork')
-rw-r--r-- | plugins/artwork/artwork.c | 140 |
1 files changed, 71 insertions, 69 deletions
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index 5850e8c1..7844faae 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -818,83 +818,85 @@ fetcher_thread (void *none) make_cache_path (cache_path, sizeof (cache_path), param->album, param->artist, -1); int got_pic = 0; - // try to load embedded from id3v2 if (deadbeef->is_local_file (param->fname)) { if (artwork_enable_embedded) { - 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); - current_file = fp; - 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 - // mime-type must always be ASCII - hence enc is 0 here - uint8_t *mime_end = id3v2_skip_str (0, data, end); - if (!mime_end) { - trace ("artwork: corrupted id3v2 APIC frame\n"); - continue; - } - if (strcasecmp (data, "image/jpeg") && strcasecmp (data, "image/png")) { - trace ("artwork: unsupported mime type: %s\n", data); - continue; - } - if (*mime_end != 3) { - trace ("artwork: picture type=%d, skipped: %s\n", *mime_end); - continue; - } - trace ("artwork: mime-type=%s, picture type: %d\n", data, *mime_end); - data = mime_end; - 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]; - 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); + // try to load embedded from id3v2 + { + 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); + current_file = fp; + 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 + // mime-type must always be ASCII - hence enc is 0 here + uint8_t *mime_end = id3v2_skip_str (0, data, end); + if (!mime_end) { + trace ("artwork: corrupted id3v2 APIC frame\n"); + continue; + } + if (strcasecmp (data, "image/jpeg") && strcasecmp (data, "image/png")) { + trace ("artwork: unsupported mime type: %s\n", data); + continue; + } + if (*mime_end != 3) { + trace ("artwork: picture type=%d, skipped: %s\n", *mime_end); + continue; + } + trace ("artwork: mime-type=%s, picture type: %d\n", data, *mime_end); + data = mime_end; + 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]; + 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_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_pic = 1; - break; } } - } - deadbeef->junk_id3v2_free (&tag); - current_file = NULL; - deadbeef->fclose (fp); + deadbeef->junk_id3v2_free (&tag); + current_file = NULL; + deadbeef->fclose (fp); + } } // try to load embedded from apev2 @@ -969,8 +971,8 @@ fetcher_thread (void *none) } #ifdef USE_METAFLAC + // try to load embedded from flac metadata { - // try to load embedded from flac metadata FLAC__StreamMetadata *meta = NULL; do { trace ("trying to load artwork flac metadata for %s\n", param->fname); |