How to get *all* the playlists that contain a given track?

hmijail's Avatar

hmijail

23 Oct, 2021 01:20 PM

I'm trying to write a plugin to show in the SongContextView all the playlists that contain the selected track. For that, I need to retrieve those playlists for the selected track; how can I do that? The interface com.tamtraug.tunes.Track provides getPlaylist(), but only returns a single playlist.

I see that the contextual menu for tracks has an option for "Show in Playlist...", which opens a submenu with all the playlists. This is exactly the information I need. Is this available from the API?

Or, should I somehow loop through all the existing playlists and check whether each of them contains the song? If so, how can I get the list of existing playlists to start the process?

  1. 1 Posted by hmijail on 24 Oct, 2021 03:51 AM

    hmijail's Avatar

    In case it matters, my version numbers are:
    macOS 11.6
    Music.app 1.1.6.37
    beaTunes 5.2.24

  2. Support Staff 2 Posted by hendrik on 25 Oct, 2021 08:04 AM

    hendrik's Avatar

    Hey there,

    please check out the attached screenshot. You can find out which playlists a track belongs to by using the track's context menu.

    If that does not fit your use case, here's how you get the playlists (in Java):

    import com.tagtraum.audiokern.AudioSong;
    import com.tagtraum.audiokern.PlayList;
    import com.tagtraum.beatunes.BeaTunes;
    import com.tagtraum.beatunes.library.Song;
    import java.util.Collection;
    
    [...]
    
    public Collection<PlayList> create(final BeaTunes beaTunes, final AudioSong audioSong) {
        final Song song = audioSong.getImplementation(Song.class);
        // may or may not be necessary
        beaTunes.getMediaLibrary().fetchCollections(song);
        return song.getPlayLists();
    }
    

    The issue here is that getPlayLists() is not exposed in AudioSong. Perhaps it should.

    Anyhow, hope this helps you,

    -hendrik

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac