Skip to content

Commit

Permalink
Use hosted resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
sander1 committed Apr 27, 2013
1 parent ddc6247 commit f3957ae
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
42 changes: 25 additions & 17 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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)))
Expand All @@ -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
Binary file removed Contents/Resources/art-default.jpg
Binary file not shown.
Binary file removed Contents/Resources/icon-default.png
Binary file not shown.
Binary file removed Contents/Services/Resources/icon-default.png
Binary file not shown.
29 changes: 18 additions & 11 deletions Contents/Services/URL/PBS Kids/ServiceCode.pys
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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']
Expand All @@ -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]

0 comments on commit f3957ae

Please sign in to comment.