Tasker Pro: Create a Playlist of your YouTube Subscription Videos

Tasker Pro: Create a Playlist of your YouTube Subscription Videos

Smartphones have paved the way for us to keep up with our personal lives and stay connected with others in our world so strongly tied to the Internet. If there’s something you would like to do, there is almost always application out there that suits your needs.

You can keep track of your finances using Mint, keep up with the news using Feedly, or even browse our very own forums using the XDA Labs app (hint hint). But unfortunately, sometimes there just isn’t an app like that. Sometimes you have to make do with what you can get, even if it’s a tedious and a waste of your time.

That’s where automation comes in. Automation is supposed to be about simplifying everyday tasks to give you more precious time doing the things you love. At XDA, we’ve shown you how you can use Tasker to secure your device, improve productivity, or make driving safer, all a part of our series called ‘Tasker Week.’ But the fun doesn’t end there. If you’ve been itching for some seriously awesome Tasker tasks (and are tired of the boring stuff like telling you how to reboot your phone or shake your phone to wake the display), then our new Tasker Pro series is for you.

We will be posting a series of highly advanced Tasker profiles that will show you just how powerful Tasker can be if you are willing to think outside of the box. Although we’ve done most of the hard work for you and you’re certainly free to import my profiles and use them as is, I highly recommend you give learning how to use Tasker a shot if you want to be able to customize these tasks yourself. Over on our Tasker Tips & Tricks forums or on Reddit’s /r/Tasker subreddit, you can share and work with others on how to implement an idea you might have (as I have done many times).


Tasker Pro #1: YouTube Subscription PlayList

One of the biggest complaints about YouTube is the fact that there is simply no easy way to autoplay videos from your subscription feed. Seriously, try finding such a feature — it doesn’t exist. If you’re on a desktop computer, you could get an RSS feed (or use a Python script to generate that feed) but you’re still left with a major problem – you can’t autoplay these videos. Your only option then is to manually add each individual video into a playlist. Who wants to do that? Google certainly doesn’t want you to – they want you to visit their webpage so they can make some sweet ad money. Hell, even the official YouTube API doesn’t provide a way to directly pull your subscription videos! So they really don’t want you (or even developers) to have an easy way to see your latest subscription uploads. Thankfully, with the power of Tasker and two new plug-ins called AutoWeb and AutoTools we can do some clever manipulation of the data from the YouTube API to build a playlist of the latest uploaded videos from your subscriptions. Don’t believe me? Here it is in action:

Disclaimer: This method uses the YouTube API in a way that is highly inefficient (thanks to Google forcing us to use a roundabout way to retrieve videos). It is highly unlikely you’ll run close to the 50,000,000 daily YouTube quota, so don’t be worried about that. You can improve the speed of this task by sacrificing a bit of accuracy, which I’ll explain below. Still, doing this beats having to manually add everything to a playlist yourself!


Requirements

The following are OPTIONAL but if you decide to import my profile then you will need these installed to replicate my set-up. My tutorial will also assume that you install these:


Instructions

You will first need to prepare the YouTube API so you can actually use it to pull information about your subscriptions.

  1. To do so, import my YouTubeAPI.json file into AutoWeb by first downloading the file from Android File Host onto a known directory on your internal storage (downloads folder is fine).
  2. Under your web services, click the “+” icon to bring up a dialogue allowing you to import or create a new API.
  3. Click “IMPORT FROM FILE” and navigate to the directory where you stored the YouTubeAPI.json. Select that file.
  4. AutoWeb will then import the API settings I created for YouTube. (Note: do not import the API that is pre-installed by AutoWeb. It does not have the proper API Actions. I added many of these myself.)
  5. You will have to authenticate AutoWeb to access the YouTube API on your behalf. Log-in and accept.
  6. You can open the API Actions to see what’s available by clicking on the YouTube icon. If you imported it successfully, you will see the API Actions as shown in the bottom right screenshot below.

Now we get to the fun part. We’re going to now create a Tasker task that will call upon the YouTube API we just imported above. We will use some arrays and for loops to manipulate the data to get what we want, and finally we will open a URL directing the YouTube app to navigate to the playlist we just created. I will guide you through what each step does below. Here is the Task in its entirety:

