diff --git a/contextmenu.py b/contextmenu.py
index a983ab59..5c16e441 100644
--- a/contextmenu.py
+++ b/contextmenu.py
@@ -50,7 +50,7 @@ if __name__ == '__main__':
elif xbmc.getCondVisibility("Container.Content(pictures)"):
itemType = "picture"
else:
- log("Itemtype is unknown.")
+ log("ItemType is unknown.")
if (not kodiId or kodiId == "-1") and xbmc.getInfoLabel("ListItem.Property(embyid)"):
itemId = xbmc.getInfoLabel("ListItem.Property(embyid)")
@@ -67,9 +67,11 @@ if __name__ == '__main__':
pass
- log("Found ItemId: %s/Itemtype: %s" % (itemId, itemType), 1)
+ log("Found ItemId: %s ItemType: %s" % (itemId, itemType), 1)
if itemId:
+ dialog = xbmcgui.Dialog()
+
emby = embyserver.Read_EmbyServer()
item = emby.getItem(itemId)
API = api.API(item)
@@ -98,71 +100,69 @@ if __name__ == '__main__':
options.append(lang(30408))
# Display select dialog and process results
+ resp = xbmcgui.Dialog().select(lang(30401), options)
+ if resp > -1:
+ selected = options[resp]
- ret = xbmcgui.Dialog().select(lang(30401), options)
- if ret != -1:
- if options[ret] == lang(30410):
+ if selected == lang(30410):
+ # Refresh item
emby.refreshItem(itemId)
- if options[ret] == lang(30402):
- emby.updateUserRating(itemId, deletelike=True)
- if options[ret] == lang(30403):
- emby.updateUserRating(itemId, like=True)
- if options[ret] == lang(30404):
- emby.updateUserRating(itemId, like=False)
- if options[ret] == lang(30405):
+ elif selected == lang(30405):
+ # Add favourite
emby.updateUserRating(itemId, favourite=True)
- if options[ret] == lang(30406):
+ elif selected == lang(30406):
+ # Delete favourite
emby.updateUserRating(itemId, favourite=False)
- if options[ret] == lang(30407):
+ elif selected == lang(30407):
+ # Update song rating
kodiconn = kodiSQL('music')
kodicursor = kodiconn.cursor()
- query = ' '.join(("SELECT rating", "FROM song", "WHERE idSong = ?" ))
- kodicursor.execute(query, (itemid,))
- currentvalue = int(round(float(kodicursor.fetchone()[0]),0))
- newvalue = xbmcgui.Dialog().numeric(0, "Set custom song rating (0-5)", str(currentvalue))
- if newvalue:
- newvalue = int(newvalue)
- if newvalue > 5: newvalue = "5"
- if settings('enableUpdateSongRating') == "true":
- musicutils.updateRatingToFile(newvalue, API.getFilePath())
- if settings('enableExportSongRating') == "true":
- like, favourite, deletelike = musicutils.getEmbyRatingFromKodiRating(newvalue)
- emby.updateUserRating(itemId, like, favourite, deletelike)
- query = ' '.join(( "UPDATE song","SET rating = ?", "WHERE idSong = ?" ))
- kodicursor.execute(query, (newvalue,itemid,))
- kodiconn.commit()
+ query = "SELECT rating FROM song WHERE idSong = ?"
+ kodicursor.execute(query, (kodiId,))
+ try:
+ value = kodicursor.fetchone()[0]
+ current_value = int(round(float(value),0))
+ except TypeError:
+ pass
+ else:
+ new_value = dialog.numeric(0, lang(30411), str(current_value))
+ if new_value > -1:
+
+ new_value = int(new_value)
+ if new_value > 5:
+ new_value = 5
- if options[ret] == lang(30408):
- #Open addon settings
+ if settings('enableUpdateSongRating') == "true":
+ musicutils.updateRatingToFile(new_value, API.getFilePath())
+
+ query = "UPDATE song SET rating = ? WHERE idSong = ?"
+ kodicursor.execute(query, (new_value, kodiId,))
+ kodiconn.commit()
+
+ '''if settings('enableExportSongRating') == "true":
+ like, favourite, deletelike = musicutils.getEmbyRatingFromKodiRating(new_value)
+ emby.updateUserRating(itemId, like, favourite, deletelike)'''
+ finally:
+ kodicursor.close()
+
+ elif selected == lang(30408):
+ # Open addon settings
xbmc.executebuiltin("Addon.OpenSettings(plugin.video.emby)")
- if options[ret] == lang(30409):
- #delete item from the server
+ elif selected == lang(30409):
+ # delete item from the server
delete = True
if settings('skipContextMenu') != "true":
- resp = xbmcgui.Dialog().yesno(
- heading="Confirm delete",
- line1=("Delete file from Emby Server? This will "
- "also delete the file(s) from disk!"))
+ resp = dialog.yesno(
+ heading=lang(29999),
+ line1=lang(33041))
if not resp:
log("User skipped deletion for: %s." % itemId, 1)
delete = False
if delete:
- import downloadutils
- doUtils = downloadutils.DownloadUtils()
- url = "{server}/emby/Items/%s?format=json" % itemId
- log("Deleting request: %s" % embyid, 0)
- doUtils.downloadUrl(url, action_type="DELETE")
-
- '''if settings('skipContextMenu') != "true":
- if xbmcgui.Dialog().yesno(
- heading="Confirm delete",
- line1=("Delete file on Emby Server? This will "
- "also delete the file(s) from disk!")):
- import downloadutils
- doUtils = downloadutils.DownloadUtils()
- doUtils.downloadUrl("{server}/emby/Items/%s?format=json" % embyid, action_type="DELETE")'''
+ log("Deleting request: %s" % itemId, 0)
+ emby.deleteItem(itemId)
xbmc.sleep(500)
xbmc.executebuiltin('Container.Update')
\ No newline at end of file
diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml
index 1655957a..9c6d4ad2 100644
--- a/resources/language/English/strings.xml
+++ b/resources/language/English/strings.xml
@@ -258,15 +258,13 @@
Emby options
- Clear like for this item
- Like this item
- Dislike this item
Add to Emby favorites
Remove from Emby favorites
Set custom song rating
Emby addon settings
Delete item from the server
Refresh this item
+ Set custom song rating (0-5)
Primary Server Address
@@ -358,5 +356,6 @@
Add network credentials to allow Kodi access to your content? Important: Kodi will need to be restarted to see the credentials. They can also be added at a later time.
Disable Emby music library?
Direct stream the music library? Select this option if the music library will be remotely accessed.
+ Delete file(s) from Emby Server? This will also delete the file(s) from disk!
diff --git a/resources/lib/musicutils.py b/resources/lib/musicutils.py
index dd44e830..66da24a1 100644
--- a/resources/lib/musicutils.py
+++ b/resources/lib/musicutils.py
@@ -15,11 +15,11 @@ import base64
import read_embyserver as embyserver
from utils import Logging, window
+log = Logging('MusicTools').log
#################################################################################################
# Helper for the music library, intended to fix missing song ID3 tags on Emby
-log = Logging('MusicTools').log
def getRealFileName(filename, isTemp=False):
#get the filename path accessible by python if possible...
diff --git a/resources/lib/read_embyserver.py b/resources/lib/read_embyserver.py
index bc51b5ca..5e62425e 100644
--- a/resources/lib/read_embyserver.py
+++ b/resources/lib/read_embyserver.py
@@ -539,32 +539,20 @@ class Read_EmbyServer():
return sorted_items
- def updateUserRating(self, itemid, like=None, favourite=None, deletelike=False):
+ def updateUserRating(self, itemid, favourite=None):
# Updates the user rating to Emby
doUtils = self.doUtils
if favourite:
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
doUtils(url, action_type="POST")
- elif favourite == False:
+ elif not favourite:
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
doUtils(url, action_type="DELETE")
-
- if not deletelike and like:
- url = "{server}/emby/Users/{UserId}/Items/%s/Rating?Likes=true&format=json" % itemid
- doUtils(url, action_type="POST")
- elif not deletelike and like is False:
- url = "{server}/emby/Users/{UserId}/Items/%s/Rating?Likes=false&format=json" % itemid
- doUtils(url, action_type="POST")
- elif deletelike:
- url = "{server}/emby/Users/{UserId}/Items/%s/Rating?format=json" % itemid
- doUtils(url, action_type="DELETE")
else:
log("Error processing user rating.", 1)
- log("Update user rating to emby for itemid: %s "
- "| like: %s | favourite: %s | deletelike: %s"
- % (itemid, like, favourite, deletelike), 1)
+ log("Update user rating to emby for itemid: %s | favourite: %s" % (itemid, favourite), 1)
def refreshItem(self, itemid):
@@ -578,4 +566,9 @@ class Read_EmbyServer():
'ReplaceAllMetadata': True
}
- self.doUtils(url, postBody=params, action_type="POST")
\ No newline at end of file
+ self.doUtils(url, postBody=params, action_type="POST")
+
+ def deleteItem(self, itemid):
+
+ url = "{server}/emby/Items/%s?format=json" % itemId
+ self.doUtils(url, action_type="DELETE")
\ No newline at end of file