reserved word type
This commit is contained in:
parent
98bee106cb
commit
47beade09a
1 changed files with 208 additions and 208 deletions
|
@ -1,209 +1,209 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
|
|
||||||
import clientinfo
|
import clientinfo
|
||||||
import downloadutils
|
import downloadutils
|
||||||
import embydb_functions as embydb
|
import embydb_functions as embydb
|
||||||
import playbackutils as pbutils
|
import playbackutils as pbutils
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
|
||||||
class KodiMonitor(xbmc.Monitor):
|
class KodiMonitor(xbmc.Monitor):
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.clientInfo = clientinfo.ClientInfo()
|
self.clientInfo = clientinfo.ClientInfo()
|
||||||
self.addonName = self.clientInfo.getAddonName()
|
self.addonName = self.clientInfo.getAddonName()
|
||||||
self.doUtils = downloadutils.DownloadUtils()
|
self.doUtils = downloadutils.DownloadUtils()
|
||||||
|
|
||||||
self.logMsg("Kodi monitor started.", 1)
|
self.logMsg("Kodi monitor started.", 1)
|
||||||
|
|
||||||
def logMsg(self, msg, lvl=1):
|
def logMsg(self, msg, lvl=1):
|
||||||
|
|
||||||
self.className = self.__class__.__name__
|
self.className = self.__class__.__name__
|
||||||
utils.logMsg("%s %s" % (self.addonName, self.className), msg, lvl)
|
utils.logMsg("%s %s" % (self.addonName, self.className), msg, lvl)
|
||||||
|
|
||||||
|
|
||||||
def onScanStarted(self, library):
|
def onScanStarted(self, library):
|
||||||
self.logMsg("Kodi library scan %s running." % library, 2)
|
self.logMsg("Kodi library scan %s running." % library, 2)
|
||||||
if library == "video":
|
if library == "video":
|
||||||
utils.window('emby_kodiScan', value="true")
|
utils.window('emby_kodiScan', value="true")
|
||||||
|
|
||||||
def onScanFinished(self, library):
|
def onScanFinished(self, library):
|
||||||
self.logMsg("Kodi library scan %s finished." % library, 2)
|
self.logMsg("Kodi library scan %s finished." % library, 2)
|
||||||
if library == "video":
|
if library == "video":
|
||||||
utils.window('emby_kodiScan', clear=True)
|
utils.window('emby_kodiScan', clear=True)
|
||||||
|
|
||||||
def onSettingsChanged(self):
|
def onSettingsChanged(self):
|
||||||
# Monitor emby settings
|
# Monitor emby settings
|
||||||
# Review reset setting at a later time, need to be adjusted to account for initial setup
|
# Review reset setting at a later time, need to be adjusted to account for initial setup
|
||||||
# changes.
|
# changes.
|
||||||
'''currentPath = utils.settings('useDirectPaths')
|
'''currentPath = utils.settings('useDirectPaths')
|
||||||
if utils.window('emby_pluginpath') != currentPath:
|
if utils.window('emby_pluginpath') != currentPath:
|
||||||
# Plugin path value changed. Offer to reset
|
# Plugin path value changed. Offer to reset
|
||||||
self.logMsg("Changed to playback mode detected", 1)
|
self.logMsg("Changed to playback mode detected", 1)
|
||||||
utils.window('emby_pluginpath', value=currentPath)
|
utils.window('emby_pluginpath', value=currentPath)
|
||||||
resp = xbmcgui.Dialog().yesno(
|
resp = xbmcgui.Dialog().yesno(
|
||||||
heading="Playback mode change detected",
|
heading="Playback mode change detected",
|
||||||
line1=(
|
line1=(
|
||||||
"Detected the playback mode has changed. The database "
|
"Detected the playback mode has changed. The database "
|
||||||
"needs to be recreated for the change to be applied. "
|
"needs to be recreated for the change to be applied. "
|
||||||
"Proceed?"))
|
"Proceed?"))
|
||||||
if resp:
|
if resp:
|
||||||
utils.reset()'''
|
utils.reset()'''
|
||||||
|
|
||||||
currentLog = utils.settings('logLevel')
|
currentLog = utils.settings('logLevel')
|
||||||
if utils.window('emby_logLevel') != currentLog:
|
if utils.window('emby_logLevel') != currentLog:
|
||||||
# The log level changed, set new prop
|
# The log level changed, set new prop
|
||||||
self.logMsg("New log level: %s" % currentLog, 1)
|
self.logMsg("New log level: %s" % currentLog, 1)
|
||||||
utils.window('emby_logLevel', value=currentLog)
|
utils.window('emby_logLevel', value=currentLog)
|
||||||
|
|
||||||
def onNotification(self, sender, method, data):
|
def onNotification(self, sender, method, data):
|
||||||
|
|
||||||
doUtils = self.doUtils
|
doUtils = self.doUtils
|
||||||
if method not in ("Playlist.OnAdd"):
|
if method not in ("Playlist.OnAdd"):
|
||||||
self.logMsg("Method: %s Data: %s" % (method, data), 1)
|
self.logMsg("Method: %s Data: %s" % (method, data), 1)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
data = json.loads(data,'utf-8')
|
data = json.loads(data,'utf-8')
|
||||||
|
|
||||||
|
|
||||||
if method == "Player.OnPlay":
|
if method == "Player.OnPlay":
|
||||||
# Set up report progress for emby playback
|
# Set up report progress for emby playback
|
||||||
item = data.get('item')
|
item = data.get('item')
|
||||||
try:
|
try:
|
||||||
kodiid = item['id']
|
kodiid = item['id']
|
||||||
type = item['type']
|
item_type = item['type']
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
self.logMsg("Item is invalid for playstate update.", 1)
|
self.logMsg("Item is invalid for playstate update.", 1)
|
||||||
else:
|
else:
|
||||||
if ((utils.settings('useDirectPaths') == "1" and not type == "song") or
|
if ((utils.settings('useDirectPaths') == "1" and not item_type == "song") or
|
||||||
(type == "song" and utils.settings('enableMusic') == "true")):
|
(item_type == "song" and utils.settings('enableMusic') == "true")):
|
||||||
# Set up properties for player
|
# Set up properties for player
|
||||||
embyconn = utils.kodiSQL('emby')
|
embyconn = utils.kodiSQL('emby')
|
||||||
embycursor = embyconn.cursor()
|
embycursor = embyconn.cursor()
|
||||||
emby_db = embydb.Embydb_Functions(embycursor)
|
emby_db = embydb.Embydb_Functions(embycursor)
|
||||||
emby_dbitem = emby_db.getItem_byKodiId(kodiid, type)
|
emby_dbitem = emby_db.getItem_byKodiId(kodiid, item_type)
|
||||||
try:
|
try:
|
||||||
itemid = emby_dbitem[0]
|
itemid = emby_dbitem[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.logMsg("No kodiid returned.", 1)
|
self.logMsg("No kodiid returned.", 1)
|
||||||
else:
|
else:
|
||||||
url = "{server}/emby/Users/{UserId}/Items/%s?format=json" % itemid
|
url = "{server}/emby/Users/{UserId}/Items/%s?format=json" % itemid
|
||||||
result = doUtils.downloadUrl(url)
|
result = doUtils.downloadUrl(url)
|
||||||
self.logMsg("Item: %s" % result, 2)
|
self.logMsg("Item: %s" % result, 2)
|
||||||
|
|
||||||
playurl = None
|
playurl = None
|
||||||
count = 0
|
count = 0
|
||||||
while not playurl and count < 2:
|
while not playurl and count < 2:
|
||||||
try:
|
try:
|
||||||
playurl = xbmc.Player().getPlayingFile()
|
playurl = xbmc.Player().getPlayingFile()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
count += 1
|
count += 1
|
||||||
xbmc.sleep(200)
|
xbmc.sleep(200)
|
||||||
else:
|
else:
|
||||||
listItem = xbmcgui.ListItem()
|
listItem = xbmcgui.ListItem()
|
||||||
playback = pbutils.PlaybackUtils(result)
|
playback = pbutils.PlaybackUtils(result)
|
||||||
|
|
||||||
if type == "song" and utils.settings('streamMusic') == "true":
|
if item_type == "song" and utils.settings('streamMusic') == "true":
|
||||||
utils.window('emby_%s.playmethod' % playurl,
|
utils.window('emby_%s.playmethod' % playurl,
|
||||||
value="DirectStream")
|
value="DirectStream")
|
||||||
else:
|
else:
|
||||||
utils.window('emby_%s.playmethod' % playurl,
|
utils.window('emby_%s.playmethod' % playurl,
|
||||||
value="DirectPlay")
|
value="DirectPlay")
|
||||||
# Set properties for player.py
|
# Set properties for player.py
|
||||||
playback.setProperties(playurl, listItem)
|
playback.setProperties(playurl, listItem)
|
||||||
finally:
|
finally:
|
||||||
embycursor.close()
|
embycursor.close()
|
||||||
|
|
||||||
|
|
||||||
elif method == "VideoLibrary.OnUpdate":
|
elif method == "VideoLibrary.OnUpdate":
|
||||||
# Manually marking as watched/unwatched
|
# Manually marking as watched/unwatched
|
||||||
playcount = data.get('playcount')
|
playcount = data.get('playcount')
|
||||||
item = data.get('item')
|
item = data.get('item')
|
||||||
try:
|
try:
|
||||||
kodiid = item['id']
|
kodiid = item['id']
|
||||||
type = item['type']
|
item_type = item['type']
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
self.logMsg("Item is invalid for playstate update.", 1)
|
self.logMsg("Item is invalid for playstate update.", 1)
|
||||||
else:
|
else:
|
||||||
# Send notification to the server.
|
# Send notification to the server.
|
||||||
embyconn = utils.kodiSQL('emby')
|
embyconn = utils.kodiSQL('emby')
|
||||||
embycursor = embyconn.cursor()
|
embycursor = embyconn.cursor()
|
||||||
emby_db = embydb.Embydb_Functions(embycursor)
|
emby_db = embydb.Embydb_Functions(embycursor)
|
||||||
emby_dbitem = emby_db.getItem_byKodiId(kodiid, type)
|
emby_dbitem = emby_db.getItem_byKodiId(kodiid, item_type)
|
||||||
try:
|
try:
|
||||||
itemid = emby_dbitem[0]
|
itemid = emby_dbitem[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.logMsg("Could not find itemid in emby database.", 1)
|
self.logMsg("Could not find itemid in emby database.", 1)
|
||||||
else:
|
else:
|
||||||
# Stop from manually marking as watched unwatched, with actual playback.
|
# Stop from manually marking as watched unwatched, with actual playback.
|
||||||
if utils.window('emby_skipWatched%s' % itemid) == "true":
|
if utils.window('emby_skipWatched%s' % itemid) == "true":
|
||||||
# property is set in player.py
|
# property is set in player.py
|
||||||
utils.window('emby_skipWatched%s' % itemid, clear=True)
|
utils.window('emby_skipWatched%s' % itemid, clear=True)
|
||||||
else:
|
else:
|
||||||
# notify the server
|
# notify the server
|
||||||
url = "{server}/emby/Users/{UserId}/PlayedItems/%s?format=json" % itemid
|
url = "{server}/emby/Users/{UserId}/PlayedItems/%s?format=json" % itemid
|
||||||
if playcount != 0:
|
if playcount != 0:
|
||||||
doUtils.downloadUrl(url, type="POST")
|
doUtils.downloadUrl(url, type="POST")
|
||||||
self.logMsg("Mark as watched for itemid: %s" % itemid, 1)
|
self.logMsg("Mark as watched for itemid: %s" % itemid, 1)
|
||||||
else:
|
else:
|
||||||
doUtils.downloadUrl(url, type="DELETE")
|
doUtils.downloadUrl(url, type="DELETE")
|
||||||
self.logMsg("Mark as unwatched for itemid: %s" % itemid, 1)
|
self.logMsg("Mark as unwatched for itemid: %s" % itemid, 1)
|
||||||
finally:
|
finally:
|
||||||
embycursor.close()
|
embycursor.close()
|
||||||
|
|
||||||
|
|
||||||
elif method == "VideoLibrary.OnRemove":
|
elif method == "VideoLibrary.OnRemove":
|
||||||
# Removed function, because with plugin paths + clean library, it will wipe
|
# Removed function, because with plugin paths + clean library, it will wipe
|
||||||
# entire library if user has permissions. Instead, use the emby context menu available
|
# entire library if user has permissions. Instead, use the emby context menu available
|
||||||
# in Isengard and higher version
|
# in Isengard and higher version
|
||||||
pass
|
pass
|
||||||
'''try:
|
'''try:
|
||||||
kodiid = data['id']
|
kodiid = data['id']
|
||||||
type = data['type']
|
type = data['type']
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
self.logMsg("Item is invalid for emby deletion.", 1)
|
self.logMsg("Item is invalid for emby deletion.", 1)
|
||||||
else:
|
else:
|
||||||
# Send the delete action to the server.
|
# Send the delete action to the server.
|
||||||
embyconn = utils.kodiSQL('emby')
|
embyconn = utils.kodiSQL('emby')
|
||||||
embycursor = embyconn.cursor()
|
embycursor = embyconn.cursor()
|
||||||
emby_db = embydb.Embydb_Functions(embycursor)
|
emby_db = embydb.Embydb_Functions(embycursor)
|
||||||
emby_dbitem = emby_db.getItem_byKodiId(kodiid, type)
|
emby_dbitem = emby_db.getItem_byKodiId(kodiid, type)
|
||||||
try:
|
try:
|
||||||
itemid = emby_dbitem[0]
|
itemid = emby_dbitem[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.logMsg("Could not find itemid in emby database.", 1)
|
self.logMsg("Could not find itemid in emby database.", 1)
|
||||||
else:
|
else:
|
||||||
if utils.settings('skipContextMenu') != "true":
|
if utils.settings('skipContextMenu') != "true":
|
||||||
resp = xbmcgui.Dialog().yesno(
|
resp = xbmcgui.Dialog().yesno(
|
||||||
heading="Confirm delete",
|
heading="Confirm delete",
|
||||||
line1="Delete file on Emby Server?")
|
line1="Delete file on Emby Server?")
|
||||||
if not resp:
|
if not resp:
|
||||||
self.logMsg("User skipped deletion.", 1)
|
self.logMsg("User skipped deletion.", 1)
|
||||||
embycursor.close()
|
embycursor.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
url = "{server}/emby/Items/%s?format=json" % itemid
|
url = "{server}/emby/Items/%s?format=json" % itemid
|
||||||
self.logMsg("Deleting request: %s" % itemid)
|
self.logMsg("Deleting request: %s" % itemid)
|
||||||
doUtils.downloadUrl(url, type="DELETE")
|
doUtils.downloadUrl(url, type="DELETE")
|
||||||
finally:
|
finally:
|
||||||
embycursor.close()'''
|
embycursor.close()'''
|
||||||
|
|
||||||
|
|
||||||
elif method == "System.OnWake":
|
elif method == "System.OnWake":
|
||||||
# Allow network to wake up
|
# Allow network to wake up
|
||||||
xbmc.sleep(10000)
|
xbmc.sleep(10000)
|
||||||
utils.window('emby_onWake', value="true")
|
utils.window('emby_onWake', value="true")
|
||||||
|
|
||||||
elif method == "Playlist.OnClear":
|
elif method == "Playlist.OnClear":
|
||||||
pass
|
pass
|
Loading…
Reference in a new issue