cleanup
This commit is contained in:
parent
d78c04d67f
commit
d080c49821
6 changed files with 174 additions and 175 deletions
315
contextmenu.py
315
contextmenu.py
|
@ -1,159 +1,158 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
import xbmcaddon
|
import xbmcaddon
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
|
|
||||||
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 = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8')
|
base_resource = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8')
|
||||||
sys.path.append(base_resource)
|
sys.path.append(base_resource)
|
||||||
|
|
||||||
import artwork
|
import artwork
|
||||||
import utils
|
import utils
|
||||||
import clientinfo
|
import clientinfo
|
||||||
import downloadutils
|
import downloadutils
|
||||||
import librarysync
|
import librarysync
|
||||||
import read_embyserver as embyserver
|
import read_embyserver as embyserver
|
||||||
import embydb_functions as embydb
|
import embydb_functions as embydb
|
||||||
import kodidb_functions as kodidb
|
import kodidb_functions as kodidb
|
||||||
import musicutils as musicutils
|
import musicutils as musicutils
|
||||||
import api
|
import api
|
||||||
|
|
||||||
def logMsg(msg, lvl=1):
|
def logMsg(msg, lvl=1):
|
||||||
utils.logMsg("%s %s" % ("EMBY", "Contextmenu"), msg, lvl)
|
utils.logMsg("%s %s" % ("EMBY", "Contextmenu"), msg, lvl)
|
||||||
|
|
||||||
|
|
||||||
#Kodi contextmenu item to configure the emby settings
|
#Kodi contextmenu item to configure the emby settings
|
||||||
#for now used to set ratings but can later be used to sync individual items etc.
|
#for now used to set ratings but can later be used to sync individual items etc.
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
itemid = xbmc.getInfoLabel("ListItem.DBID").decode("utf-8")
|
itemid = xbmc.getInfoLabel("ListItem.DBID").decode("utf-8")
|
||||||
itemtype = xbmc.getInfoLabel("ListItem.DBTYPE").decode("utf-8")
|
itemtype = xbmc.getInfoLabel("ListItem.DBTYPE").decode("utf-8")
|
||||||
|
|
||||||
emby = embyserver.Read_EmbyServer()
|
emby = embyserver.Read_EmbyServer()
|
||||||
|
|
||||||
embyid = ""
|
embyid = ""
|
||||||
if not itemtype and xbmc.getCondVisibility("Container.Content(albums)"): itemtype = "album"
|
if not itemtype and xbmc.getCondVisibility("Container.Content(albums)"): itemtype = "album"
|
||||||
if not itemtype and xbmc.getCondVisibility("Container.Content(artists)"): itemtype = "artist"
|
if not itemtype and xbmc.getCondVisibility("Container.Content(artists)"): itemtype = "artist"
|
||||||
if not itemtype and xbmc.getCondVisibility("Container.Content(songs)"): itemtype = "song"
|
if not itemtype and xbmc.getCondVisibility("Container.Content(songs)"): itemtype = "song"
|
||||||
if not itemtype and xbmc.getCondVisibility("Container.Content(pictures)"): itemtype = "picture"
|
if not itemtype and xbmc.getCondVisibility("Container.Content(pictures)"): itemtype = "picture"
|
||||||
|
|
||||||
if (not itemid or itemid == "-1") and xbmc.getInfoLabel("ListItem.Property(embyid)"):
|
if (not itemid or itemid == "-1") and xbmc.getInfoLabel("ListItem.Property(embyid)"):
|
||||||
embyid = xbmc.getInfoLabel("ListItem.Property(embyid)")
|
embyid = xbmc.getInfoLabel("ListItem.Property(embyid)")
|
||||||
else:
|
else:
|
||||||
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)
|
||||||
item = emby_db.getItem_byKodiId(itemid, itemtype)
|
item = emby_db.getItem_byKodiId(itemid, itemtype)
|
||||||
embycursor.close()
|
embycursor.close()
|
||||||
if item: embyid = item[0]
|
if item: embyid = item[0]
|
||||||
|
|
||||||
logMsg("Contextmenu opened for embyid: %s - itemtype: %s" %(embyid,itemtype))
|
logMsg("Contextmenu opened for embyid: %s - itemtype: %s" %(embyid,itemtype))
|
||||||
|
|
||||||
if embyid:
|
if embyid:
|
||||||
item = emby.getItem(embyid)
|
item = emby.getItem(embyid)
|
||||||
API = api.API(item)
|
API = api.API(item)
|
||||||
userdata = API.getUserData()
|
userdata = API.getUserData()
|
||||||
likes = userdata['Likes']
|
likes = userdata['Likes']
|
||||||
favourite = userdata['Favorite']
|
favourite = userdata['Favorite']
|
||||||
|
|
||||||
options=[]
|
options=[]
|
||||||
if likes == True:
|
if likes == True:
|
||||||
#clear like for the item
|
#clear like for the item
|
||||||
options.append(utils.language(30402))
|
options.append(utils.language(30402))
|
||||||
if likes == False or likes == None:
|
if likes == False or likes == None:
|
||||||
#Like the item
|
#Like the item
|
||||||
options.append(utils.language(30403))
|
options.append(utils.language(30403))
|
||||||
if likes == True or likes == None:
|
if likes == True or likes == None:
|
||||||
#Dislike the item
|
#Dislike the item
|
||||||
options.append(utils.language(30404))
|
options.append(utils.language(30404))
|
||||||
if favourite == False:
|
if favourite == False:
|
||||||
#Add to emby favourites
|
#Add to emby favourites
|
||||||
options.append(utils.language(30405))
|
options.append(utils.language(30405))
|
||||||
if favourite == True:
|
if favourite == True:
|
||||||
#Remove from emby favourites
|
#Remove from emby favourites
|
||||||
options.append(utils.language(30406))
|
options.append(utils.language(30406))
|
||||||
if itemtype == "song":
|
if itemtype == "song":
|
||||||
#Set custom song rating
|
#Set custom song rating
|
||||||
options.append(utils.language(30407))
|
options.append(utils.language(30407))
|
||||||
|
|
||||||
#delete item
|
#delete item
|
||||||
options.append(utils.language(30409))
|
options.append(utils.language(30409))
|
||||||
|
|
||||||
#addon settings
|
#addon settings
|
||||||
options.append(utils.language(30408))
|
options.append(utils.language(30408))
|
||||||
|
|
||||||
#display select dialog and process results
|
#display select dialog and process results
|
||||||
header = utils.language(30401)
|
header = utils.language(30401)
|
||||||
ret = xbmcgui.Dialog().select(header, options)
|
ret = xbmcgui.Dialog().select(header, options)
|
||||||
if ret != -1:
|
if ret != -1:
|
||||||
if options[ret] == utils.language(30402):
|
if options[ret] == utils.language(30402):
|
||||||
emby.updateUserRating(embyid, deletelike=True)
|
emby.updateUserRating(embyid, deletelike=True)
|
||||||
if options[ret] == utils.language(30403):
|
if options[ret] == utils.language(30403):
|
||||||
emby.updateUserRating(embyid, like=True)
|
emby.updateUserRating(embyid, like=True)
|
||||||
if options[ret] == utils.language(30404):
|
if options[ret] == utils.language(30404):
|
||||||
emby.updateUserRating(embyid, like=False)
|
emby.updateUserRating(embyid, like=False)
|
||||||
if options[ret] == utils.language(30405):
|
if options[ret] == utils.language(30405):
|
||||||
emby.updateUserRating(embyid, favourite=True)
|
emby.updateUserRating(embyid, favourite=True)
|
||||||
if options[ret] == utils.language(30406):
|
if options[ret] == utils.language(30406):
|
||||||
emby.updateUserRating(embyid, favourite=False)
|
emby.updateUserRating(embyid, favourite=False)
|
||||||
if options[ret] == utils.language(30407):
|
if options[ret] == utils.language(30407):
|
||||||
kodiconn = utils.kodiSQL('music')
|
kodiconn = utils.kodiSQL('music')
|
||||||
kodicursor = kodiconn.cursor()
|
kodicursor = kodiconn.cursor()
|
||||||
query = ' '.join(("SELECT rating", "FROM song", "WHERE idSong = ?" ))
|
query = ' '.join(("SELECT rating", "FROM song", "WHERE idSong = ?" ))
|
||||||
kodicursor.execute(query, (itemid,))
|
kodicursor.execute(query, (itemid,))
|
||||||
currentvalue = int(round(float(kodicursor.fetchone()[0]),0))
|
currentvalue = int(round(float(kodicursor.fetchone()[0]),0))
|
||||||
newvalue = xbmcgui.Dialog().numeric(0, "Set custom song rating (0-5)", str(currentvalue))
|
newvalue = xbmcgui.Dialog().numeric(0, "Set custom song rating (0-5)", str(currentvalue))
|
||||||
if newvalue:
|
if newvalue:
|
||||||
newvalue = int(newvalue)
|
newvalue = int(newvalue)
|
||||||
if newvalue > 5: newvalue = "5"
|
if newvalue > 5: newvalue = "5"
|
||||||
if utils.settings('enableUpdateSongRating') == "true":
|
if utils.settings('enableUpdateSongRating') == "true":
|
||||||
musicutils.updateRatingToFile(newvalue, API.getFilePath())
|
musicutils.updateRatingToFile(newvalue, API.getFilePath())
|
||||||
if utils.settings('enableExportSongRating') == "true":
|
if utils.settings('enableExportSongRating') == "true":
|
||||||
like, favourite, deletelike = musicutils.getEmbyRatingFromKodiRating(newvalue)
|
like, favourite, deletelike = musicutils.getEmbyRatingFromKodiRating(newvalue)
|
||||||
emby.updateUserRating(embyid, like, favourite, deletelike)
|
emby.updateUserRating(embyid, like, favourite, deletelike)
|
||||||
query = ' '.join(( "UPDATE song","SET rating = ?", "WHERE idSong = ?" ))
|
query = ' '.join(( "UPDATE song","SET rating = ?", "WHERE idSong = ?" ))
|
||||||
kodicursor.execute(query, (newvalue,itemid,))
|
kodicursor.execute(query, (newvalue,itemid,))
|
||||||
kodiconn.commit()
|
kodiconn.commit()
|
||||||
|
|
||||||
if options[ret] == utils.language(30408):
|
if options[ret] == utils.language(30408):
|
||||||
#Open addon settings
|
#Open addon settings
|
||||||
xbmc.executebuiltin("Addon.OpenSettings(plugin.video.emby)")
|
xbmc.executebuiltin("Addon.OpenSettings(plugin.video.emby)")
|
||||||
|
|
||||||
if options[ret] == utils.language(30409):
|
if options[ret] == utils.language(30409):
|
||||||
#delete item from the server
|
#delete item from the server
|
||||||
delete = True
|
delete = True
|
||||||
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 from Emby Server? This will "
|
line1=("Delete file from Emby Server? This will "
|
||||||
"also delete the file(s) from disk!"))
|
"also delete the file(s) from disk!"))
|
||||||
if not resp:
|
if not resp:
|
||||||
logMsg("User skipped deletion for: %s." % embyid, 1)
|
logMsg("User skipped deletion for: %s." % embyid, 1)
|
||||||
delete = False
|
delete = False
|
||||||
|
|
||||||
if delete:
|
if delete:
|
||||||
import downloadutils
|
import downloadutils
|
||||||
doUtils = downloadutils.DownloadUtils()
|
doUtils = downloadutils.DownloadUtils()
|
||||||
url = "{server}/emby/Items/%s?format=json" % embyid
|
url = "{server}/emby/Items/%s?format=json" % embyid
|
||||||
logMsg("Deleting request: %s" % embyid, 0)
|
logMsg("Deleting request: %s" % embyid, 0)
|
||||||
doUtils.downloadUrl(url, type="DELETE")
|
doUtils.downloadUrl(url, action_type="DELETE")
|
||||||
|
|
||||||
'''if utils.settings('skipContextMenu') != "true":
|
'''if utils.settings('skipContextMenu') != "true":
|
||||||
if xbmcgui.Dialog().yesno(
|
if xbmcgui.Dialog().yesno(
|
||||||
heading="Confirm delete",
|
heading="Confirm delete",
|
||||||
line1=("Delete file on Emby Server? This will "
|
line1=("Delete file on Emby Server? This will "
|
||||||
"also delete the file(s) from disk!")):
|
"also delete the file(s) from disk!")):
|
||||||
import downloadutils
|
import downloadutils
|
||||||
doUtils = downloadutils.DownloadUtils()
|
doUtils = downloadutils.DownloadUtils()
|
||||||
url = "{server}/emby/Items/%s?format=json" % embyid
|
doUtils.downloadUrl("{server}/emby/Items/%s?format=json" % embyid, action_type="DELETE")'''
|
||||||
doUtils.downloadUrl(url, type="DELETE")'''
|
|
||||||
|
xbmc.sleep(500)
|
||||||
xbmc.sleep(500)
|
|
||||||
xbmc.executebuiltin("Container.Update")
|
xbmc.executebuiltin("Container.Update")
|
|
@ -97,7 +97,7 @@ class DownloadUtils():
|
||||||
self.logMsg("Capabilities URL: %s" % url, 2)
|
self.logMsg("Capabilities URL: %s" % url, 2)
|
||||||
self.logMsg("Postdata: %s" % data, 2)
|
self.logMsg("Postdata: %s" % data, 2)
|
||||||
|
|
||||||
self.downloadUrl(url, postBody=data, type="POST")
|
self.downloadUrl(url, postBody=data, action_type="POST")
|
||||||
self.logMsg("Posted capabilities to %s" % self.server, 2)
|
self.logMsg("Posted capabilities to %s" % self.server, 2)
|
||||||
|
|
||||||
# Attempt at getting sessionId
|
# Attempt at getting sessionId
|
||||||
|
@ -140,7 +140,7 @@ class DownloadUtils():
|
||||||
"{server}/emby/Sessions/%s/Users/%s?format=json"
|
"{server}/emby/Sessions/%s/Users/%s?format=json"
|
||||||
% (sessionId, userId)
|
% (sessionId, userId)
|
||||||
)
|
)
|
||||||
self.downloadUrl(url, postBody={}, type="POST")
|
self.downloadUrl(url, postBody={}, action_type="POST")
|
||||||
|
|
||||||
|
|
||||||
def startSession(self):
|
def startSession(self):
|
||||||
|
|
|
@ -166,7 +166,7 @@ def deleteItem():
|
||||||
doUtils = downloadutils.DownloadUtils()
|
doUtils = downloadutils.DownloadUtils()
|
||||||
url = "{server}/emby/Items/%s?format=json" % embyid
|
url = "{server}/emby/Items/%s?format=json" % embyid
|
||||||
utils.logMsg("EMBY delete", "Deleting request: %s" % embyid, 0)
|
utils.logMsg("EMBY delete", "Deleting request: %s" % embyid, 0)
|
||||||
doUtils.downloadUrl(url, type="DELETE")
|
doUtils.downloadUrl(url, action_type="DELETE")
|
||||||
|
|
||||||
##### ADD ADDITIONAL USERS #####
|
##### ADD ADDITIONAL USERS #####
|
||||||
def addUser():
|
def addUser():
|
||||||
|
@ -221,7 +221,7 @@ def addUser():
|
||||||
selected = additionalUsername[resp]
|
selected = additionalUsername[resp]
|
||||||
selected_userId = additionalUserlist[selected]
|
selected_userId = additionalUserlist[selected]
|
||||||
url = "{server}/emby/Sessions/%s/Users/%s" % (sessionId, selected_userId)
|
url = "{server}/emby/Sessions/%s/Users/%s" % (sessionId, selected_userId)
|
||||||
doUtils.downloadUrl(url, postBody={}, type="DELETE")
|
doUtils.downloadUrl(url, postBody={}, action_type="DELETE")
|
||||||
dialog.notification(
|
dialog.notification(
|
||||||
heading="Success!",
|
heading="Success!",
|
||||||
message="%s removed from viewing session" % selected,
|
message="%s removed from viewing session" % selected,
|
||||||
|
@ -254,7 +254,7 @@ def addUser():
|
||||||
selected = users[resp]
|
selected = users[resp]
|
||||||
selected_userId = userlist[selected]
|
selected_userId = userlist[selected]
|
||||||
url = "{server}/emby/Sessions/%s/Users/%s" % (sessionId, selected_userId)
|
url = "{server}/emby/Sessions/%s/Users/%s" % (sessionId, selected_userId)
|
||||||
doUtils.downloadUrl(url, postBody={}, type="POST")
|
doUtils.downloadUrl(url, postBody={}, action_type="POST")
|
||||||
dialog.notification(
|
dialog.notification(
|
||||||
heading="Success!",
|
heading="Success!",
|
||||||
message="%s added to viewing session" % selected,
|
message="%s added to viewing session" % selected,
|
||||||
|
|
|
@ -154,10 +154,10 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
# 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, action_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, action_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()
|
||||||
|
@ -195,7 +195,7 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
|
|
||||||
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, action_type="DELETE")
|
||||||
finally:
|
finally:
|
||||||
embycursor.close()'''
|
embycursor.close()'''
|
||||||
|
|
||||||
|
|
|
@ -208,7 +208,7 @@ class Player(xbmc.Player):
|
||||||
|
|
||||||
# Post playback to server
|
# Post playback to server
|
||||||
self.logMsg("Sending POST play started: %s." % postdata, 2)
|
self.logMsg("Sending POST play started: %s." % postdata, 2)
|
||||||
self.doUtils(url, postBody=postdata, type="POST")
|
self.doUtils(url, postBody=postdata, action_type="POST")
|
||||||
|
|
||||||
# Ensure we do have a runtime
|
# Ensure we do have a runtime
|
||||||
try:
|
try:
|
||||||
|
@ -480,7 +480,7 @@ class Player(xbmc.Player):
|
||||||
|
|
||||||
url = "{server}/emby/Items/%s?format=json" % itemid
|
url = "{server}/emby/Items/%s?format=json" % itemid
|
||||||
self.logMsg("Deleting request: %s" % itemid, 1)
|
self.logMsg("Deleting request: %s" % itemid, 1)
|
||||||
self.doUtils(url, type="DELETE")
|
self.doUtils(url, action_type="DELETE")
|
||||||
|
|
||||||
self.stopPlayback(data)
|
self.stopPlayback(data)
|
||||||
|
|
||||||
|
@ -489,7 +489,7 @@ class Player(xbmc.Player):
|
||||||
self.logMsg("Transcoding for %s terminated." % itemid, 1)
|
self.logMsg("Transcoding for %s terminated." % itemid, 1)
|
||||||
deviceId = self.clientInfo.getDeviceId()
|
deviceId = self.clientInfo.getDeviceId()
|
||||||
url = "{server}/emby/Videos/ActiveEncodings?DeviceId=%s" % deviceId
|
url = "{server}/emby/Videos/ActiveEncodings?DeviceId=%s" % deviceId
|
||||||
self.doUtils(url, type="DELETE")
|
self.doUtils(url, action_type="DELETE")
|
||||||
|
|
||||||
self.played_info.clear()
|
self.played_info.clear()
|
||||||
|
|
||||||
|
@ -508,4 +508,4 @@ class Player(xbmc.Player):
|
||||||
'MediaSourceId': itemId,
|
'MediaSourceId': itemId,
|
||||||
'PositionTicks': positionTicks
|
'PositionTicks': positionTicks
|
||||||
}
|
}
|
||||||
self.doUtils(url, postBody=postdata, type="POST")
|
self.doUtils(url, postBody=postdata, action_type="POST")
|
|
@ -522,16 +522,16 @@ class Read_EmbyServer():
|
||||||
# Updates the user rating to Emby
|
# Updates the user rating to Emby
|
||||||
|
|
||||||
if favourite:
|
if favourite:
|
||||||
self.doUtils("{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid, type="POST")
|
self.doUtils("{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid, action_type="POST")
|
||||||
elif favourite == False:
|
elif favourite == False:
|
||||||
self.doUtils("{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid, type="DELETE")
|
self.doUtils("{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid, action_type="DELETE")
|
||||||
|
|
||||||
if not deletelike and like:
|
if not deletelike and like:
|
||||||
self.doUtils("{server}/emby/Users/{UserId}/Items/%s/Rating?Likes=true&format=json" % itemid, type="POST")
|
self.doUtils("{server}/emby/Users/{UserId}/Items/%s/Rating?Likes=true&format=json" % itemid, action_type="POST")
|
||||||
elif not deletelike and like is False:
|
elif not deletelike and like is False:
|
||||||
self.doUtils("{server}/emby/Users/{UserId}/Items/%s/Rating?Likes=false&format=json" % itemid, type="POST")
|
self.doUtils("{server}/emby/Users/{UserId}/Items/%s/Rating?Likes=false&format=json" % itemid, action_type="POST")
|
||||||
elif deletelike:
|
elif deletelike:
|
||||||
self.doUtils("{server}/emby/Users/{UserId}/Items/%s/Rating?format=json" % itemid, type="DELETE")
|
self.doUtils("{server}/emby/Users/{UserId}/Items/%s/Rating?format=json" % itemid, action_type="DELETE")
|
||||||
|
|
||||||
self.logMsg("Update user rating to emby for itemid: %s "
|
self.logMsg("Update user rating to emby for itemid: %s "
|
||||||
"| like: %s | favourite: %s | deletelike: %s"
|
"| like: %s | favourite: %s | deletelike: %s"
|
||||||
|
|
Loading…
Reference in a new issue