PBS Kids Changed their API
Updating the kids media player to handle the new API Sometimes when you are relying on an undocumented pseudo-public API that you’re probably not supposed to be using for your own devices, the people that run that API make changes without telling you. After three years of the kids media player working fine, at some point in the last couple of weeks the PBS Kids shows stopped working on it. Trying the endpoints, all of the producerplayer stuff was 404ing. The PBS Kids website and PBS Kids app still work, so there’s an API somewhere that contains most of the relevant information. Checking the network tab for anything that sounds API-ish, it was pretty obvious that they have a GraphQL endpoint now I threw the GraphQL endpoint into Bruno and was hopeful that they had introspection available to load the schema, and it turns out they left it on! After a bit of fiddling and assuming First, to get all of the show slugs: Then, to use that slug to get episodes (replace the show slug with the mediaManagerSlug): The only change that had to be made to accomodate the new API was changing of the get_url function, which is now just wrapping the above queries up into a json blob and fetching the baseline 16x9 video profile. While testing, the Mecha Builders episodes failed and it wasn’t obvious why right away when all of the others worked fine. Seems like Sesame Workshop has pulled the rights for this show from being on PBS and it is now exclusively on Netflix. It’s nice to see that we are pulling media that was created through donations intended for public broadcast and putting it behind subscription services.The Problem
Finding the new API
at https://graph.services.pbskids.orgNew Queries
slug was important when actually there is a similar-but-slightly-different mediaManagerSlug that was actually the important bit, I ended up with these two queries that I cared about.{
pbsKidsShows {
id
title
slug
mediaManagerSlug
}
}{
mediaManagerVideoSearch(
showSlug: "weather-hunters"
available: "public"
type: "full_length"
page: 1
pageSize: 50
) {
id
title
season_number
episode_number
videos {
profile
url
}
}
}
Updating the Media Player
def get_url(stub):
query = """query($stub: String) {
mediaManagerVideoSearch(showSlug: $stub, available: "public", type: "full_length", page: 1, pageSize: 50) {
title videos { profile url }
}
}"""
response = requests.post("https://graph.services.pbskids.org/", json={"query": query, "variables": {"stub": stub}}).json()
episodes = response["data"]["mediaManagerVideoSearch"] or []
episodeurls = []
for episode in episodes:
for video in episode["videos"]:
if video["profile"] == "mp4-16x9-baseline":
episodeurls.append(video["url"])
break
if len(episodeurls) == 0:
raise RuntimeError(f"No episodes for '{stub}'")
randomepisodenumber = random.randint(0,len(episodeurls)-1)
episodeurl=episodeurls[randomepisodenumber]
return episodeurlWith One Difference