Building your own watch-it-later video podcast with Dropbox

Update January 2017: This approach will stop working soon, since Dropbox will be turning off public folders in March (and acts like that’s a good thing, because they have “built even better ways for you to share securely and work together with your team” … yeah, right).

iPhonePodcast
Playing a video from the podcast we’ll create.

My feed reader and social media streams swamp me with videos every day, and some of them actually seem to be interesting. The thing is: During the day, I don’t have time to watch them. And the one time I can actually watch them – on my way home on the subway – I have no (or very slow) Internet access. Which basically means no Youtube, no Vimeo – simply no video streaming in general. So I thought it would be great if I could just save these videos to watch them later, and have them transferred automagically to my phone for offline viewing. Turns out this is actually not so hard if we use Dropbox and a fairly simple PHP script. Yes, I know this could also be done in [insert your favorite programming language here]. PHP is preinstalled on Mac OS, though, and I know PHP well enough to quickly implement this, so that’s what I did.

I’ll describe the process on Mac OS, but it should be easily transferrable to any other operating system. As the title suggests, you’ll need a Dropbox account to make this work. What we’ll do is use your Dropbox’s Public folder to publish your own podcast, generated from your saved videos, and then subscribe to this podcast on the phone.

1. Put the PHP script in place.

Download this GitHub repository, unzip it, and copy the folder Watchlater-master to your Dropbox’s Public folder. If you’d rather have it in a different subfolder, you can change the path in the configuration at the top of the feed.php file (just make sure it’s somewhere inside the Public folder):

$path = "Watchlater-master"; // change this if you place the script in a different subfolder.

2. Configure the script

The one thing you do need to change in the script is your Dropbox ID:

$dropboxID = "123";

The easiest way to find out your Dropbox ID is by going to your Public folder, right-clicking on any file (such as the feed.php file we have just pasted there), and select Copy Public Link. Paste that into a text editor, and it should look something like this:

https://dl.dropboxusercontent.com/u/123/path/to/my/file.txt

The number after /u/ (123 in this example) is your Dropbox ID.

The other two things you can (but don’t have to) tweak are setting your local time zone:

date_default_timezone_set('America/New_York');

and the number of videos you want to keep in the folder:

$keepVids = 10;

The script does some housekeeping for you, so if you have more than, say, 10 (which is the default) videos in your folder, the script will automatically remove the oldest X videos until only the 10 newest videos are left. This keeps your Dropbox from overflowing. Note that the script has no way of knowing which videos you have already watched, so it may also remove videos you have not watched yet.

3. Add some videos

Before we run the script, we’ll need some videos to feed it. Download some videos into the Watchlater-master folder (or wherever you put the feed.php script). Since most services like YouTube don’t really offer an easy way to download their stuff, I’m using youtube-dl for that (which also works great for a wide range of other streaming sites). On a Mac, you can install it via Homebrew (if you don’t have Homebrew, go and install it right now – it’s awesome!). While we’re at it, we will also install ffmpeg and use that later to automatically convert videos to web-friendly formats. In a terminal window, type

$ brew install youtube-dl ffmpeg

Once Homebrew is done installing youtube-dl, change into our feed directory and download some videos:

$ cd ~/Dropbox/Public/Watchlater-master
$ youtube-dl https://www.youtube.com/watch?v=dQw4w9WgXcQ

3. Run the script

To run the script, type

$ php feed.php

into the Terminal. If everything goes right, you should see some messages, and a new file called later.xml in the folder.

4. Subscribe to your podcast

This later.xml is the actual podcast that we want to subscribe to, and because it is in your Dropbox’s Public folder, it actually has a stable URL and is accessible online even when your computer is not running (if your Dropbox is completely synced, that is; if not, wait until it’s done and the spinning arrow on the Dropbox icon in your menu bar has disappeared). Right-click on the later.xml, and select Copy Public Link again. Since we need this URL on the phone to subscribe to the podcast, I simply emailed it to myself (there should really be an iCloud-based clipboard, I know).

On your phone, open your Podcast client and add that URL as a new podcast. I use Pocket Casts 4, but it should work with any other app the same way:

casts

Voilà – we now get videos saved to watch later delivered to our phone! Make sure you pick a podcast client that automatically downloads new episodes.

5. Automatically update your podcast

The one piece that is missing is some magic that automatically updates the later.xml on a regular basis to check whether new videos have been added to the folder. We’ll use a Cron job for that. In a terminal, type:

env EDITOR=nano crontab -e

This will open the nano editor inside your terminal window, showing an empty file (unless you have already set up any other Cron jobs on your system). In nano, paste this line:

59 * * * * cd ~/Dropbox/Public/Watchlater-master/; for f in *.mkv;do ffmpeg -i "$f" -c:v copy -c:a aac -b:a 256k -strict -2 "${f%mkv}mp4"; rm "$f"; done; php feed.php

on the first line. This sets up a Cron job to automatically convert any .mkv files in the folder to .mp4 format, remove the .mkv files, and then run the feed.php script once every hour to update the podcast feed. Press CTRL-X to close nano, confirm to save the file by pressing ‘Y’, then enter.

That’s it. Now every time you place a new video in that folder, your podcast will be updated hourly, and the videos will end up in your podcast app. I’ve been using this script for a few months now and find it really useful – it’s a bit tedious to set up, but once you have done that, gone are the times of awkwardly staring at ads on the subway because there’s nothing else to do.

6. (Optional) Make an alias for youtube-dl

If you don’t want to change into the Watchlater directory every time before downloading the video, you also make an alias for youtube-dl that will always download videos to the folder. While we’re at it, we will also make the video titles a bit nicer and tell youtube-dl to fetch MP4 videos straight away (so the conversion from MKV we have added in the previous step is actually not really required any more.) To do that, we’ll just add an alias to our bash profile like so: Change into your home directory:

cd ~

Then open your bash profile in nano:

sudo nano .bash_profile

And add the following line to the end of the file:

alias ytdl='youtube-dl -f mp4 -o "~/Dropbox/Public/Watchlater-master/%(title)s.%(ext)s"'

Then hot control + O to save your change (hit enter to confirm) and control + X to exit nano. That’s all. Now you can use ytdl https://www.youtube.com/watch?v=dQw4w9WgXcQ from any terminal session and the video will always go into your Watchlater folder in MP4 format.

Update October 22, 2015: Added instructions for automatic conversion of .mkv videos to .mp4 format.

Update November 30, 2016: Added instructions for alias.

5 thoughts on “Building your own watch-it-later video podcast with Dropbox

    1. That seems to work great for YouTube channels, but the whole point of my solution is that you can build a stream of any video you come across.

Leave a Reply

Your email address will not be published. Required fields are marked *