diff --git a/Twitch.tv.bundle/Contents/Code/__init__.py b/Twitch.tv.bundle/Contents/Code/__init__.py index 6fd08ca..662be8f 100644 --- a/Twitch.tv.bundle/Contents/Code/__init__.py +++ b/Twitch.tv.bundle/Contents/Code/__init__.py @@ -1,6 +1,8 @@ # Twitch.tv Plugin # v0.1 by Marshall Thornton # Code inspired by Justin.tv plugin by Trevor Cortez and John Roberts +# v0.2 by Nicolas Aravena +# Adaptation of v0.1 for new Plex Media Server. #################################################################################################### @@ -22,27 +24,28 @@ #################################################################################################### def Start(): - Plugin.AddPrefixHandler("/video/twitchtv", VideoMainMenu, NAME, ICON, ART) - Plugin.AddViewGroup("InfoList", viewMode="InfoList", mediaType="items") - Plugin.AddViewGroup("List", viewMode="List", mediaType="items") - MediaContainer.art = R(ART) - MediaContainer.title1 = NAME - MediaContainer.viewGroup = "InfoList" - DirectoryItem.thumb = R(ICON) - PrefsItem.thumb = R(ICON) - InputDirectoryItem.thumb = R(ICON) + Plugin.AddViewGroup("List", viewMode = "List", mediaType = "items") + ObjectContainer.art = R(ART) + ObjectContainer.title1 = NAME + ObjectContainer.view_group = "List" + DirectoryItem.thumb = R(ICON) + + HTTP.Headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:15.0) Gecko/20100101 Firefox/15.0.1' -def VideoMainMenu(): - dir = MediaContainer(noCache=True) - dir.Append(Function(DirectoryItem(FeaturedStreamsMenu, title="Featured Streams", summary="Browse featured streams"))) - dir.Append(Function(DirectoryItem(GamesMenu, title="Games", summary="Browse live streams by game"))) - dir.Append(Function(InputDirectoryItem(SearchResults, title="Search", prompt="Search For A Stream", summary="Search for a stream"))) - return dir +@handler "/video/twitch" +def MainMenu(): + oc = ObjectContainer() + oc.add(DirectoryObject(key=Callback(FeaturedStreamsMenu), title="Featured Streams")) + oc.add(DirectoryObject(key=Callback(GamesMenu), title="Games", summary="Browse live streams by game")) + oc.add(InputDirectoryObject(key=Callback(SearchResults), title="Search", prompt="Search For A Stream", summary="Search for a stream")) + return oc + +@route('/video/twitch/featured', page=int, cacheTime=int, allow_sync=True) def FeaturedStreamsMenu(sender, page=None): - dir = MediaContainer(viewGroup="List", title2="Featured Streams") + oc = ObjectContainer(view_group="List", title2="Featured Streams") url = "%s?limit=%s" % (TWITCH_FEATURED_STREAMS, PAGE_LIMIT) featured = JSON.ObjectFromURL(url, cacheTime=CACHE_INTERVAL) @@ -51,29 +54,29 @@ def FeaturedStreamsMenu(sender, page=None): subtitle = "%s\n%s Viewers" % (stream['stream']['game'], stream['stream']['viewers']) summary = strip_tags(stream['text']) streamUrl = "%s&channel=%s" % (TWITCH_LIVE_PLAYER, stream['stream']['channel']['name']) - dir.Append(WebVideoItem(streamUrl, title=stream['stream']['channel']['display_name'], subtitle=subtitle, summary=summary, thumb=stream['stream']['preview'])) - - return dir + oc.add(VideoClipObject(url=streamUrl, title=stream['stream']['channel']['display_name'], thumb=stream['stream']['preview'], subtitle=subtitle)) + return oc +@route('/video/twitch/games', page=int, cacheTime=int, allow_sync=True) def GamesMenu(sender, page=0): - dir = MediaContainer(viewGroup="List", title2="Top Games") + oc = ObjectContainer(view_group="List", title2="Top Games") url = "%s?limit=%s&offset=%s" % (TWITCH_TOP_GAMES, PAGE_LIMIT, page*PAGE_LIMIT) games = JSON.ObjectFromURL(url, cacheTime=CACHE_INTERVAL) for game in games['top']: gameSummary = "%s Channels\n%s Viewers" % (game['channels'], game['viewers']) - dir.Append(Function(DirectoryItem(ChannelMenu, title=game['game']['name'], thumb=game['game']['logo']['large'], summary=gameSummary), game=game['game']['name'])) + oc.add(DirectoryObject(key=Callback(ChannelMenu, game=game['game']['name'])), title=game['game']['name'], summary=gameSummary, thumb=game['game']['logo']['large']) if(len(games['top']) == 100): - dir.Append(Function(DirectoryItem(GamesMenu, title="More Games"), page=(page+1))) + oc.add(DirectoryObject(key=Callback(GamesMenu, title = "More Games", page = (page+1)))) - return dir + return oc def ChannelMenu(sender, game=None): - dir = MediaContainer(title2=sender.itemTitle) + oc = ObjectContainer(title2=sender.itemTitle) url = "%s?game=%s&limit=%s" % (TWITCH_LIST_STREAMS, urllib.quote_plus(game), PAGE_LIMIT) streams = JSON.ObjectFromURL(url, cacheTime=CACHE_INTERVAL) @@ -81,21 +84,21 @@ def ChannelMenu(sender, game=None): for stream in streams['streams']: subtitle = " %s Viewers" % stream['viewers'] streamURL = "%s&channel=%s" % (TWITCH_LIVE_PLAYER, stream['channel']['name']) - dir.Append(WebVideoItem(streamURL, title=stream['channel']['display_name'], summary=stream['channel']['status'], subtitle=subtitle, thumb=stream['channel']['banner'], duration=0)) + oc.add(VideoClipObject(url=streamUrl, title=stream['channel']['display_name'], summary=stream['channel']['status'],thumb=stream['channel']['logo'], subtitle=subtitle, duration=0))) - return dir + return oc def SearchResults(sender, query=None): - dir = MediaContainer() + oc = ObjectContainer() results = JSON.ObjectFromURL("%s?query=%s&limit=%s" % (TWITCH_SEARCH_STREAMS, urllib.quote_plus(query), PAGE_LIMIT), cacheTime=CACHE_INTERVAL) for stream in results['streams']: subtitle = "%s\n%s Viewers" % (stream['game'], stream['viewers']) streamURL = "%s&channel=%s" % (TWITCH_LIVE_PLAYER, stream['channel']['name']) - dir.Append(WebVideoItem(streamURL, title=stream['channel']['display_name'], summary=stream['channel']['status'], subtitle=subtitle, thumb=stream['channel']['banner'])) + oc.add(VideoClipObject(url=streamUrl, title=stream['channel']['display_name'], summary=stream['channel']['status'],thumb=stream['channel']['logo'], subtitle=subtitle, duration=0))) if len(dir) > 0: - return dir + return oc else: - return MessageContainer("Not found", "No streams were found that match your query.") + return ObjectContainer(header="Not found", message="No streams were found that match your query.")