2016 May 16 11-10-08

  1. Plugins –> Snackbar Tasker Plugin –> Bottom Sheet. The ‘main text’ is the title of the bottom bar (that you see at the beginning of the video) and you can name that anything. The only important thing is to specify the ‘items to appear in sheet’ and ‘commands to be sent’ options. Input the number of videos you want as an option in both. For example, I input ‘5,10,15,20’ in both ‘items’ and ‘commands’. Doing this will bring up a sheet asking you to pick between 5,10,15, and 20 videos and whatever you pick will tell the Task how many videos to add to the playlist.
  2. Plugins –> AutoTools –> AutoTools Dialog. Select dialog type ‘Progress’ and make it ‘Indeterminate.’ This is entirely optional and just a way to add some neat UX flare to the task. This is what brings up the spinner dialog telling me the task is processing.
  3. Plugins –> AutoWeb. Select the YouTube API. For API Action select Get subscriptions. Under Inputs, you can leave the default values there. Under Output, select Resource Id Channel Id. Back out. This will get the unique channel IDs of up to 50 of your YouTube subscriptions.
  4. Task –> For. Variable: %items. Items: 1:%resourceid_channelid(#). This will cycle through each of the YouTube channels under your subscription list.
  5. Plugins –> AutoWeb. Again select the YouTube API. For API Action this time select Get channel’s videos. Under Inputs, input %resourceid_channelid(%items) as the Channel ID. Under Outputs, select all of the outputs. What you are doing here is getting up to 50 of the most recent activities performed by that channel. This includes that YouTuber liking video, uploading a video, or adding a video to a playlist. But we don’t want that, we only want the videos they upload. Let’s continue. Note: if you want to speed up this task you can lower the max results input to a lower number. However, the fewer activities you pull the less accurate the overall task will be, as you may not be getting enough of their recent uploaded videos to form the playlist.
  6.  Task –> For. Variable %activity. Items: 1:%type(#). This will cycle through each of the activities we pulled from each of the channels above.
  7. Variables –> Array Push. Name: %videos. Position: 1. Value: %publishedat(%activity)%default_url(%activity). Select If at the bottom and set it to If %type(%activity) ~ upload. This one is a bit of a doozy to explain. But the gist of it is that IF the activity is determined to be an upload activity by that YouTuber, then we will add it to an array named ‘videos’. The value we push to the array is a concatenated string of the RFC3339 timestamp of when the video was published as well as the URL of the thumbnail image used for the video. Why the thumbnail image? As you’ll see below, it’s the quickest way to retrieve the video’s unique ID.
  8. Task –> End For.
  9. Task –> End For.
  10. Variables –> Array Process. Variable: %videos. Type: Sort Alpha, Reverse. We will order the array of videos from most recently uploaded to least recently uploaded.
  11. Variables –> Array Process. Variable: %videos. Type: Remove Duplicates. Sometimes, you will get duplicate results. I don’t know why this happens, but this will get rid of those.
  12. Variables –> Array Process. Variable: %videos. Type: Squash.
  13. Plugins –> AutoWeb. Select the YouTube API. For API Action select Create playlist. Under input input the name of the playlist you will create under ‘Title’ and put in any random text for ‘id.’ YouTube will create a playlist and will pick an ID for you, so there’s no need to specify an actual ID here (even though it requires you to add one, that’s why I just wrote in ‘blank’ there). Under Output, select Id.
  14. Task –> For. Variable: %recent. Items: 1:%bs_command. This will use the input from step 1 to determine how many videos we will add to our playlist.
  15. Variables –> Array Pop. Variable: %videos. Position: %recent. To var: %video. We are popping the nth video from our list of videos that are sorted by published date. n is a number from 1 to however many videos you wanted pulled.
  16. Variables –> Variable Section. Name: %video. From 48 length 11.  Store result in: %videoid. Remember that concatenated string earlier? Well, we’re now going to section off the parts of that string that we actually want, namely the video’s unique ID.
  17. Plugins –> AutoWeb. Select the YouTube API. For API Action select Add to playlist. Under Input, put youtube#video for ‘Kind’, %videoid for ‘Video Id, and %aid for ‘Playlist Id.’ This will add the video using the video ID to the playlist we created in step 13 above. The kind specifies what activity type it is – something YouTube uses to differentiate between videos, playlists, etc.
  18. Task –> End For.
  19. Plugins –> AutoTools –> AutoTools Dialog. Dialog Type: Progress. Scroll down and select ‘Close’ to end the spinner we created in step 2.
  20. Net –> Browse URL. For the URL, put this in: https://www.youtube.com/playlist?list=%playlistid. Assuming the YouTube app is your default app to handle YouTube links, this will open the YouTube app to the playlist we just created.

And voila! If you are able to follow along this, then congratulations you’re pretty much a master of Tasker! Confused on a step and just want to import the profile and get on with your life? I can’t blame you, this one took myself a lot of thinking to get it down right.

If you want to import this task, you can download it from Android File HostIn order to import the task, you need to first disable Beginner Mode in Tasker by going to the menu –> preferences. Under the UI tab, uncheck ‘Beginner Mode.’ Then back in the main Tasker menu, click on the ‘Tasks’ tab. Then long-press on the ‘Tasks’ tab and press ‘Import.’ Navigate to where you downloaded my .tsk.xml file and select it to import it. Once you import it, you’re free to play around with it as you see fit. This task is standalone and can be coupled with any context to trigger it. The easiest way is to just make a homescreen icon with a shortcut to this Task. Play around with it and see if you can make some improvements.

Next week for Tasker Pro I will show you how to track your driving mileage to help you with your tax returns!

Check out all Tasker Pro scripts!


What would you like to see me make with Tasker? Let us know below and we might feature your idea in a future article!