From 1e61c9edc81e76fe8da6b5c7445da5fcd2256de3 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 9 May 2015 03:16:03 +0200 Subject: [PATCH] (finally) fixed the video node sublevels filtered on tagname with episodes --- default.py | 9 +++ resources/lib/Entrypoint.py | 129 ++++++++++++++++++++++++++---------- resources/lib/VideoNodes.py | 21 ++---- 3 files changed, 108 insertions(+), 51 deletions(-) diff --git a/default.py b/default.py index 865e2ffa..611cc1c4 100644 --- a/default.py +++ b/default.py @@ -62,6 +62,15 @@ elif mode == "nextup": limit = int(params['limit']) entrypoint.getNextUpEpisodes(id, limit) +##### GET INPROGRESS EPISODES FOR TAGNAME ##### +elif mode == "inprogressepisodes": + limit = int(params['limit']) + entrypoint.getInProgressEpisodes(id, limit) + +##### GET RECENT EPISODES FOR TAGNAME ##### +elif mode == "recentepisodes": + limit = int(params['limit']) + entrypoint.getRecentEpisodes(id, limit) ##### GET EXTRAFANART FOR LISTITEM ##### elif "extrafanart" in sys.argv[0]: diff --git a/resources/lib/Entrypoint.py b/resources/lib/Entrypoint.py index 1b8c2217..c02533cd 100644 --- a/resources/lib/Entrypoint.py +++ b/resources/lib/Entrypoint.py @@ -285,48 +285,105 @@ def getNextUpEpisodes(tagname,limit): if json_query2.has_key('result') and json_query2['result'].has_key('episodes'): count = 0 for item in json_query2['result']['episodes']: - episode = "%.2d" % float(item['episode']) - season = "%.2d" % float(item['season']) - episodeno = "s%se%s" %(season,episode) - watched = False - if item['playcount'] >= 1: - watched = True - plot = item['plot'] - liz = xbmcgui.ListItem(item['title']) - liz.setInfo( type="Video", infoLabels={ "Title": item['title'] }) - liz.setProperty('IsPlayable', 'true') - liz.setInfo( type="Video", infoLabels={ "duration": str(item['runtime']/60) }) - liz.setInfo( type="Video", infoLabels={ "Episode": item['episode'] }) - liz.setInfo( type="Video", infoLabels={ "Season": item['season'] }) - liz.setInfo( type="Video", infoLabels={ "Premiered": item['firstaired'] }) - liz.setInfo( type="Video", infoLabels={ "Plot": plot }) - liz.setInfo( type="Video", infoLabels={ "TVshowTitle": item['showtitle'] }) - liz.setInfo( type="Video", infoLabels={ "Rating": str(round(float(item['rating']),1)) }) - liz.setInfo( type="Video", infoLabels={ "Playcount": item['playcount'] }) - if "director" in item: - liz.setInfo( type="Video", infoLabels={ "Director": " / ".join(item['director']) }) - if "writer" in item: - liz.setInfo( type="Video", infoLabels={ "Writer": " / ".join(item['writer']) }) - if "cast" in item: - liz.setInfo( type="Video", infoLabels={ "Cast": cast[0] }) - liz.setInfo( type="Video", infoLabels={ "CastAndRole": cast[1] }) - liz.setProperty("episodeno", episodeno) - liz.setProperty("resumetime", str(item['resume']['position'])) - liz.setProperty("totaltime", str(item['resume']['total'])) - liz.setArt(item['art']) - liz.setThumbnailImage(item['art'].get('thumb','')) - liz.setIconImage('DefaultTVShows.png') - liz.setProperty("dbid", str(item['episodeid'])) - liz.setProperty("fanart_image", item['art'].get('tvshow.fanart','')) - for key, value in item['streamdetails'].iteritems(): - for stream in value: - liz.addStreamInfo( key, stream ) + liz = createListItem(item) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz) count +=1 if count == limit: break xbmcplugin.endOfDirectory(handle=int(sys.argv[1])) +def getInProgressEpisodes(tagname,limit): + #if the addon is called with inprogressepisodes parameter, we return the inprogressepisodes list of the given tagname + xbmcplugin.setContent(int(sys.argv[1]), 'episodes') + # First we get a list of all the in-progress TV shows - filtered by tag + json_query_string = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "sort": { "order": "descending", "method": "lastplayed" }, "filter": {"and": [{"operator":"true", "field":"inprogress", "value":""}, {"operator": "contains", "field": "tag", "value": "%s"}]}, "properties": [ "title", "studio", "mpaa", "file", "art" ] }, "id": "libTvShows"}' %tagname) + + json_result = json.loads(json_query_string) + # If we found any, find all in progress episodes for each one. + if json_result.has_key('result') and json_result['result'].has_key('tvshows'): + for item in json_result['result']['tvshows']: + json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "tvshowid": %d, "sort": {"method":"episode"}, "filter": {"field": "inprogress", "operator": "true", "value":""}, "properties": [ "title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime", "writer", "dateadded", "lastplayed" ]}, "id": "1"}' %item['tvshowid']) + + if json_query2: + json_query2 = json.loads(json_query2) + if json_query2.has_key('result') and json_query2['result'].has_key('episodes'): + count = 0 + for item in json_query2['result']['episodes']: + liz = createListItem(item) + xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz) + count +=1 + if count == limit: + break + xbmcplugin.endOfDirectory(handle=int(sys.argv[1])) + +def getRecentEpisodes(tagname,limit): + #if the addon is called with recentepisodes parameter, we return the recentepisodes list of the given tagname + xbmcplugin.setContent(int(sys.argv[1]), 'episodes') + # First we get a list of all the TV shows - filtered by tag + json_query_string = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "sort": { "order": "descending", "method": "dateadded" }, "properties": [ "title","sorttitle" ], "filter": {"operator": "contains", "field": "tag", "value": "%s"} }, "id": "libTvShows"}' %tagname) + json_result = json.loads(json_query_string) + + # If we found any, put all tv show id's in a list + if json_result.has_key('result') and json_result['result'].has_key('tvshows'): + alltvshowIds = list() + for tvshow in json_result['result']['tvshows']: + alltvshowIds.append(tvshow["tvshowid"]) + alltvshowIds = set(alltvshowIds) + + #get all recently added episodes + json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "sort": {"order": "descending", "method": "dateadded"}, "filter": {"field": "playcount", "operator": "lessthan", "value":"1"}, "properties": [ "title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime", "writer", "dateadded", "lastplayed" ]}, "limits":{"end":%d}, "id": "1"}' %limit) + count = 0 + if json_query2: + json_query2 = json.loads(json_query2) + if json_query2.has_key('result') and json_query2['result'].has_key('episodes'): + for item in json_query2['result']['episodes']: + if item["tvshowid"] in alltvshowIds: + liz = createListItem(item) + xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz) + count += 1 + if count >= limit: + break + xbmcplugin.endOfDirectory(handle=int(sys.argv[1])) + +def createListItem(item): + episode = "%.2d" % float(item['episode']) + season = "%.2d" % float(item['season']) + episodeno = "s%se%s" %(season,episode) + watched = False + if item['playcount'] >= 1: + watched = True + plot = item['plot'] + liz = xbmcgui.ListItem(item['title']) + liz.setInfo( type="Video", infoLabels={ "Title": item['title'] }) + liz.setProperty('IsPlayable', 'true') + liz.setInfo( type="Video", infoLabels={ "duration": str(item['runtime']/60) }) + liz.setInfo( type="Video", infoLabels={ "Episode": item['episode'] }) + liz.setInfo( type="Video", infoLabels={ "Season": item['season'] }) + liz.setInfo( type="Video", infoLabels={ "Premiered": item['firstaired'] }) + liz.setInfo( type="Video", infoLabels={ "Plot": plot }) + liz.setInfo( type="Video", infoLabels={ "TVshowTitle": item['showtitle'] }) + liz.setInfo( type="Video", infoLabels={ "Rating": str(round(float(item['rating']),1)) }) + liz.setInfo( type="Video", infoLabels={ "Playcount": item['playcount'] }) + if "director" in item: + liz.setInfo( type="Video", infoLabels={ "Director": " / ".join(item['director']) }) + if "writer" in item: + liz.setInfo( type="Video", infoLabels={ "Writer": " / ".join(item['writer']) }) + if "cast" in item: + liz.setInfo( type="Video", infoLabels={ "Cast": cast[0] }) + liz.setInfo( type="Video", infoLabels={ "CastAndRole": cast[1] }) + liz.setProperty("episodeno", episodeno) + liz.setProperty("resumetime", str(item['resume']['position'])) + liz.setProperty("totaltime", str(item['resume']['total'])) + liz.setArt(item['art']) + liz.setThumbnailImage(item['art'].get('thumb','')) + liz.setIconImage('DefaultTVShows.png') + liz.setProperty("dbid", str(item['episodeid'])) + liz.setProperty("fanart_image", item['art'].get('tvshow.fanart','')) + for key, value in item['streamdetails'].iteritems(): + for stream in value: + liz.addStreamInfo( key, stream ) + + return liz ##### GET EXTRAFANART FOR LISTITEM ##### def getExtraFanArt(): diff --git a/resources/lib/VideoNodes.py b/resources/lib/VideoNodes.py index bf58af06..efa03dc4 100644 --- a/resources/lib/VideoNodes.py +++ b/resources/lib/VideoNodes.py @@ -149,19 +149,13 @@ class VideoNodes(): if type == "tvshows": #create tag node - recent episodes nodefile = os.path.join(libraryPath, tagname + "_recent_episodes.xml") - root = etree.Element("node", {"order":"3", "type":"filter"}) + root = etree.Element("node", {"order":"3", "type":"folder"}) label = language(30175) etree.SubElement(root, "label").text = label - etree.SubElement(root, "match").text = "all" etree.SubElement(root, "content").text = "episodes" - etree.SubElement(root, "path").text = nodefile_root etree.SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png" - etree.SubElement(root, "order", {"direction":"descending"}).text = "dateadded" - #set limit to 25 --> currently hardcoded --> TODO: add a setting for this ? - etree.SubElement(root, "limit").text = "25" - #exclude watched items --> currently hardcoded --> TODO: add a setting for this ? - Rule2 = etree.SubElement(root, "rule", {"field":"playcount","operator":"is"}) - etree.SubElement(Rule2, "value").text = "0" + path = "plugin://plugin.video.emby/?id=%s&mode=recentepisodes&limit=25" %tagname + etree.SubElement(root, "path").text = path WINDOW.setProperty("Emby.nodes.%s.recentepisodes.title" %str(windowPropId),label) path = "library://video/Emby - %s/%s_recent_episodes.xml"%(tagname,tagname) WINDOW.setProperty("Emby.nodes.%s.recentepisodes.path" %str(windowPropId),"ActivateWindow(Video,%s,return)"%path) @@ -173,16 +167,13 @@ class VideoNodes(): #create tag node - inprogress items nodefile = os.path.join(libraryPath, tagname + "_progress_episodes.xml") - root = etree.Element("node", {"order":"4", "type":"filter"}) + root = etree.Element("node", {"order":"4", "type":"folder"}) label = language(30178) etree.SubElement(root, "label").text = label - etree.SubElement(root, "match").text = "all" etree.SubElement(root, "content").text = "episodes" etree.SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png" - etree.SubElement(root, "path").text = nodefile_root - #set limit to 25 --> currently hardcoded --> TODO: add a setting for this ? - etree.SubElement(root, "limit").text = "25" - Rule2 = etree.SubElement(root, "rule", {"field":"inprogress","operator":"true"}) + path = "plugin://plugin.video.emby/?id=%s&mode=inprogressepisodes&limit=25" %tagname + etree.SubElement(root, "path").text = path WINDOW.setProperty("Emby.nodes.%s.inprogressepisodes.title" %str(windowPropId),label) path = "library://video/Emby - %s/%s_progress_episodes.xml"%(tagname,tagname) WINDOW.setProperty("Emby.nodes.%s.inprogressepisodes.path" %str(windowPropId),"ActivateWindow(Video,%s,return)"%path)