mopidy / mopidy-local

Mopidy extension for playing music from your local music archive
https://mopidy.com/ext/local/
Apache License 2.0
62 stars 26 forks source link

Handle artist and album URIs in get_images() #13

Open tkem opened 9 years ago

tkem commented 9 years ago

Mopidy v1.0 Library.get_images() allows retrieving images for any URI, not just tracks. To facilitate this, a mapping of URIs to image paths should be kept, probably in an SQLite database. Since the local scanner only provides a track URI in the model passed to local.Library.add(), the implementation needs too first call add() and then lookup on the delegate library to extract any album or artist URIs assigned by Mopidy-Local-SQLite, for example.

tkem commented 9 years ago

The database should also store image width and height, which are now encoded in the image path.

tkem commented 9 years ago

Since a mapping of URIs to images will be available, this can also be used to (optionally) add image URIs to album models on lookup`.

tkem commented 9 years ago

Cleanup should be handled using database triggers. For example, if the last track is removed for an image, all other model mappings for that image must be removed, too, and the file deleted from disk.

tkem commented 9 years ago

Looks like (at least) three tables are needed for this:

image (path, width, height, ...)
track_model (track_uri, model_uri, ...)
model_image (model_uri, image_path)

Deleting a track will delete the model_image and all track_model records for that track. Deleting a track_model will delete all model_image records for that model, unless the model is referenced by another track. Deleting a model_image will delete the image unless referenced otherwise.

This definitely needs some unit tests...