Checking if Spotify track is in your current library

Use the Spotify API to check your library for the currently playing track

  1. joaomgcd
    This is how it'll look like in the end:


    In this tutorial you'll:
    • Get the currently playing track via AutoNotification
    • Get the correspondent track id with AutoWeb
    • Get if the track is your library with AutoWeb

    STEP 1 - GET TRACK NAME


    • Create a task in Tasker and call it Check If Track In Library
    • Add an AutoNotification Query action and select the Spotify app
    • Back in Tasker add a Flash action with the text %anticker()
    (i) At the time of writing %anticker() contained the track name and artist, so this is probably the info we have to search Spotify
    • Run the task to check that the track name and artist show up in the toast


    STEP 2 - GET TRACK ID


    • Add an AutoWeb Web Service action
    • Select the Spotify API
    • Select the Search Tracks action
    • Set the Market to US
    (i) For some reason this worked for me with US but not with my own market PT. If one doesn't work, try another one.
    • Set the Q field to %anticker()
    • Set the output to get to Items Id
    • Go back to Tasker and add a Flash action with the text %items_id()
    • Run the task and check that some track ids are shown on the screen


    STEP 3 - CHECK IF TRACKS ARE IN YOUR LIBRARY


    • Add another AutoWeb Web Service action
    • Select the Spotify API again
    • Select the Check user's saved tracks action
    • Set the market to US
    • Set the Ids field to %items_id()
    (i) %items_id() might contain more than 1 ID, but that's OK. This API action supports multiple IDs.
    • Set the output to get to Results
    • Go back to Tasker and add a Flash action with the text %result()
    • Run the task and check that a toast with 1 or a bunch of false or true shows up
    (i) You'll get a false or a true for each track ID. false means that the track was not in your library, true means that it was


    STEP 4 - DO STUFF DEPENDING IF IT IS OR NOT IN YOUR LIBRARY


    • Add an If - Else - End If segment where you check if %result() matches regex true
    • In the If part add a positive Flash action
    • In the Else part add a negative Flash action
    (i) This will check the full list of true and falses if any of them are true. So, even if one of the found tracks is in your library we'll assume that it is.


    STEP 5 - TEST


    If you now run the task (and the song is not in your library), it'll show the negative toast. If you add the song to your library it should show you the positive toast! :cool: