Guide: Automating Youtube Subscriptions to your Plex Queue

Guide: Automating Youtube Subscriptions to your Plex Queue

After reading Corey DeGrandchamp's great guide on using Zapier to automatically get your new YouTube subscriptions sent straight to your Plex queue I spent a month loving it; until my Zapier free trial came to an end. [However I suggest using that guide and using Zapier for a month to see whether you really need to do any of the below]
Looking at the options for Zapier and my large amount of YouTube subscriptions I started hunting around for better (free) options but couldn't find anything; then a friend suggested just doing it myself in python. 

Note 1: This pertains largely to windows.

Note 2: I installed this on my actual Plex server but will work on any machine that is always on

STEP 1: Download and Install Python

Go here and download Python 3.4:

Install Python, taking note of the install directory (Mine is C:/Python34 )

STEP 2: Configure Windows environmental variables

Right click on my computer and click properties.
Click "advanced system settings", then under the advanced tab click "environmental variables", in the second box edit the "path" variables, and on the very end add the string " ;C:/Python34 " 

Or wherever you installed python

STEP 3: Download and Install feedparser


And download the .zip version of feedparser, and unzip it.

Save the following file as:

Now open Command Prompt (cmd) and change the directory to the save location of and execute as below

>cd C:\Users\Sean\Downloads

Next we need to change the directory to the location of the extracted feedparser, in particular the file

>cd C:\Users\Sean\Downloads\feedparser-5.1.3\feedparser-5.1.3
>python install

STEP 4: Downloading this custom script and your details

Download the above file and save to your /Python34 folder.

Right click on the file and click "Edit with IDLE" (Or notepad, it doesn't matter).

Change USER_NAME to your YouTube username

change EMAIL_ADDRESS to your email address

change PLEX_QUEUE_ADDRESS to your Plex queue email you can find by going to your web client and click the help (question mark) next to queue, under "add videos by email"

change PASSWORD to your email password.

I've left the smtp server as the Gmail server, however if you want to use a different email I'll update this page with more servers, or you can just google for "smtp server outlook" or whatever service you're using, change the 587 to the TLS port the service uses.

Save the file once you've made your changes.

STEP 5: Create bin text file

In your python directory (C:/Python34), right click>new>text document.
Name the file "youtubeurls"

STEP 6: Setup automation

In the start menu search "Task Scheduler" and in the right hand side select "create basic task".

Name/Describe the task whatever you want, select next, set the task to start daily, next.

The action you want to perform is "start a program". Browse to python.exe in your python installation directory. Then in the "add arguments field" add "C:\Python34\"

Make sure for the add arguments to add the quotations. 

Select next and check the box that says "open properties dialog for this task when I click finish".

Under general change option to "run whether user is logged on or not".

Under the Trigger tab, select your daily trigger and 'edit'. 
Under advanced settings select "repeat task every:" and choose whatever interval you would like for a duration of "indefinitely".

EXTRA STEP: Run first time to build bin // Check that script is working

The first time you run the code it will take a couple of minutes to send all (25 of) the emails (the YouTube atom feed is fixed at 25 items, so 25 emails).

Open command prompt and change directory and run the script as follows

>cd C:\Python34

The script is finished when the input option returns. If any errors are returned let me know in the comments and I'll try and help you out!

If you check your email outbox, plex queue, and the bin text file "youtubeurls.txt" the 25 most recent subscription videos should be there. 

Once the first task scheduler task has run, it should run every 15 minutes or whatever you chose and send the URLs of any videos that weren't there previously.


Music Review Tests