diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 2aeed49..3f88200 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -1,41 +1,40 @@ -PREFIX = "/video/pbskids" -NAME = "PBS Kids" +PREFIX = "/video/pbskids" +NAME = "PBS Kids" PBSKIDS_URL = "http://www.pbskids.org/video/" PBSKIDS_SHOWS = "http://pbskids.org/go/video/js/org.pbskids.shows.js" #"http://pbskids.org/everything.html" VIDEO_LIST = "http://pbskids.org/pbsk/video/api/getVideos/?startindex=%s&endindex=%s&program=%s&category=&group=&selectedID=&status=available&type=%s&return=airdate,+expirationdate,+rating" CATEGORY_LIST = "http://pbs.feeds.theplatform.com/ps/JSON/PortalService/2.2/getCategoryList?PID=6HSLquMebdOkNaEygDWyPOIbkPAnQ0_C&query=CustomText|CategoryType|%s&query=HasReleases&field=title&field=thumbnailURL" -ART = "art-default.jpg" -ICON = "icon-default.png" +OFFSET = 20 +VIDEO_URL = '%sid=%s' -OFFSET = 20 - -VIDEO_URL = '%sid=%s' #################################################################################################### def Start(): - ObjectContainer.art = R(ART) + ObjectContainer.title1 = NAME - DirectoryObject.thumb=R(ICON) #################################################################################################### -@handler(PREFIX, NAME, ICON, ART) +@handler(PREFIX, NAME) def MainMenu(): + oc = ObjectContainer() content = JSON.ObjectFromURL(PBSKIDS_SHOWS) + for item in content: title = item['title'] thumb = item['thumbnail2URL'] summary = String.StripTags(item['description']) oc.add(DirectoryObject(key=Callback(ShowPage, title=title, thumb=thumb), title=title, summary=summary, thumb=Resource.ContentsOfURLWithFallback(url=thumb))) + return oc #################################################################################################### @route(PREFIX + '/show') def ShowPage(title, thumb): + oc = ObjectContainer(title2=title) - oc.add(DirectoryObject(key=Callback(VideoPage, clip='Episode', title=title), title="Full Episodes", thumb=Resource.ContentsOfURLWithFallback(url=thumb))) oc.add(DirectoryObject(key=Callback(VideoPage, clip='Clip', title=title), title="Clips", @@ -46,25 +45,33 @@ def ShowPage(title, thumb): #################################################################################################### @route(PREFIX + '/videos') def VideoPage(clip, title, offset=0): + oc = ObjectContainer(title2=title) + if offset == 0: start = 0 else: start = offset offset = offset + OFFSET + content = JSON.ObjectFromURL(VIDEO_LIST % (start, offset, String.Quote(title, usePlus=True), clip), cacheTime=CACHE_1DAY) + for item in content['items']: series_url = item['series_url'] + if not series_url.endswith('/'): series_url = series_url + '/' + url = VIDEO_URL % (series_url, item['id']) video_title = item['title'] summary = item['description'] duration = item['videos']['iphone']['length'] - try: thumb = item['images']['originalres_4x3']['url'] + + try: thumb = item['images']['originalres_4x3']['url'] except: - try: thumb = item['images']['originalres_16x9']['url'] - except: thumb = ICON + try: thumb = item['images']['originalres_16x9']['url'] + except: thumb = '' + if clip == 'Clip': oc.add(VideoClipObject(url=url, title=video_title, summary=summary, duration=duration, thumb=Resource.ContentsOfURLWithFallback(thumb))) @@ -74,7 +81,8 @@ def VideoPage(clip, title, offset=0): if int(content['matched']) > offset: oc.add(NextPageObject(key=Callback(VideoPage, clip=clip, title=title, offset=offset), title="More")) - if len(oc) == 0: + + if len(oc) < 1: return ObjectContainer(header="Empty", message="There aren't any items") - else: - return oc + + return oc diff --git a/Contents/Resources/art-default.jpg b/Contents/Resources/art-default.jpg deleted file mode 100644 index c410b88..0000000 Binary files a/Contents/Resources/art-default.jpg and /dev/null differ diff --git a/Contents/Resources/icon-default.png b/Contents/Resources/icon-default.png deleted file mode 100644 index bae4d36..0000000 Binary files a/Contents/Resources/icon-default.png and /dev/null differ diff --git a/Contents/Services/Resources/icon-default.png b/Contents/Services/Resources/icon-default.png deleted file mode 100644 index bae4d36..0000000 Binary files a/Contents/Services/Resources/icon-default.png and /dev/null differ diff --git a/Contents/Services/URL/PBS Kids/ServiceCode.pys b/Contents/Services/URL/PBS Kids/ServiceCode.pys index 10b66d3..b86ac24 100644 --- a/Contents/Services/URL/PBS Kids/ServiceCode.pys +++ b/Contents/Services/URL/PBS Kids/ServiceCode.pys @@ -1,18 +1,23 @@ JSON_URL = 'http://pbskids.org/pbsk/video/api/getVideos/?id=' + #################################################################################################### def MetadataObjectForURL(url): + details = GetJSON(url) + title = details['title'] - try: thumb = item['images']['originalres_4x3']['url'] - except: - try: thumb = item['images']['originalres_16x9']['url'] - except: thumb = R('icon-deafult.jpg') summary = details['description'] duration = details['videos']['ipad']['length'] + + try: thumb = item['images']['originalres_4x3']['url'] + except: + try: thumb = item['images']['originalres_16x9']['url'] + except: thumb = '' + if details['type'] =='Clip': return VideoClipObject( title = title, - summary=summary, + summary = summary, thumb = Resource.ContentsOfURLWithFallback(thumb) ) else: @@ -28,17 +33,18 @@ def MetadataObjectForURL(url): def MediaObjectsForURL(url): return [ - MediaObject( - video_codec = VideoCodec.H264, - audio_codec = AudioCodec.AAC, - protocol = 'hls', - parts = [PartObject(key=Callback(PlayVideo, url=url))], - ) + MediaObject( + video_codec = VideoCodec.H264, + audio_codec = AudioCodec.AAC, + protocol = 'hls', + parts = [PartObject(key=Callback(PlayVideo, url=url))], + ) ] #################################################################################################### @indirect def PlayVideo(url): + details = GetJSON(url) try: redirect_url = details['videos']['ipad']['url'] except: redirect_url = details['videos']['iphone']['url'] @@ -47,6 +53,7 @@ def PlayVideo(url): #################################################################################################### def GetJSON(url): + video_id = url.split('id=')[1] json = JSON.ObjectFromURL(JSON_URL + video_id) return json['items'][0] \ No newline at end of file