diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 89517b0..56ef07d 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -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 #################################################################################################### @@ -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) )) @@ -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']: diff --git a/Contents/Services/URL/PBS Kids/ServiceCode.pys b/Contents/Services/URL/PBS Kids/ServiceCode.pys index 69c7070..259faa3 100644 --- a/Contents/Services/URL/PBS Kids/ServiceCode.pys +++ b/Contents/Services/URL/PBS Kids/ServiceCode.pys @@ -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 = '' @@ -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, @@ -36,7 +39,6 @@ def MetadataObjectForURL(url): #################################################################################################### def MediaObjectsForURL(url): - return [ MediaObject( video_codec = VideoCodec.H264, @@ -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)) ####################################################################################################