From cc6d7ab6d3b50265d5b8bb0ffe095548753a89ce Mon Sep 17 00:00:00 2001 From: Matthew Depew Date: Tue, 22 May 2018 09:57:48 -0500 Subject: [PATCH 1/5] fixes for new api format --- Contents/Code/__init__.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 89517b0..6db1d22 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -23,40 +23,39 @@ def MainMenu(): json_obj = JSON.ObjectFromURL(PBSKIDS_SHOWS) for item in json_obj['items']: - title = item['title'] summary = String.StripTags(item['description']) + # API now uses slug for program id + if 'cove_slug' in item: + slug = item['cove_slug'] - 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: + # The API appears to no longer serve thumbnail URLs + # Could eventually try to find another source for thumbnails thumb = '' - oc.add(DirectoryObject( - key = Callback(ShowPage, title=title, thumb=thumb), - title = title, - summary = summary, - thumb = Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON) - )) + 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 +64,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']: From b51ad81b1164390a1e8099d0df091013754fe027 Mon Sep 17 00:00:00 2001 From: Matthew Depew Date: Tue, 22 May 2018 12:45:57 -0500 Subject: [PATCH 2/5] Added hack for some thumbs --- Contents/Code/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 6db1d22..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 #################################################################################################### @@ -30,8 +30,10 @@ def MainMenu(): slug = item['cove_slug'] # The API appears to no longer serve thumbnail URLs - # Could eventually try to find another source for thumbnails - thumb = '' + # 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), From b02a58a9cfffc60eaa1944c86ae5f879e7545058 Mon Sep 17 00:00:00 2001 From: Matthew Depew Date: Wed, 23 May 2018 08:43:48 -0500 Subject: [PATCH 3/5] workaround for crashing https streams --- .../Services/URL/PBS Kids/ServiceCode.pys | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Contents/Services/URL/PBS Kids/ServiceCode.pys b/Contents/Services/URL/PBS Kids/ServiceCode.pys index 69c7070..4423b19 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,22 @@ 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-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)) #################################################################################################### From d7ff851a1dccfe4ac5e2a5709e8e829d09fdffe5 Mon Sep 17 00:00:00 2001 From: Matthew Depew Date: Sat, 26 May 2018 09:21:00 -0500 Subject: [PATCH 4/5] prefer 1080p --- Contents/Services/URL/PBS Kids/ServiceCode.pys | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Contents/Services/URL/PBS Kids/ServiceCode.pys b/Contents/Services/URL/PBS Kids/ServiceCode.pys index 4423b19..dde2749 100644 --- a/Contents/Services/URL/PBS Kids/ServiceCode.pys +++ b/Contents/Services/URL/PBS Kids/ServiceCode.pys @@ -54,7 +54,8 @@ def PlayVideo(url): details = GetJSON(url) vid_profiles = {vid['profile']:vid['url'] for vid in details['videos']} - preferred_profile_list = ['hls-2500k-16x9', + preferred_profile_list = ['hls-1080p-16x9', + 'hls-2500k-16x9', 'ipad-16x9', 'iphone-16x9', 'hls-2500k-4x3', From 005d0766a157f95956fddfc97c12b37b22a39997 Mon Sep 17 00:00:00 2001 From: Matthew Depew Date: Sat, 26 May 2018 10:16:44 -0500 Subject: [PATCH 5/5] added new profile formats --- Contents/Services/URL/PBS Kids/ServiceCode.pys | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Contents/Services/URL/PBS Kids/ServiceCode.pys b/Contents/Services/URL/PBS Kids/ServiceCode.pys index dde2749..259faa3 100644 --- a/Contents/Services/URL/PBS Kids/ServiceCode.pys +++ b/Contents/Services/URL/PBS Kids/ServiceCode.pys @@ -54,7 +54,9 @@ def PlayVideo(url): details = GetJSON(url) vid_profiles = {vid['profile']:vid['url'] for vid in details['videos']} - preferred_profile_list = ['hls-1080p-16x9', + preferred_profile_list = ['hls-16x9-1080p', + 'hls-16x9-720p', + 'hls-1080p-16x9', 'hls-2500k-16x9', 'ipad-16x9', 'iphone-16x9',