mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-06-17 05:36:12 +00:00
fix: redundant userdata update for music rating
add settings for music ratings import/export
This commit is contained in:
parent
2d7f8a5a06
commit
ae06548c9d
5 changed files with 142 additions and 106 deletions
|
@ -38,7 +38,7 @@ class Items(object):
|
|||
self.directpath = utils.settings('useDirectPaths') == "1"
|
||||
self.music_enabled = utils.settings('enableMusic') == "true"
|
||||
self.contentmsg = utils.settings('newContent') == "true"
|
||||
|
||||
|
||||
self.artwork = artwork.Artwork()
|
||||
self.emby = embyserver.Read_EmbyServer()
|
||||
self.emby_db = embydb.Embydb_Functions(embycursor)
|
||||
|
@ -1613,6 +1613,9 @@ class Music(Items):
|
|||
Items.__init__(self, embycursor, musiccursor)
|
||||
|
||||
self.directstream = utils.settings('streamMusic') == "true"
|
||||
self.enableimportsongrating = utils.settings('enableImportSongRating') == "true"
|
||||
self.enableexportsongrating = utils.settings('enableExportSongRating') == "true"
|
||||
self.enableupdatesongrating = utils.settings('enableUpdateSongRating') == "true"
|
||||
self.userid = utils.window('emby_currUser')
|
||||
self.server = utils.window('emby_server%s' % self.userid)
|
||||
|
||||
|
@ -1952,9 +1955,9 @@ class Music(Items):
|
|||
#the server doesn't support comment on songs so this will always be empty
|
||||
comment = API.getOverview()
|
||||
|
||||
#if enabled, try to get the rating and comment value from the file itself
|
||||
#if enabled, try to get the rating from file and/or emby
|
||||
if not self.directstream:
|
||||
rating, comment, hasEmbeddedCover = self.getSongTagsFromFile(itemid, rating, API)
|
||||
rating, comment, hasEmbeddedCover = musicutils.getAdditionalSongTags(itemid, rating, API, kodicursor, emby_db, self.enableimportsongrating, self.enableexportsongrating, self.enableupdatesongrating)
|
||||
|
||||
##### GET THE FILE AND PATH #####
|
||||
if self.directstream:
|
||||
|
@ -2191,7 +2194,7 @@ class Music(Items):
|
|||
# Process playstates
|
||||
playcount = userdata['PlayCount']
|
||||
dateplayed = userdata['LastPlayedDate']
|
||||
rating, comment, hasEmbeddedCover = self.getSongTagsFromFile(itemid, rating, API)
|
||||
rating, comment, hasEmbeddedCover = musicutils.getAdditionalSongTags(itemid, rating, API, kodicursor, emby_db, self.enableimportsongrating, self.enableexportsongrating, self.enableupdatesongrating)
|
||||
|
||||
query = "UPDATE song SET iTimesPlayed = ?, lastplayed = ?, rating = ? WHERE idSong = ?"
|
||||
kodicursor.execute(query, (playcount, dateplayed, rating, kodiid))
|
||||
|
@ -2203,89 +2206,6 @@ class Music(Items):
|
|||
|
||||
emby_db.updateReference(itemid, checksum)
|
||||
|
||||
def getSongTagsFromFile(self, embyid, emby_rating, API):
|
||||
|
||||
kodicursor = self.kodicursor
|
||||
|
||||
previous_values = None
|
||||
filename = API.getFilePath()
|
||||
rating = 0
|
||||
emby_rating = int(round(emby_rating, 0))
|
||||
|
||||
#get file rating and comment tag from file itself.
|
||||
#TODO: should we make this an optional setting if it impacts sync speed too much ?
|
||||
file_rating, comment, hasEmbeddedCover = musicutils.getSongTags(filename)
|
||||
|
||||
emby_dbitem = self.emby_db.getItem_byId(embyid)
|
||||
try:
|
||||
kodiid = emby_dbitem[0]
|
||||
except TypeError:
|
||||
# Item is not in database.
|
||||
currentvalue = None
|
||||
else:
|
||||
query = "SELECT rating FROM song WHERE idSong = ?"
|
||||
kodicursor.execute(query, (kodiid,))
|
||||
try:
|
||||
currentvalue = int(round(float(kodicursor.fetchone()[0]),0))
|
||||
except: currentvalue = None
|
||||
|
||||
# Only proceed if we actually have a rating from the file
|
||||
if file_rating is None and currentvalue:
|
||||
return (currentvalue, comment, False)
|
||||
elif file_rating is None and not currentvalue:
|
||||
return (emby_rating, comment, False)
|
||||
|
||||
self.logMsg("getSongTagsFromFile --> embyid: %s - emby_rating: %s - file_rating: %s - current rating in kodidb: %s" %(embyid, emby_rating, file_rating, currentvalue))
|
||||
|
||||
updateFileRating = False
|
||||
updateEmbyRating = False
|
||||
|
||||
if currentvalue != None:
|
||||
# we need to translate the emby values...
|
||||
if emby_rating == 1 and currentvalue == 2:
|
||||
emby_rating = 2
|
||||
if emby_rating == 3 and currentvalue == 4:
|
||||
emby_rating = 4
|
||||
|
||||
if (emby_rating == file_rating) and (file_rating != currentvalue):
|
||||
#the rating has been updated from kodi itself, update change to both emby ands file
|
||||
rating = currentvalue
|
||||
updateFileRating = True
|
||||
updateEmbyRating = True
|
||||
elif (emby_rating != currentvalue) and (file_rating == currentvalue):
|
||||
#emby rating changed - update the file
|
||||
rating = emby_rating
|
||||
updateFileRating = True
|
||||
elif (file_rating != currentvalue) and (emby_rating == currentvalue):
|
||||
#file rating was updated, sync change to emby
|
||||
rating = file_rating
|
||||
updateEmbyRating = True
|
||||
elif (emby_rating != currentvalue) and (file_rating != currentvalue):
|
||||
#both ratings have changed (corner case) - the highest rating wins...
|
||||
if emby_rating > file_rating:
|
||||
rating = emby_rating
|
||||
updateFileRating = True
|
||||
else:
|
||||
rating = file_rating
|
||||
updateEmbyRating = True
|
||||
else:
|
||||
#nothing has changed, just return the current value
|
||||
rating = currentvalue
|
||||
else:
|
||||
# no rating yet in DB, always prefer file details...
|
||||
rating = file_rating
|
||||
updateEmbyRating = True
|
||||
|
||||
if updateFileRating:
|
||||
musicutils.updateRatingToFile(rating, filename)
|
||||
|
||||
if updateEmbyRating:
|
||||
# sync details to emby server. Translation needed between ID3 rating and emby likes/favourites:
|
||||
like, favourite, deletelike = musicutils.getEmbyRatingFromKodiRating(rating)
|
||||
API.updateUserRating(embyid, like, favourite, deletelike)
|
||||
|
||||
return (rating, comment, hasEmbeddedCover)
|
||||
|
||||
def remove(self, itemid):
|
||||
# Remove kodiid, fileid, pathid, emby reference
|
||||
emby_db = self.emby_db
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue