Multiple AutoApps [Help] AutoSpotify/AutoWeb Add current track to specific playlist

Discussion in 'AutoApps' started by Kenny_vl, May 9, 2019.

  1. Kenny_vl

    Kenny_vl New Member

    Joined:
    Sep 29, 2017
    Messages:
    6
    Likes Received:
    0
    First of all, I have also posted this question on Tasker's subreddit but I'm hoping to reach a larger audience by also asking here.
    Long story short, I am trying to add the current track to specific playlist in Spotify and I've ran into the Spotify "Get playlist tracks"" API's limit of 100. I am now trying to figure out how to get around this but my brain has gotten blocked. Been thinking on it for too long and I just know I'm missing something fairly simple here.

    Ok, so first things first. I've currently got my task set up like this:

    Code (Text):
        Spotify Favorite (14)
            A1: AutoSpotify Player State [ Configuration:Warning: To receive media events from the Spotify app you need to set Device Broadcast Status to ON in the Spotify app’s settings. Timeout (Seconds):20 ]
            A2: Variable Set [ Name:%currentTrack To:%astrackuri Recurse Variables:Off Do Maths:Off Append:Off ]
            A3: Variable Search Replace [ Variable:%currentTrack Search:track Ignore Case:On Multi-Line:Off One Match Only:Off Store Matches In Array: Replace Matches:On Replace With: ]
            A4: Variable Search Replace [ Variable:%currentTrack Search:: Ignore Case:On Multi-Line:Off One Match Only:Off Store Matches In Array: Replace Matches:On Replace With: ]
            A5: Variable Search Replace [ Variable:%currentTrack Search:spotify Ignore Case:On Multi-Line:Off One Match Only:Off Store Matches In Array: Replace Matches:On Replace With: ]
            A6: AutoWeb Web Service [ Configuration:API: Spotify
        API Action: Get playlist tracks
        Market: US
        User Id: kenny.vl
        Playlist Id: 6ySC5wO49Af5zIRFkjBMVe Timeout (Seconds):120 ]
            A7: Write File [ File:Download/spoturi.txt Text:%trackIDs Append:Off Add Newline:On ]
            A8: For [ Variable:%tracksInList Items:%trackIDs ]
            A9: If [ %tracksInList ~ %currentTrack ]
            A10: Variable Set [ Name:%alreadyInList To:true Recurse Variables:Off Do Maths:Off Append:Off ]
            A11: End If
            A12: End For
            A13: If [ %alreadyInList neq true ]
            A14: AutoWeb Web Service [ Configuration:API: Spotify
        API Action: Add Tracks to a Playlist
        Market: US
        User Id: kenny.vl
        Playlist Id: 6ySC5wO49Af5zIRFkjBMVe
        Position: 0 Timeout (Seconds):120 ]
            A15: Flash [ Text:%astrackname was added to your playlist Long:On ]
            A16: Else
            A17: Flash [ Text:%astrackname is already in your playlist Long:On ]
            A18: End If
            A19: Variable Clear [ Name:%alreadyInList Pattern Matching:Off Local Variables Only:Off ]
       
    In order to get around the API limit, I need to find a way to dynamically update the offset used in A6 and store all values to an array (I had considered using a text file but I assumed this will affect performance).
    So, based on comments from my Reddit topic, I've found that I could probably use ceil(%total/100) as input for the iterations. Thing is, I'm not sure on how to implement this. My first idea was to create an array, set a variable that calculates ceil(%total/100), create a for-loop to run the result number of times of that variable and push the object (track_id()) to the array.
    Code (Text):
          A7: Array Set [ Variable Array:%trackIDs Values:%track_id() Splitter:, ]
            A8: Variable Set [ Name:%iterationsNumber To:ceil(%total/100) Recurse Variables:Off Do Maths:On Append:Off ]
            A9: For [ Variable:%iterations Items:%iterationsNumber ]
            A10: Array Push [ Variable Array:%trackIDs Position:1 Value:%track_id() Fill Spaces:Off ]
            A11: End For
     
    When I test this, writing my array to a text file, all I got was %trackIDs (=name of array variable) rather then the expected result (which would be a list of 100 track ID's).
    On top of that, I also don't see how I can change the offset to increase by 100 in each iteration.
    I'm stuck and hoping to bank on common knowledge to implement my requirement.
     
  2. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,479
    Likes Received:
    806
    Hi, just to confirm, have you found a way around it?
     
  3. Kenny_vl

    Kenny_vl New Member

    Joined:
    Sep 29, 2017
    Messages:
    6
    Likes Received:
    0
    I'm working on it and I believe I'm pretty close.
    Although I believe my task may be optimised, I'm assuming to have it finished today or tomorrow.
     

Share This Page