String & remove like/dislike
To review: music rating since server does not have like/dislike anymore
This commit is contained in:
parent
313899c8e7
commit
0efc37f646
4 changed files with 63 additions and 71 deletions
|
@ -50,7 +50,7 @@ if __name__ == '__main__':
|
||||||
elif xbmc.getCondVisibility("Container.Content(pictures)"):
|
elif xbmc.getCondVisibility("Container.Content(pictures)"):
|
||||||
itemType = "picture"
|
itemType = "picture"
|
||||||
else:
|
else:
|
||||||
log("Itemtype is unknown.")
|
log("ItemType is unknown.")
|
||||||
|
|
||||||
if (not kodiId or kodiId == "-1") and xbmc.getInfoLabel("ListItem.Property(embyid)"):
|
if (not kodiId or kodiId == "-1") and xbmc.getInfoLabel("ListItem.Property(embyid)"):
|
||||||
itemId = xbmc.getInfoLabel("ListItem.Property(embyid)")
|
itemId = xbmc.getInfoLabel("ListItem.Property(embyid)")
|
||||||
|
@ -67,9 +67,11 @@ if __name__ == '__main__':
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
log("Found ItemId: %s/Itemtype: %s" % (itemId, itemType), 1)
|
log("Found ItemId: %s ItemType: %s" % (itemId, itemType), 1)
|
||||||
if itemId:
|
if itemId:
|
||||||
|
|
||||||
|
dialog = xbmcgui.Dialog()
|
||||||
|
|
||||||
emby = embyserver.Read_EmbyServer()
|
emby = embyserver.Read_EmbyServer()
|
||||||
item = emby.getItem(itemId)
|
item = emby.getItem(itemId)
|
||||||
API = api.API(item)
|
API = api.API(item)
|
||||||
|
@ -98,71 +100,69 @@ if __name__ == '__main__':
|
||||||
options.append(lang(30408))
|
options.append(lang(30408))
|
||||||
|
|
||||||
# Display select dialog and process results
|
# 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 selected == lang(30410):
|
||||||
if ret != -1:
|
# Refresh item
|
||||||
if options[ret] == lang(30410):
|
|
||||||
emby.refreshItem(itemId)
|
emby.refreshItem(itemId)
|
||||||
if options[ret] == lang(30402):
|
elif selected == lang(30405):
|
||||||
emby.updateUserRating(itemId, deletelike=True)
|
# Add favourite
|
||||||
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):
|
|
||||||
emby.updateUserRating(itemId, favourite=True)
|
emby.updateUserRating(itemId, favourite=True)
|
||||||
if options[ret] == lang(30406):
|
elif selected == lang(30406):
|
||||||
|
# Delete favourite
|
||||||
emby.updateUserRating(itemId, favourite=False)
|
emby.updateUserRating(itemId, favourite=False)
|
||||||
if options[ret] == lang(30407):
|
elif selected == lang(30407):
|
||||||
|
# Update song rating
|
||||||
kodiconn = kodiSQL('music')
|
kodiconn = kodiSQL('music')
|
||||||
kodicursor = kodiconn.cursor()
|
kodicursor = kodiconn.cursor()
|
||||||
query = ' '.join(("SELECT rating", "FROM song", "WHERE idSong = ?" ))
|
query = "SELECT rating FROM song WHERE idSong = ?"
|
||||||
kodicursor.execute(query, (itemid,))
|
kodicursor.execute(query, (kodiId,))
|
||||||
currentvalue = int(round(float(kodicursor.fetchone()[0]),0))
|
try:
|
||||||
newvalue = xbmcgui.Dialog().numeric(0, "Set custom song rating (0-5)", str(currentvalue))
|
value = kodicursor.fetchone()[0]
|
||||||
if newvalue:
|
current_value = int(round(float(value),0))
|
||||||
newvalue = int(newvalue)
|
except TypeError:
|
||||||
if newvalue > 5: newvalue = "5"
|
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 settings('enableUpdateSongRating') == "true":
|
if settings('enableUpdateSongRating') == "true":
|
||||||
musicutils.updateRatingToFile(newvalue, API.getFilePath())
|
musicutils.updateRatingToFile(new_value, API.getFilePath())
|
||||||
if settings('enableExportSongRating') == "true":
|
|
||||||
like, favourite, deletelike = musicutils.getEmbyRatingFromKodiRating(newvalue)
|
query = "UPDATE song SET rating = ? WHERE idSong = ?"
|
||||||
emby.updateUserRating(itemId, like, favourite, deletelike)
|
kodicursor.execute(query, (new_value, kodiId,))
|
||||||
query = ' '.join(( "UPDATE song","SET rating = ?", "WHERE idSong = ?" ))
|
|
||||||
kodicursor.execute(query, (newvalue,itemid,))
|
|
||||||
kodiconn.commit()
|
kodiconn.commit()
|
||||||
|
|
||||||
if options[ret] == lang(30408):
|
'''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
|
# Open addon settings
|
||||||
xbmc.executebuiltin("Addon.OpenSettings(plugin.video.emby)")
|
xbmc.executebuiltin("Addon.OpenSettings(plugin.video.emby)")
|
||||||
|
|
||||||
if options[ret] == lang(30409):
|
elif selected == lang(30409):
|
||||||
# delete item from the server
|
# delete item from the server
|
||||||
delete = True
|
delete = True
|
||||||
if settings('skipContextMenu') != "true":
|
if settings('skipContextMenu') != "true":
|
||||||
resp = xbmcgui.Dialog().yesno(
|
resp = dialog.yesno(
|
||||||
heading="Confirm delete",
|
heading=lang(29999),
|
||||||
line1=("Delete file from Emby Server? This will "
|
line1=lang(33041))
|
||||||
"also delete the file(s) from disk!"))
|
|
||||||
if not resp:
|
if not resp:
|
||||||
log("User skipped deletion for: %s." % itemId, 1)
|
log("User skipped deletion for: %s." % itemId, 1)
|
||||||
delete = False
|
delete = False
|
||||||
|
|
||||||
if delete:
|
if delete:
|
||||||
import downloadutils
|
log("Deleting request: %s" % itemId, 0)
|
||||||
doUtils = downloadutils.DownloadUtils()
|
emby.deleteItem(itemId)
|
||||||
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")'''
|
|
||||||
|
|
||||||
xbmc.sleep(500)
|
xbmc.sleep(500)
|
||||||
xbmc.executebuiltin('Container.Update')
|
xbmc.executebuiltin('Container.Update')
|
|
@ -258,15 +258,13 @@
|
||||||
|
|
||||||
<!-- contextmenu -->
|
<!-- contextmenu -->
|
||||||
<string id="30401">Emby options</string>
|
<string id="30401">Emby options</string>
|
||||||
<string id="30402">Clear like for this item</string>
|
|
||||||
<string id="30403">Like this item</string>
|
|
||||||
<string id="30404">Dislike this item</string>
|
|
||||||
<string id="30405">Add to Emby favorites</string>
|
<string id="30405">Add to Emby favorites</string>
|
||||||
<string id="30406">Remove from Emby favorites</string>
|
<string id="30406">Remove from Emby favorites</string>
|
||||||
<string id="30407">Set custom song rating</string>
|
<string id="30407">Set custom song rating</string>
|
||||||
<string id="30408">Emby addon settings</string>
|
<string id="30408">Emby addon settings</string>
|
||||||
<string id="30409">Delete item from the server</string>
|
<string id="30409">Delete item from the server</string>
|
||||||
<string id="30410">Refresh this item</string>
|
<string id="30410">Refresh this item</string>
|
||||||
|
<string id="30411">Set custom song rating (0-5)</string>
|
||||||
|
|
||||||
<!-- add-on settings -->
|
<!-- add-on settings -->
|
||||||
<string id="30000">Primary Server Address</string><!-- Verified -->
|
<string id="30000">Primary Server Address</string><!-- Verified -->
|
||||||
|
@ -358,5 +356,6 @@
|
||||||
<string id="33038">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.</string>
|
<string id="33038">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.</string>
|
||||||
<string id="33039">Disable Emby music library?</string>
|
<string id="33039">Disable Emby music library?</string>
|
||||||
<string id="33040">Direct stream the music library? Select this option if the music library will be remotely accessed.</string>
|
<string id="33040">Direct stream the music library? Select this option if the music library will be remotely accessed.</string>
|
||||||
|
<string id="33041">Delete file(s) from Emby Server? This will also delete the file(s) from disk!</string>
|
||||||
|
|
||||||
</strings>
|
</strings>
|
||||||
|
|
|
@ -15,11 +15,11 @@ import base64
|
||||||
|
|
||||||
import read_embyserver as embyserver
|
import read_embyserver as embyserver
|
||||||
from utils import Logging, window
|
from utils import Logging, window
|
||||||
|
log = Logging('MusicTools').log
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
# Helper for the music library, intended to fix missing song ID3 tags on Emby
|
# Helper for the music library, intended to fix missing song ID3 tags on Emby
|
||||||
log = Logging('MusicTools').log
|
|
||||||
|
|
||||||
def getRealFileName(filename, isTemp=False):
|
def getRealFileName(filename, isTemp=False):
|
||||||
#get the filename path accessible by python if possible...
|
#get the filename path accessible by python if possible...
|
||||||
|
|
|
@ -539,32 +539,20 @@ class Read_EmbyServer():
|
||||||
|
|
||||||
return sorted_items
|
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
|
# Updates the user rating to Emby
|
||||||
doUtils = self.doUtils
|
doUtils = self.doUtils
|
||||||
|
|
||||||
if favourite:
|
if favourite:
|
||||||
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
||||||
doUtils(url, action_type="POST")
|
doUtils(url, action_type="POST")
|
||||||
elif favourite == False:
|
elif not favourite:
|
||||||
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
||||||
doUtils(url, action_type="DELETE")
|
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:
|
else:
|
||||||
log("Error processing user rating.", 1)
|
log("Error processing user rating.", 1)
|
||||||
|
|
||||||
log("Update user rating to emby for itemid: %s "
|
log("Update user rating to emby for itemid: %s | favourite: %s" % (itemid, favourite), 1)
|
||||||
"| like: %s | favourite: %s | deletelike: %s"
|
|
||||||
% (itemid, like, favourite, deletelike), 1)
|
|
||||||
|
|
||||||
def refreshItem(self, itemid):
|
def refreshItem(self, itemid):
|
||||||
|
|
||||||
|
@ -579,3 +567,8 @@ class Read_EmbyServer():
|
||||||
|
|
||||||
}
|
}
|
||||||
self.doUtils(url, postBody=params, action_type="POST")
|
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")
|
Loading…
Reference in a new issue