mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-01-24 00:46:11 +00:00
added profiling to default.py to measure speed improvements
added caching to nextup widget generation
This commit is contained in:
parent
6264090741
commit
9c639d47ca
3 changed files with 155 additions and 114 deletions
188
default.py
188
default.py
|
@ -1,101 +1,127 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import xbmcaddon, xbmc
|
||||||
import os
|
import os, sys
|
||||||
import sys
|
import urlparse
|
||||||
from urlparse import parse_qs
|
|
||||||
|
|
||||||
import xbmcaddon
|
|
||||||
import xbmc
|
|
||||||
|
|
||||||
addon_ = xbmcaddon.Addon(id='plugin.video.emby')
|
addon_ = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
addon_path = addon_.getAddonInfo('path').decode('utf-8')
|
addon_path = addon_.getAddonInfo('path').decode('utf-8')
|
||||||
base_resource_path = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8')
|
base_resource_path = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8')
|
||||||
sys.path.append(base_resource_path)
|
sys.path.append(base_resource_path)
|
||||||
|
|
||||||
import Entrypoint as entrypoint
|
import Entrypoint as entrypoint
|
||||||
|
|
||||||
# Parse parameters
|
enableProfiling = False
|
||||||
base_url = sys.argv[0]
|
|
||||||
addon_handle = int(sys.argv[1])
|
|
||||||
params = parse_qs(sys.argv[2][1:])
|
|
||||||
xbmc.log("Parameter string: %s" % sys.argv[2])
|
|
||||||
|
|
||||||
try:
|
class Main:
|
||||||
mode = params['mode'][0]
|
|
||||||
id = params.get('id', None)
|
|
||||||
if id:
|
|
||||||
id = id[0]
|
|
||||||
except:
|
|
||||||
params = {}
|
|
||||||
mode = ""
|
|
||||||
|
|
||||||
##### PLAY ITEM VIA plugin://plugin.video.emby/ #####
|
# MAIN ENTRY POINT
|
||||||
if "play" in mode or "playnow" in mode:
|
def __init__(self):
|
||||||
entrypoint.doPlayback(id)
|
|
||||||
|
|
||||||
#### DO RESET AUTH #####
|
# Parse parameters
|
||||||
elif "resetauth" in mode:
|
base_url = sys.argv[0]
|
||||||
entrypoint.resetAuth()
|
addon_handle = int(sys.argv[1])
|
||||||
|
params = urlparse.parse_qs(sys.argv[2][1:])
|
||||||
##### DO DATABASE RESET #####
|
xbmc.log("Parameter string: %s" % sys.argv[2])
|
||||||
elif "reset" in mode:
|
|
||||||
import Utils as utils
|
|
||||||
utils.reset()
|
|
||||||
|
|
||||||
##### ADD/REMOVE USER FROM SESSION #####
|
try:
|
||||||
elif "adduser" in mode:
|
mode = params['mode'][0]
|
||||||
entrypoint.addUser()
|
id = params.get('id', None)
|
||||||
|
if id:
|
||||||
|
id = id[0]
|
||||||
|
except:
|
||||||
|
params = {}
|
||||||
|
mode = ""
|
||||||
|
|
||||||
##### SYNC THEME MEDIA #####
|
##### PLAY ITEM VIA plugin://plugin.video.emby/ #####
|
||||||
elif "thememedia" in mode:
|
if "play" in mode or "playnow" in mode:
|
||||||
entrypoint.getThemeMedia()
|
entrypoint.doPlayback(id)
|
||||||
|
|
||||||
##### LAUNCH EMBY USER PREFS #####
|
#### DO RESET AUTH #####
|
||||||
elif "userprefs" in mode:
|
elif "resetauth" in mode:
|
||||||
entrypoint.userPreferences()
|
entrypoint.resetAuth()
|
||||||
|
|
||||||
|
##### DO DATABASE RESET #####
|
||||||
|
elif "reset" in mode:
|
||||||
|
import Utils as utils
|
||||||
|
utils.reset()
|
||||||
|
|
||||||
##### OPEN ADDON SETTINGS #####
|
##### ADD/REMOVE USER FROM SESSION #####
|
||||||
elif "settings" in mode:
|
elif "adduser" in mode:
|
||||||
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.emby)')
|
entrypoint.addUser()
|
||||||
|
|
||||||
##### MANUALLY SYNC LIBRARY #####
|
##### SYNC THEME MEDIA #####
|
||||||
elif "manualsync" in mode:
|
elif "thememedia" in mode:
|
||||||
from LibrarySync import LibrarySync
|
entrypoint.getThemeMedia()
|
||||||
LibrarySync().FullLibrarySync(True)
|
|
||||||
|
|
||||||
##### CACHE ARTWORK #####
|
##### LAUNCH EMBY USER PREFS #####
|
||||||
elif "texturecache" in mode:
|
elif "userprefs" in mode:
|
||||||
from TextureCache import TextureCache
|
entrypoint.userPreferences()
|
||||||
TextureCache().FullTextureCacheSync()
|
|
||||||
|
|
||||||
##### BROWSE EMBY CHANNELS FOLDER #####
|
##### OPEN ADDON SETTINGS #####
|
||||||
elif "channelsfolder" in mode:
|
elif "settings" in mode:
|
||||||
folderid = params['folderid'][0]
|
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.emby)')
|
||||||
entrypoint.BrowseChannels(id,folderid)
|
|
||||||
|
##### MANUALLY SYNC LIBRARY #####
|
||||||
|
elif "manualsync" in mode:
|
||||||
|
from LibrarySync import LibrarySync
|
||||||
|
LibrarySync().FullLibrarySync(True)
|
||||||
|
|
||||||
|
##### CACHE ARTWORK #####
|
||||||
|
elif "texturecache" in mode:
|
||||||
|
from TextureCache import TextureCache
|
||||||
|
TextureCache().FullTextureCacheSync()
|
||||||
|
|
||||||
|
##### BROWSE EMBY CHANNELS FOLDER #####
|
||||||
|
elif "channelsfolder" in mode:
|
||||||
|
folderid = params['folderid'][0]
|
||||||
|
entrypoint.BrowseChannels(id,folderid)
|
||||||
|
|
||||||
|
##### BROWSE EMBY CHANNELS ROOT #####
|
||||||
|
elif "channels" in mode:
|
||||||
|
entrypoint.BrowseChannels(id)
|
||||||
|
|
||||||
|
##### GET NEXTUP EPISODES FOR TAGNAME #####
|
||||||
|
elif "nextup" in mode:
|
||||||
|
limit = params['limit'][0]
|
||||||
|
entrypoint.getNextUpEpisodes(id, limit)
|
||||||
|
|
||||||
|
##### GET INPROGRESS EPISODES FOR TAGNAME #####
|
||||||
|
elif "inprogressepisodes" in mode:
|
||||||
|
limit = params['limit'][0]
|
||||||
|
entrypoint.getInProgressEpisodes(id, limit)
|
||||||
|
|
||||||
|
##### GET RECENT EPISODES FOR TAGNAME #####
|
||||||
|
elif "recentepisodes" in mode:
|
||||||
|
limit = params['limit'][0]
|
||||||
|
entrypoint.getRecentEpisodes(id, limit)
|
||||||
|
|
||||||
|
##### GET EXTRAFANART FOR LISTITEM #####
|
||||||
|
elif "extrafanart" in sys.argv[0]:
|
||||||
|
entrypoint.getExtraFanArt()
|
||||||
|
|
||||||
|
##### SHOW ADDON NODES LISTING #####
|
||||||
|
if not mode:
|
||||||
|
entrypoint.doMainListing()
|
||||||
|
|
||||||
|
if ( __name__ == "__main__" ):
|
||||||
|
xbmc.log('plugin.video.emby started')
|
||||||
|
|
||||||
|
if enableProfiling:
|
||||||
|
import cProfile
|
||||||
|
import pstats
|
||||||
|
import random
|
||||||
|
from time import gmtime, strftime
|
||||||
|
addonid = addon_.getAddonInfo('id').decode( 'utf-8' )
|
||||||
|
datapath = os.path.join( xbmc.translatePath( "special://profile/" ).decode( 'utf-8' ), "addon_data", addonid )
|
||||||
|
|
||||||
|
filename = os.path.join( datapath, strftime( "%Y%m%d%H%M%S",gmtime() ) + "-" + str( random.randrange(0,100000) ) + ".log" )
|
||||||
|
cProfile.run( 'Main()', filename )
|
||||||
|
|
||||||
|
stream = open( filename + ".txt", 'w')
|
||||||
|
p = pstats.Stats( filename, stream = stream )
|
||||||
|
p.sort_stats( "cumulative" )
|
||||||
|
p.print_stats()
|
||||||
|
|
||||||
##### BROWSE EMBY CHANNELS ROOT #####
|
else:
|
||||||
elif "channels" in mode:
|
Main()
|
||||||
entrypoint.BrowseChannels(id)
|
|
||||||
|
|
||||||
##### GET NEXTUP EPISODES FOR TAGNAME #####
|
xbmc.log('plugin.video.emby stopped')
|
||||||
elif "nextup" in mode:
|
|
||||||
limit = params['limit'][0]
|
|
||||||
entrypoint.getNextUpEpisodes(id, limit)
|
|
||||||
|
|
||||||
##### GET INPROGRESS EPISODES FOR TAGNAME #####
|
|
||||||
elif "inprogressepisodes" in mode:
|
|
||||||
limit = params['limit'][0]
|
|
||||||
entrypoint.getInProgressEpisodes(id, limit)
|
|
||||||
|
|
||||||
##### GET RECENT EPISODES FOR TAGNAME #####
|
|
||||||
elif "recentepisodes" in mode:
|
|
||||||
limit = params['limit'][0]
|
|
||||||
entrypoint.getRecentEpisodes(id, limit)
|
|
||||||
|
|
||||||
##### GET EXTRAFANART FOR LISTITEM #####
|
|
||||||
elif "extrafanart" in sys.argv[0]:
|
|
||||||
entrypoint.getExtraFanArt()
|
|
||||||
|
|
||||||
##### SHOW ADDON NODES LISTING #####
|
|
||||||
if not mode:
|
|
||||||
entrypoint.doMainListing()
|
|
|
@ -437,41 +437,57 @@ def BrowseChannels(id, folderid=None):
|
||||||
|
|
||||||
##### GET NEXTUP EPISODES FOR TAGNAME #####
|
##### GET NEXTUP EPISODES FOR TAGNAME #####
|
||||||
def getNextUpEpisodes(tagname,limit):
|
def getNextUpEpisodes(tagname,limit):
|
||||||
#if the addon is called with nextup parameter, we return the nextepisodes list of the given tagname
|
count=0
|
||||||
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)
|
#try to load from cache first
|
||||||
# If we found any, find the oldest unwatched show for each one.
|
win = xbmcgui.Window( 10000 )
|
||||||
if json_result.has_key('result') and json_result['result'].has_key('tvshows'):
|
data = win.getProperty("emby.widget.nextup." + tagname)
|
||||||
for item in json_result['result']['tvshows']:
|
if data and not win.getProperty("clearwidgetcache") == "clear":
|
||||||
addonSettings = xbmcaddon.Addon(id='plugin.video.emby')
|
data = json.loads(data)
|
||||||
|
for item in data:
|
||||||
|
liz = createListItem(item)
|
||||||
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz)
|
||||||
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
||||||
|
else:
|
||||||
|
episodes = list()
|
||||||
|
addonSettings = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
|
win.clearProperty("clearwidgetcache")
|
||||||
|
#if the addon is called with nextup parameter, we return the nextepisodes 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 the oldest unwatched show for each one.
|
||||||
|
if json_result.has_key('result') and json_result['result'].has_key('tvshows'):
|
||||||
|
for item in json_result['result']['tvshows']:
|
||||||
|
|
||||||
# If Ignore Specials is true only choose episodes from seasons greater than 0.
|
# If Ignore Specials is true only choose episodes from seasons greater than 0.
|
||||||
if addonSettings.getSetting("ignoreSpecialsNextEpisodes")=="true":
|
if addonSettings.getSetting("ignoreSpecialsNextEpisodes")=="true":
|
||||||
json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "tvshowid": %d, "sort": {"method":"episode"}, "filter": {"and": [ {"field": "playcount", "operator": "lessthan", "value":"1"}, {"field": "season", "operator": "greaterthan", "value": "0"} ]}, "properties": [ "title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime", "writer", "cast", "dateadded", "lastplayed" ], "limits":{"end":1}}, "id": "1"}' %item['tvshowid'])
|
json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "tvshowid": %d, "sort": {"method":"episode"}, "filter": {"and": [ {"field": "playcount", "operator": "lessthan", "value":"1"}, {"field": "season", "operator": "greaterthan", "value": "0"} ]}, "properties": [ "title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime", "writer", "dateadded", "lastplayed" ], "limits":{"end":1}}, "id": "1"}' %item['tvshowid'])
|
||||||
else:
|
else:
|
||||||
json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "tvshowid": %d, "sort": {"method":"episode"}, "filter": {"field": "playcount", "operator": "lessthan", "value":"1"}, "properties": [ "title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime", "writer", "cast", "dateadded", "lastplayed" ], "limits":{"end":1}}, "id": "1"}' %item['tvshowid'])
|
json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "tvshowid": %d, "sort": {"method":"episode"}, "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":1}}, "id": "1"}' %item['tvshowid'])
|
||||||
|
|
||||||
if json_query2:
|
if json_query2:
|
||||||
json_query2 = json.loads(json_query2)
|
json_query2 = json.loads(json_query2)
|
||||||
if json_query2.has_key('result') and json_query2['result'].has_key('episodes'):
|
if json_query2.has_key('result') and json_query2['result'].has_key('episodes'):
|
||||||
count = 0
|
for item in json_query2['result']['episodes']:
|
||||||
for item in json_query2['result']['episodes']:
|
liz = createListItem(item)
|
||||||
liz = createListItem(item)
|
episodes.append(item)
|
||||||
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz)
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz)
|
||||||
count +=1
|
count +=1
|
||||||
if count == limit:
|
if count == limit:
|
||||||
break
|
break
|
||||||
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
#use window prop as cache
|
||||||
|
win.setProperty("emby.widget.nextup." + tagname, json.dumps(episodes))
|
||||||
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
||||||
|
|
||||||
def getInProgressEpisodes(tagname,limit):
|
def getInProgressEpisodes(tagname,limit):
|
||||||
|
count = 0
|
||||||
#if the addon is called with inprogressepisodes parameter, we return the inprogressepisodes list of the given tagname
|
#if the addon is called with inprogressepisodes parameter, we return the inprogressepisodes list of the given tagname
|
||||||
xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
|
xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
|
||||||
# First we get a list of all the in-progress TV shows - filtered by tag
|
# 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_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)
|
json_result = json.loads(json_query_string)
|
||||||
# If we found any, find all in progress episodes for each one.
|
# 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'):
|
if json_result.has_key('result') and json_result['result'].has_key('tvshows'):
|
||||||
|
@ -481,13 +497,12 @@ def getInProgressEpisodes(tagname,limit):
|
||||||
if json_query2:
|
if json_query2:
|
||||||
json_query2 = json.loads(json_query2)
|
json_query2 = json.loads(json_query2)
|
||||||
if json_query2.has_key('result') and json_query2['result'].has_key('episodes'):
|
if json_query2.has_key('result') and json_query2['result'].has_key('episodes'):
|
||||||
count = 0
|
|
||||||
for item in json_query2['result']['episodes']:
|
for item in json_query2['result']['episodes']:
|
||||||
liz = createListItem(item)
|
liz = createListItem(item)
|
||||||
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz)
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz)
|
||||||
count +=1
|
count +=1
|
||||||
if count == limit:
|
if count == limit:
|
||||||
break
|
break
|
||||||
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
||||||
|
|
||||||
def getRecentEpisodes(tagname,limit):
|
def getRecentEpisodes(tagname,limit):
|
||||||
|
@ -515,7 +530,7 @@ def getRecentEpisodes(tagname,limit):
|
||||||
liz = createListItem(item)
|
liz = createListItem(item)
|
||||||
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz)
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz)
|
||||||
count += 1
|
count += 1
|
||||||
if count >= limit:
|
if count == limit:
|
||||||
break
|
break
|
||||||
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,6 @@ class Kodi_Monitor(xbmc.Monitor):
|
||||||
self.WINDOW.clearProperty("Played%s%s" % (type,id))
|
self.WINDOW.clearProperty("Played%s%s" % (type,id))
|
||||||
self.WINDOW.clearProperty('played_skipWatched')
|
self.WINDOW.clearProperty('played_skipWatched')
|
||||||
|
|
||||||
|
#clear the widget cache
|
||||||
|
self.WINDOW.setProperty('clearwidgetcache','clear')
|
||||||
|
|
Loading…
Reference in a new issue