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
At the time of writing %anticker() contained the track name and artist, so this is probably the info we have to search Spotify
- 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()
- Run the task to check that the track name and artist show up in the toast
STEP 2 - GET TRACK ID
For some reason this worked for me with US but not with my own market PT. If one doesn't work, try another one.
- Add an AutoWeb Web Service action
- Select the Spotify API
- Select the Search Tracks action
- Set the Market to US
- 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
%items_id() might contain more than 1 ID, but that's OK. This API action supports multiple IDs.
- 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()
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
- 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
STEP 4 - DO STUFF DEPENDING IF IT IS OR NOT IN YOUR LIBRARY
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.
- 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
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!
Checking if Spotify track is in your current library
Use the Spotify API to check your library for the currently playing track