Skip to content

Instantly share code, notes, and snippets.

@larsenv
Last active January 26, 2024 07:43
Show Gist options
  • Save larsenv/432ffbd58978df07dd2e43089a12f8db to your computer and use it in GitHub Desktop.
Save larsenv/432ffbd58978df07dd2e43089a12f8db to your computer and use it in GitHub Desktop.
PBS Kids Video Downloader
import json
import requests
import subprocess
home = requests.get("https://content.services.pbskids.org/v2/kidspbsorg/home/").text
home = json.loads(home)
shows = {}
episodes = {}
print("==========PBS Kids Show Downloader by Larsenv==========\n")
def title(j, k, data):
i = 0
for f in data:
i += 1
number = str(j) + str(i).zfill(2)
number = number.zfill(3)
if k == 0:
shows[number] = f
elif k == 1:
episodes[number] = f
print(number + ". " + f["title"])
print("Show List:")
print("\nWeekly Promo:\n")
promo = home["collections"]["kids-promo"]
shows["000"] = promo
print("000. " + promo["title"])
print("\nSpotlight:\n")
spotlight = home["collections"]["kids-show-spotlight"]["content"]
shows["001"] = spotlight[0]
print("001. " + spotlight[0]["title"])
for i in range(1, 4):
print("\nTier {}:\n".format(i))
title(i, 0, home["collections"]["kids-programs-tier-{}".format(i)]["content"])
selection = input("\nPlease enter the number of the show you want to download: ")
url = shows[selection]["URI"].replace("pbs.org", "pbskids.org")
showhome = json.loads(requests.get(url).text)
print("\nEpisode and Clips List:")
print("\nClips:\n")
title("", 1, showhome["collections"]["clips"]["content"])
print("\nEpisodes:\n")
title(2, 1, showhome["collections"]["episodes"]["content"])
print("\nPromoted Content:\n")
title(3, 1, showhome["collections"]["promoted_content"]["content"])
selection2 = input("\nPlease enter the number of the episode or clip you want to download: ")
print("\nDownloading...")
vtt = None
for cc in episodes[selection2]["closedCaptions"]:
if cc["format"] == "WebVTT":
vtt = cc["URI"]
filename = (shows[selection]["title"] + " - " + episodes[selection2]["title"] + ".mp4").replace("/", " - ")
if vtt:
subprocess.call(["ffmpeg", "-i", episodes[selection2]["URI"], "-i", vtt, "-c:s", "mov_text", "-metadata:s:s:0", "language=eng", filename])
else:
subprocess.call(["ffmpeg", "-i", episodes[selection2]["URI"], filename])
print("\nDone!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment