CUTR-at-USF / MUSER

App used in USF research on music therapy. Based on Shuttle Music Player (https://github.com/timusus/Shuttle).
Other
2 stars 1 forks source link

What is the remote album artwork source? #35

Closed barbeau closed 4 years ago

barbeau commented 4 years ago

Looking at the Shuttle Song class, there is the following method:

    public String getRemoteArtworkUrl() {
        try {
            return "https://artwork.shuttlemusicplayer.app/api/v1/artwork"
                    + "?artist=" + URLEncoder.encode(albumArtistName, Charset.forName("UTF-8").name())
                    + "&album=" + URLEncoder.encode(albumName, Charset.forName("UTF-8").name());
        } catch (UnsupportedEncodingException e) {
            return null;
        }
    }

This is used to fetch album artwork from an API maintained by Shuttle - but it seems to redirect to a Last FM API?

Here's a sample request: https://artwork.shuttlemusicplayer.app/api/v1/artwork?artist=The%201975&album=The%201975

...which redirects to: https://lastfm.freetls.fastly.net/i/u/1080s/2666bdc9b7264b799f8a882e471cd62e.png

In MultiFetcher, following attempts to fetch artwork from the local provider and storage, it then goes to this block:

        if (inputStream == null) {
            if (allowOfflineDownload
                    || (settingsManager.canDownloadArtworkAutomatically()
                    && ShuttleUtils.isOnline(applicationContext, true))) {

                //Last FM
                dataFetcher = new RemoteFetcher(artworkProvider);
                inputStream = loadData(dataFetcher, priority);
            }
        }

So it seems to fall back to Last FM as a data source for the album artwork as a last resort?

@BumbleFlash Do you know any more about this?

We'll need to determine if this is something we want to keep in MUSER.

BumbleFlash commented 4 years ago

To the best of my knowledge, I think Shuttle scans the internal storage for an artwork to be embedded with the song. If the artwork is not available in the storage, then the Shuttle's API is called. There's a switch block in the MultiFetcher class that handles the scanning and API calling part.

UserSelectedArtwork userSelectedArtwork = ((ShuttleApplication) applicationContext).userSelectedArtwork.get(artworkProvider.getArtworkKey());
    if (userSelectedArtwork != null) {
        switch (userSelectedArtwork.type) {
            case ArtworkProvider.Type.MEDIA_STORE:
                dataFetcher = new MediaStoreFetcher(applicationContext, artworkProvider);
                break;
            case ArtworkProvider.Type.FOLDER:
                dataFetcher = new FolderFetcher(artworkProvider, new File(userSelectedArtwork.path));
                break;
            case ArtworkProvider.Type.TAG:
                dataFetcher = new TagFetcher(artworkProvider);
                break;
            case ArtworkProvider.Type.REMOTE:
                dataFetcher = new RemoteFetcher(artworkProvider);
                break;
        }
        inputStream = loadData(dataFetcher, priority);

Also, the Shuttle is trying to abstract the last.fm API URL to hide the API key and that's why they have an additional API that redirects to the last.fm. Let's track this issue further in '#15'

barbeau commented 4 years ago

Sounds good, thanks! We can just use a locally-provided API key in our project so we don't need to maintain a server. And we can hide the API key in an unversioned file.