Skip to content

Commit

Permalink
Merge pull request #10 from mddepew/master
Browse files Browse the repository at this point in the history
Fixes for new PBS API
  • Loading branch information
sander1 authored May 30, 2018
2 parents 934ed55 + 005d076 commit bd172d3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 26 deletions.
43 changes: 22 additions & 21 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
PBSKIDS_SHOWS = 'http://pbskids.org/pbsk/video/api/getShows/?return=images'
VIDEO_LIST = 'http://pbskids.org/pbsk/video/api/getVideos/?startindex=%d&endindex=%d&program=%s&status=available&type=%s&return=airdate,expirationdate,rating'
VIDEO_URL = 'http://pbskids.org/pbsk/video/api/getVideos/?guid=%s'

SHOW_ICON_URL = 'http://www-tc.pbskids.org/shell/images/content/show-bubbles/square/%s.png'
OFFSET = 20

####################################################################################################
Expand All @@ -23,40 +23,41 @@ def MainMenu():
json_obj = JSON.ObjectFromURL(PBSKIDS_SHOWS)

for item in json_obj['items']:

title = item['title']
summary = String.StripTags(item['description'])

if 'program-mezzanine-16x9' in item['images']:
thumb = item['images']['program-mezzanine-16x9']['url']
elif 'program-kids-square' in item['images']:
thumb = item['images']['program-kids-square']['url']
else:
thumb = ''

oc.add(DirectoryObject(
key = Callback(ShowPage, title=title, thumb=thumb),
title = title,
summary = summary,
thumb = Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON)
))
# API now uses slug for program id
if 'cove_slug' in item:
slug = item['cove_slug']

# The API appears to no longer serve thumbnail URLs
# This hack gets some thumbnails, in some cases the
# slug matches the image filename on the pbs site.
# Fails for some shows.
thumb = SHOW_ICON_URL % slug

oc.add(DirectoryObject(
key = Callback(ShowPage, title=title, thumb=thumb, slug=slug),
title = title,
summary = summary,
thumb = Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON)
))

return oc

####################################################################################################
@route(PREFIX + '/show')
def ShowPage(title, thumb):
def ShowPage(title, thumb, slug=''):

oc = ObjectContainer(title2=title)

oc.add(DirectoryObject(
key = Callback(VideoPage, type='Episode', title=title),
key = Callback(VideoPage, type='Episode', title=title, slug=slug),
title = 'Full Episodes',
thumb = Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON)
))

oc.add(DirectoryObject(
key = Callback(VideoPage, type='Clip', title=title),
key = Callback(VideoPage, type='Clip', title=title, slug=slug),
title = 'Clips',
thumb = Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON)
))
Expand All @@ -65,12 +66,12 @@ def ShowPage(title, thumb):

####################################################################################################
@route(PREFIX + '/videos', start=int)
def VideoPage(type, title, start=0):
def VideoPage(type, title, slug, start=0):

oc = ObjectContainer(title2=title)
end = start+OFFSET

json_obj = JSON.ObjectFromURL(VIDEO_LIST % (start, end, String.Quote(title, usePlus=True), type), cacheTime=CACHE_1DAY)
json_obj = JSON.ObjectFromURL(VIDEO_LIST % (start, end, String.Quote(slug, usePlus=True), type), cacheTime=CACHE_1DAY)

for item in json_obj['items']:

Expand Down
28 changes: 23 additions & 5 deletions Contents/Services/URL/PBS Kids/ServiceCode.pys
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def MetadataObjectForURL(url):
title = details['title']
summary = details['description']

try: duration = details['videos']['iphone']['length']
try: duration = details['duration']
except: duration = None

thumb = ''
Expand All @@ -26,7 +26,10 @@ def MetadataObjectForURL(url):
thumb = Resource.ContentsOfURLWithFallback(thumb)
)
else:
show_title = details['series_title']
if details['show'] is not None:
show_title = details['show']['attributes']['title']
else:
show_title = details['parent_tree']['attributes']['title']
return EpisodeObject(
title = title,
show = show_title,
Expand All @@ -36,7 +39,6 @@ def MetadataObjectForURL(url):

####################################################################################################
def MediaObjectsForURL(url):

return [
MediaObject(
video_codec = VideoCodec.H264,
Expand All @@ -51,9 +53,25 @@ def MediaObjectsForURL(url):
def PlayVideo(url):

details = GetJSON(url)
try: redirect_url = details['videos']['ipad']['url']
except: redirect_url = details['videos']['iphone']['url']
vid_profiles = {vid['profile']:vid['url'] for vid in details['videos']}
preferred_profile_list = ['hls-16x9-1080p',
'hls-16x9-720p',
'hls-1080p-16x9',
'hls-2500k-16x9',
'ipad-16x9',
'iphone-16x9',
'hls-2500k-4x3',
'ipad-4x3',
'iphone-4x3']
for profile_name in preferred_profile_list:
if profile_name in vid_profiles:
selected_profile=profile_name
break
try: redirect_url = vid_profiles[selected_profile]
except: redirect_url = details['videos'][0]['url']
m3u8_url = JSON.ObjectFromURL(redirect_url + '?format=json')['url']
# Force http for m3u8, https crashing
m3u8_url = m3u8_url.replace('https:','http:')
return IndirectResponse(VideoClipObject, key=HTTPLiveStreamURL(url=m3u8_url))

####################################################################################################
Expand Down

0 comments on commit bd172d3

Please sign in to comment.