Skip to content

Rewrite #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 44 additions & 37 deletions Contents/Code/__init__.py
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&param=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
4 changes: 0 additions & 4 deletions Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@
<string>*</string>
<key>PlexFrameworkVersion</key>
<string>2</string>
<key>PlexFrameworkFlags</key>
<array>
<string>UseRealRTMP</string>
</array>
</dict>
</plist>
10 changes: 1 addition & 9 deletions Contents/Services/ServiceInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@
<dict>
<key>PBS Kids</key>
<dict>
<key>TestURLs</key>
<array>
<string>http://release.theplatform.com/content.select\?pid=3CxvEh2lftsC1ypeLZXmKt6Vu50ksjYL%26UserName=Unknown%26affiliate=prekPlayer%26Embedded=True%26Portal=PBS%20KidsGo%20Default%20Feed%26Tracking=True</string>
</array>
<key>URLPatterns</key>
<array>
<string>http://release.theplatform.com/content.select\?pid=.+?Portal=PBS%20KidsGo.*</string>
<string>http://pbskids.org/.+/id=[0-9]+</string>
</array>
</dict>
</dict>
<key>PlexFrameworkFlags</key>
<array>
<string>UseRealRTMP</string>
</array>
</dict>
</plist>
62 changes: 35 additions & 27 deletions Contents/Services/URL/PBS Kids/ServiceCode.pys
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
NAMESPACES = {"a" : "http://www.w3.org/2001/SMIL20/Language", "tp" : "http://xml.theplatform.com/mps/metadata/content/custom"}

JSON_URL = 'http://pbskids.org/pbsk/video/api/getVideos/?id='
####################################################################################################
def MetadataObjectForURL(url):
smil = XML.ElementFromURL(url + '&format=SMIL')
video = smil.xpath('//a:ref', namespaces=NAMESPACES)[0]
title = video.get('title')
duration = int(video.get('dur').strip('ms'))

return VideoClipObject(
title = title,
thumb = R('icon-default.png'),
duration = duration
)
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']
if details['type'] =='Clip':
return VideoClipObject(
title = title,
summary=summary,
thumb = Resource.ContentsOfURLWithFallback(thumb)
)
else:
show_title = details['series_title']
return EpisodeObject(
title = title,
show = show_title,
summary = summary,
thumb = Resource.ContentsOfURLWithFallback(thumb)
)

####################################################################################################
def MediaObjectsForURL(url):
Expand All @@ -20,25 +31,22 @@ def MediaObjectsForURL(url):
MediaObject(
video_codec = VideoCodec.H264,
audio_codec = AudioCodec.AAC,
video_resolution = 360,
parts = [PartObject(key=Callback(PlayVideo, url = url))]
protocol = 'hls',
parts = [PartObject(key=Callback(PlayVideo, url=url))],
)
]

####################################################################################################
@indirect
def PlayVideo(url):

smil = XML.ElementFromURL(url + '&format=SMIL')
details = GetJSON(url)
try: redirect_url = details['videos']['ipad']['url']
except: redirect_url = details['videos']['iphone']['url']
m3u8_url = JSON.ObjectFromURL(redirect_url + '?format=json')['url']
return IndirectResponse(VideoClipObject, key=HTTPLiveStreamURL(url=m3u8_url))

rtmp_base = smil.xpath('//a:meta', namespaces=NAMESPACES)[0].get('base')
rtmp_url = smil.xpath('//a:ref', namespaces=NAMESPACES)[0].get('src')

clip = rtmp_url
if '.mp4' in clip:
clip = 'mp4:' + clip.split('.mp4')[0]
elif '.flv' in clip:
clip = clip.split('.flv')[0]

return IndirectResponse(VideoClipObject, key=RTMPVideoURL(url=rtmp_base, clip=clip))

####################################################################################################
def GetJSON(url):
video_id = url.split('id=')[1]
json = JSON.ObjectFromURL(JSON_URL + video_id)
return json['items'][0]