forked from dbl-a/PBSKids.bundle
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from mikedm139/master
Rewrite
- Loading branch information
Showing
4 changed files
with
80 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,80 @@ | ||
VIDEO_PREFIX = "/video/pbskids" | ||
PREFIX = "/video/pbskids" | ||
NAME = "PBS Kids" | ||
|
||
PBSKIDS_URL = "http://www.pbskids.org/video/" | ||
PBSKIDS_SHOWS = "http://pbskids.org/everything.html" | ||
PBS_JSON = "http://pbs.feeds.theplatform.com/ps/JSON/PortalService/2.2/getReleaseList?PID=6HSLquMebdOkNaEygDWyPOIbkPAnQ0_C&startIndex=1&endIndex=500&sortField=airdate&sortDescending=true&query=contentCustomBoolean|isClip|%s&field=airdate&field=author&field=bitrate&field=description&field=format&field=length&field=PID&field=thumbnailURL&field=title&field=URL&contentCustomField=isClip¶m=affiliate|prekPlayer&field=categories&field=expirationDate&query=categories|%s" | ||
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' | ||
#################################################################################################### | ||
def Start(): | ||
Plugin.AddPrefixHandler(VIDEO_PREFIX, MainMenu, NAME, ICON, ART) | ||
ObjectContainer.art = R(ART) | ||
ObjectContainer.title1 = NAME | ||
DirectoryObject.thumb=R(ICON) | ||
|
||
#################################################################################################### | ||
@handler(PREFIX, NAME, ICON, ART) | ||
def MainMenu(): | ||
oc = ObjectContainer() | ||
oc.add(DirectoryObject(key=Callback(ShowsList, categoryType="Show", title="Shows"), title="Shows")) | ||
oc.add(DirectoryObject(key=Callback(ShowsList, categoryType="Channel", title="Topics"), title="Topics")) | ||
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='false', title=title), title="Full Episodes", thumb=Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON))) | ||
oc.add(DirectoryObject(key=Callback(VideoPage, clip='true', title=title), title="Clips", thumb=Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON))) | ||
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", | ||
thumb=Resource.ContentsOfURLWithFallback(url=thumb))) | ||
|
||
if len(oc) == 0: | ||
return ObjectContainer(header="Empty", message="There aren't any items") | ||
else: | ||
return oc | ||
return oc | ||
|
||
#################################################################################################### | ||
def VideoPage(clip, title): | ||
@route(PREFIX + '/videos') | ||
def VideoPage(clip, title, offset=0): | ||
oc = ObjectContainer(title2=title) | ||
show_title = title.replace(' ', '%20').replace('&', '%26') ### FORMATTING FIX | ||
content = JSON.ObjectFromURL(PBS_JSON % (clip, show_title), cacheTime=CACHE_1DAY) | ||
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']: | ||
thumb = item['thumbnailURL'] | ||
link = item['URL'] | ||
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['length'] | ||
|
||
if clip == 'true': | ||
oc.add(VideoClipObject(url=link, title=video_title, summary=summary, duration=int(duration), thumb=Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON))) | ||
duration = item['videos']['iphone']['length'] | ||
try: thumb = item['images']['originalres_4x3']['url'] | ||
except: | ||
try: thumb = item['images']['originalres_16x9']['url'] | ||
except: thumb = ICON | ||
if clip == 'Clip': | ||
oc.add(VideoClipObject(url=url, title=video_title, summary=summary, duration=duration, | ||
thumb=Resource.ContentsOfURLWithFallback(thumb))) | ||
else: | ||
oc.add(EpisodeObject(url=link, title=video_title, show=title, summary=summary, duration=int(duration), thumb=Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON))) | ||
oc.add(EpisodeObject(url=url, title=video_title, show=title, summary=summary, duration=duration, | ||
thumb=Resource.ContentsOfURLWithFallback(thumb))) | ||
|
||
if int(content['matched']) > offset: | ||
oc.add(NextPageObject(key=Callback(VideoPage, clip=clip, title=title, offset=offset), title="More")) | ||
if len(oc) == 0: | ||
return ObjectContainer(header="Empty", message="There aren't any items") | ||
else: | ||
return oc | ||
|
||
#################################################################################################### | ||
def ShowsList(categoryType, title): | ||
oc = ObjectContainer(title2=title) | ||
content = JSON.ObjectFromURL(CATEGORY_LIST % categoryType) | ||
for item in content['items']: | ||
title = item['title'] | ||
thumb = item['thumbnailURL'] | ||
if thumb != "": | ||
if "Channel Sample" not in title: | ||
if categoryType == "Show": | ||
oc.add(DirectoryObject(key=Callback(ShowPage, title=title, thumb=thumb), title=title, thumb=Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON))) | ||
else: | ||
oc.add(DirectoryObject(key=Callback(VideoPage, title=title, clip='true'), title=title, thumb=Resource.ContentsOfURLWithFallback(url=thumb, fallback=ICON))) | ||
return oc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters