diff --git a/default.py b/default.py
index 4680f867..5d7f64c0 100644
--- a/default.py
+++ b/default.py
@@ -25,43 +25,32 @@ from API import API
from PluginFunctions import PluginFunctions
-def json_query( method, unplayed=False, properties=None, sort=False, query_filter=False, limit=False, params=False):
- json_query = { "jsonrpc": "2.0", "id": 1, "method": method, "params": {} }
- if properties is not None:
- json_query["params"]["properties"] = properties
- if limit is not None:
- json_query["params"]["limits"] = {"end":limit if limit else 25}
- if sort is not None:
- json_query["params"]["sort"] = sort
- if query_filter:
- json_query["params"]["filter"] = query_filter
- if params:
- json_query["params"].update(params)
-
- json_string = json.dumps(json_query)
- rv = xbmc.executeJSONRPC(json_string)
-
- return unicode(rv, 'utf-8', errors='ignore')
-
-
try:
params = utils.get_params(sys.argv[2])
mode = params['mode']
- id = params['id']
+ id = params.get('id', None)
except:
params = {}
mode = None
-if mode == "play":
+if mode == "play" or mode == "playfromaddon":
# Play items via plugin://plugin.video.emby/
url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&ImageTypeLimit=1" % id
result = DownloadUtils().downloadUrl(url)
- item = PlaybackUtils().PLAY(result, setup="default")
+ #from from addon needed if the palyback is launched from the addon itself
+ if mode == "playfromaddon":
+ item = PlaybackUtils().PLAY(result, setup="service")
+ else:
+ item = PlaybackUtils().PLAY(result, setup="default")
-
-elif "getnextup" in sys.argv[0]:
- params = utils.get_params(sys.argv[2])
- tagname = params['tagname']
+elif mode == "reset":
+ utils.reset()
+
+
+elif mode == "nextup":
+ #if the addon is called with nextup parameter, we return the nextepisodes list of the given tagname
+ tagname = params['id']
+ limit = int(params['limit'])
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)
@@ -87,6 +76,7 @@ elif "getnextup" in sys.argv[0]:
plot = item['plot']
liz = xbmcgui.ListItem(item['title'])
liz.setInfo( type="Video", infoLabels={ "Title": item['title'] })
+ 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'] })
@@ -111,10 +101,13 @@ elif "getnextup" in sys.argv[0]:
liz.setProperty("fanart_image", item['art'].get('tvshow.fanart',''))
for key, value in item['streamdetails'].iteritems():
for stream in value:
- liz.addStreamInfo( key, stream )
-
- xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=item['file'], listitem=liz)
- xbmcplugin.endOfDirectory(handle= int(sys.argv[1]))
+ liz.addStreamInfo( key, stream )
+ file = item['file'].replace("mode=play","mode=playfromaddon")
+ xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=file, listitem=liz)
+ count +=1
+ if count == limit:
+ break
+ xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
#get extrafanart for listitem - this will only be used for skins that actually call the listitem's path + fanart dir...
@@ -164,9 +157,6 @@ elif "extrafanart" in sys.argv[0]:
#always do endofdirectory to prevent errors in the logs
xbmcplugin.endOfDirectory(int(sys.argv[1]))
-
-elif sys.argv[1] == "reset":
- utils.reset()
else:
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.emby)')
diff --git a/resources/lib/DownloadUtils.py b/resources/lib/DownloadUtils.py
index 390a9d2d..d18d2b8a 100644
--- a/resources/lib/DownloadUtils.py
+++ b/resources/lib/DownloadUtils.py
@@ -238,7 +238,10 @@ class DownloadUtils():
self.logMsg("====== 200 Success ======", 2)
return r
except:
- self.logMsg("Unable to convert the response for: %s" % url, 1)
+ if r.headers['content-type'] == "text/html":
+ pass
+ else:
+ self.logMsg("Unable to convert the response for: %s" % url, 1)
else:
r.raise_for_status()
diff --git a/resources/lib/KodiMonitor.py b/resources/lib/KodiMonitor.py
index be4688ef..a9104355 100644
--- a/resources/lib/KodiMonitor.py
+++ b/resources/lib/KodiMonitor.py
@@ -17,6 +17,9 @@ from DownloadUtils import DownloadUtils
from PlaybackUtils import PlaybackUtils
class Kodi_Monitor(xbmc.Monitor):
+
+ WINDOW = xbmcgui.Window(10000)
+
def __init__(self, *args, **kwargs):
xbmc.Monitor.__init__(self)
@@ -26,7 +29,8 @@ class Kodi_Monitor(xbmc.Monitor):
#this library monitor is used to detect a watchedstate change by the user through the library
#as well as detect when a library item has been deleted to pass the delete to the Emby server
def onNotification (self,sender,method,data):
- addon = xbmcaddon.Addon(id='plugin.video.emby')
+
+ WINDOW = self.WINDOW
downloadUtils = DownloadUtils()
if method == "VideoLibrary.OnUpdate":
@@ -37,15 +41,26 @@ class Kodi_Monitor(xbmc.Monitor):
playcount = jsondata.get("playcount")
item = jsondata.get("item").get("id")
type = jsondata.get("item").get("type")
- if playcount != None:
+ prop = WINDOW.getProperty('Played%s%s' % (type,item))
+
+ if (playcount != None) and (prop != "true"):
+ WINDOW.setProperty("Played%s%s" % (type,item), "true")
utils.logMsg("MB# Sync","Kodi_Monitor--> VideoLibrary.OnUpdate : " + str(data),2)
WriteKodiDB().updatePlayCountFromKodi(item, type, playcount)
+
+ self.clearProperty(type,item)
if method == "System.OnWake":
xbmc.sleep(10000) #Allow network to wake up
utils.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Started)",1)
libSync = LibrarySync().FullLibrarySync()
utils.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Finished) " + str(libSync),1)
+
+ def clearProperty(self,type,id):
+ # The sleep is necessary since VideoLibrary.OnUpdate
+ # triggers 3 times in a row.
+ xbmc.sleep(100)
+ self.WINDOW.clearProperty("Played%s%s" % (type,id))
diff --git a/resources/lib/PlaybackUtils.py b/resources/lib/PlaybackUtils.py
index 4dae984a..854a28f8 100644
--- a/resources/lib/PlaybackUtils.py
+++ b/resources/lib/PlaybackUtils.py
@@ -121,7 +121,7 @@ class PlaybackUtils():
if xbmc.getCondVisibility("Window.IsActive(home)"):
xbmc.Player().play(playurl,listItem)
else:
- xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
+ xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
def setArt(self, list,name,path):
if name=='thumb' or name=='fanart_image' or name=='small_poster' or name=='tiny_poster' or name == "medium_landscape" or name=='medium_poster' or name=='small_fanartimage' or name=='medium_fanartimage' or name=='fanart_noindicators':
diff --git a/resources/lib/Utils.py b/resources/lib/Utils.py
index 578a5cae..93af17b1 100644
--- a/resources/lib/Utils.py
+++ b/resources/lib/Utils.py
@@ -143,16 +143,6 @@ def CleanName(filename):
cleanedFilename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore')
return ''.join(c for c in cleanedFilename if c in validFilenameChars)
-
-def removeDirectory(path):
- if xbmcvfs.exists(path):
- allDirs, allFiles = xbmcvfs.listdir(path)
- for dir in allDirs:
- xbmcvfs.rmdir(os.path.join(path,dir))
- for file in allFiles:
- xbmcvfs.delete(os.path.join(path,file))
-
- xbmcvfs.rmdir(path)
def reset():
@@ -161,6 +151,16 @@ def reset():
if return_value == 0:
return
+ #cleanup video nodes
+ import shutil
+ path = "special://userdata/library/video/"
+ if xbmcvfs.exists(path):
+ allDirs, allFiles = xbmcvfs.listdir(path)
+ for dir in allDirs:
+ if dir.startswith("Emby "):
+ shutil.rmtree(xbmc.translatePath("special://userdata/library/video/" + dir))
+
+
# Ask if user information should be deleted too.
return_user = xbmcgui.Dialog().yesno("Warning", "Reset all Emby Addon settings?")
diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py
index 7ce70520..277437f2 100644
--- a/resources/lib/WriteKodiDB.py
+++ b/resources/lib/WriteKodiDB.py
@@ -1159,6 +1159,17 @@ class WriteKodiDB():
ET.ElementTree(root).write(nodefile, xml_declaration=True)
except:
ET.ElementTree(root).write(nodefile)
+
+ #create tag node - nextup items
+ nodefile = os.path.join(libraryPath, tagname + "_nextup_episodes.xml")
+ root = Element("node", {"order":"4", "type":"folder"})
+ SubElement(root, "label").text = tagname + " - Nextup episodes"
+ SubElement(root, "path").text = "plugin://plugin.video.emby/?id=%s&mode=nextup&limit=25" %tagname
+ SubElement(root, "icon").text = "DefaultMovies.png"
+ try:
+ ET.ElementTree(root).write(nodefile, xml_declaration=True)
+ except:
+ ET.ElementTree(root).write(nodefile)
def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset, connection, cursor):
strSet = boxset["Name"]
diff --git a/resources/settings.xml b/resources/settings.xml
index b1305123..a58bea71 100644
--- a/resources/settings.xml
+++ b/resources/settings.xml
@@ -10,7 +10,6 @@
-
@@ -21,6 +20,7 @@
+
@@ -29,6 +29,6 @@
-
+