A dad posted on a forum I frequent in Denmark asking for some help. His child loves Mister Rogers, but he was hoping for a way to download a bunch of episodes that didn't involve streaming them from the website to stick on an iPad. I love simple Python projects like this and so I jumped on the chance. Let me walk you through what I did.
If you just want to download the script you can skip all this and find the full script here.
Step 1: Download Youtube-DL
My first thought was of youtube-dl for the actual downloading and thankfully it worked great. This is one of those insanely useful utilities that I cannot recommend highly enough. You can find the download instructions here: http://ytdl-org.github.io/youtube-dl/download.html
Step 2: Install Python 3
You shouldn't need a super modern version of python. I wrote this with Python 3.7.3, so anything that number or newer should be good. We are using f strings because I love them, so you will need 3.6 or newer.
I'm checking the version here but only to confirm that you are running Python 3, on the assumption that if you have 3 you have a relatively recent version of 3.
version = platform.python_version_tuple() if version != "3": print("You are not running Python 3. Please check your version.") sys.exit(1)
Step 3: Decide where you are going to download the files
I have my download location in the script here:
path = "/mnt/usb/television/mister-rogers-neighborhood/"
However if you just want them to download into the Downloads folder, uncomment the line above this one by removing the # and delete the line I show above. So you'll want
path = str(Path.home() / "Downloads") to not have a # in front of it.
Step 4: Run the script
Not sure how to run a Python script? We got you taken care of. Click here for Windows. Here are some Mac tips.
You can find the script on Gitlab here: https://gitlab.com/-/snippets/2100082
Download the script and run it locally. The script checks if it is the first or third Monday of the month and only runs the download if it is. This is to basically keep us from endlessly spamming the servers hosting this great free content.
The first Monday of every month will feature programs from the early years 1968-1975. The third Monday of every month will feature programs from the “Theme Weeks” library 1979-2001.
NOTE: If you just want to download 5 episodes right now, delete these lines:
today = date.today().isocalendar() if today == 1 and (today == 1 or 3): logging.info("There is a new download available.") else: logging.info("There are no new downloads today.") sys.exit(0)
Step 5: Set the script to run every day
This script is designed to be run every day and only go out to the servers if there is a new file to get.
Here is how to run a python script every day on Windows.
For Linux and Mac open up your terminal, run
crontab -e and enter in the frequency you want to run the script at. Here is a useful site to generate the whole entry.
Here is the metadata formatting I followed for the Infuse iOS app, my favorite app. You may want a different format for the filename depending on your application.
If people actually use this script I'll rewrite it to use celery beat to handle the scheduling of the downloads, but for my own use case I'm comfortable writing cron jobs. However if you run into issues running this, either add a comment on the GitLab link or shoot me an email: mat at matduggan.com.