Alexey-Yakovenko/deadbeef — pull request #26 by Lithopsian (2014-08-27 13:28:48+00:00)
Title: Artwork plugin ideas for comment, not ready for release yet

Here is a grab-bag of ideas for the artwork plugin. This code includes:
1) Cache cleaner thread. Expired files should be removed within a few minutes, and scaled versions and directories should be cleaned up. At the moment it examines one artist directory every second and pauses for 60 seconds when they're all done.
2) All image scaling is now done in the same queued thread as image fetches, even when the unscaled image is already cached. This avoids freezes with large files or slow CPUs.
3) Changing the scale towards longer side preference now invalidates the scaled image cache immediately, but not the unscaled cache.
4) Don't do unnecessary lookups. After finding no cover art, an empty placeholder file is put in the cache. This is not re-checked until either the track file changes, the containing folder contents change, or after 10 minutes (longer?).
5) Mutex protect all callbacks so that none are missed when they are added to a query, and only make each callback once.
6) No limit on the number of callbacks, because dropping callbacks causes memory leaks.
7) Limit path components (eg. artist directory name) to NAME_MAX or they just fail. Remove limit on URL length for http requests.
8) Fixed various memory leaks, buffer and path overflows, null allocated pointers, etc. Probably more introduced :)
9) A preference "check-button" to invalidate the cache manually. Currently default off.
10) Dropped image type checking for embedded tags. It can never be 100% accurate, tools are sloppy about setting APE extensions and ID3 mime types, GTK can display just about any image type, imlib can scale 99.9% of them, and if the tag is there the user probably wants it. All WOS tags are GIFs anyway, plus some lastfm, and maybe others.
11) Doesn't create an artist directory unless there is a file to put in it. This is less useful now because there will almost always be a zero length placeholder file created if there isn't a real image file.
12) Disable get_album_art_sync(). It doesn't work and it isn't safe to call.
13) Playlist context menu item to refresh the cached artwork for the selected playitem(s). Note that this requires the plugin to reference playitems directly, something it hasn't done before, so it has to make its own choices about which tags to use.
14) Add "plain album" (ie. with any trailing parenthesised text stripped) retry for albumart.org as well as lastfm. Do both the plain album lookups after both regular lookups have been done.
15) Checks in several places that files are actually files, eg. in the local folder scan, so weird directories can be ignored instead of causing lookups to fail.
16) Reset local file mask to default if the user sets it to blank.
17) Make local folder scans work with local VFS URLs. Maybe should also look *inside* containers? Although vfs_zip scandir filtering doesn't currently work ...
18) Disable imlib caching because it can cause scaled images to be of an old version of the artwork. Also it is just a waste of memory since we only ever scale each file once.

There are no changes to the API, but I'd still like to add a way to query decoder plugins for non-junklib artwork without having to write everything in this plugin. My idea is an extra function in the decoder API, and it would probably need a change to the artwork API so that it has access to the playitem data to access the decoder property.

I also tried reading metadata from non-local streams which theoretically should work at least some of the time. Complete disaster. The vfs http seeking seems to cause all sorts of problems, particularly causing Flac to hang.

These changes have made some underlying bugs in the coverart code more visible: see issue #1179.