mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-26 02:36:10 +00:00
Add userdata update only for music
Only songs have playcount and lastplayed
This commit is contained in:
parent
f87cdae256
commit
db45faed24
2 changed files with 51 additions and 10 deletions
|
@ -869,12 +869,13 @@ class LibrarySync(threading.Thread):
|
|||
connectionvideo = utils.KodiSQL()
|
||||
cursorvideo = connectionvideo.cursor()
|
||||
# Database connection to myMusicXX.db
|
||||
#connectionmusic = utils.KodiSQL('music')
|
||||
#cursormusic = connectionmusic.cursor()
|
||||
connectionmusic = utils.KodiSQL('music')
|
||||
cursormusic = connectionmusic.cursor()
|
||||
|
||||
count = 1
|
||||
total = len(listItems) + 1
|
||||
for userdata in listItems:
|
||||
# Sort between video and music
|
||||
itemId = userdata['ItemId']
|
||||
|
||||
if(pDialog != None):
|
||||
|
@ -889,13 +890,12 @@ class LibrarySync(threading.Thread):
|
|||
mediatype = cursorvideo.fetchone()[0]
|
||||
video.append(userdata)
|
||||
except:
|
||||
self.logMsg("Item %s is not found in Kodi database." % itemId, 2)
|
||||
'''cursormusic.execute("SELECT media_type FROM emby WHERE emby_id = ?", (itemId,))
|
||||
cursormusic.execute("SELECT media_type FROM emby WHERE emby_id = ?", (itemId,))
|
||||
try: # Search music database
|
||||
self.logMsg("Check the music database.", 1)
|
||||
mediatype = cursormusic.fetchone()[0]
|
||||
music.append(userdata)
|
||||
except: self.logMsg("Item %s is not found in Kodi database." % itemId, 2)'''
|
||||
except: self.logMsg("Item %s is not found in Kodi database." % itemId, 2)
|
||||
|
||||
if len(video) > 0:
|
||||
connection = connectionvideo
|
||||
|
@ -908,7 +908,7 @@ class LibrarySync(threading.Thread):
|
|||
progressTitle = "Incremental Sync "+ " (" + str(count) + " of " + str(total) + ")"
|
||||
percentage = int(((float(count) / float(total)) * 100))
|
||||
pDialog.update(percentage, "Emby for Kodi - Incremental Sync User Data ", progressTitle)
|
||||
count = count + 1
|
||||
count = count + 1
|
||||
WriteKodiVideoDB().updateUserdata(userdata, connection, cursor)
|
||||
|
||||
connection.commit()
|
||||
|
@ -916,20 +916,27 @@ class LibrarySync(threading.Thread):
|
|||
# Close connection
|
||||
cursorvideo.close()
|
||||
|
||||
'''if len(music) > 0:
|
||||
if len(music) > 0:
|
||||
connection = connectionmusic
|
||||
cursor = cursormusic
|
||||
#Process music library
|
||||
count = 1
|
||||
total = len(video) + 1
|
||||
musicenabled = utils.settings('enableMusicSync') == "true"
|
||||
# Process the userdata update for music library
|
||||
if musicenabled:
|
||||
for userdata in music:
|
||||
if(pDialog != None):
|
||||
progressTitle = "Incremental Sync "+ " (" + str(count) + " of " + str(total) + ")"
|
||||
percentage = int(((float(count) / float(total)) * 100))
|
||||
pDialog.update(percentage, "Emby for Kodi - Incremental Sync User Data ", progressTitle)
|
||||
count = count + 1
|
||||
WriteKodiMusicDB().updateUserdata(userdata, connection, cursor)
|
||||
|
||||
connection.commit()
|
||||
xbmc.executebuiltin("UpdateLibrary(music)")'''
|
||||
#xbmc.executebuiltin("UpdateLibrary(music)")
|
||||
# Close connection
|
||||
#cursormusic.close()
|
||||
cursormusic.close()
|
||||
|
||||
if(pDialog != None):
|
||||
pDialog.close()
|
||||
|
|
|
@ -445,4 +445,38 @@ class WriteKodiMusicDB():
|
|||
cursor.execute(query, (idGenre, id))
|
||||
elif "song" in mediatype:
|
||||
query = "INSERT OR REPLACE INTO song_genre(idGenre, idSong) values(?, ?)"
|
||||
cursor.execute(query, (idGenre, id))
|
||||
cursor.execute(query, (idGenre, id))
|
||||
|
||||
def updateUserdata(self, userdata, connection, cursor):
|
||||
# This updates: LastPlayedDate, Playcount
|
||||
embyId = userdata['ItemId']
|
||||
MBitem = ReadEmbyDB().getItem(embyId)
|
||||
|
||||
if not MBitem:
|
||||
self.logMsg("UPDATE userdata to Kodi library FAILED, Item %s not found on server!" % embyId, 1)
|
||||
return
|
||||
|
||||
# Get details
|
||||
checksum = API().getChecksum(MBitem)
|
||||
userdata = API().getUserData(MBitem)
|
||||
|
||||
# Find the Kodi Id
|
||||
cursor.execute("SELECT kodi_id, media_type FROM emby WHERE emby_id = ?", (embyId,))
|
||||
try:
|
||||
result = cursor.fetchone()
|
||||
kodiid = result[0]
|
||||
mediatype = result[1]
|
||||
self.logMsg("Found embyId: %s in database - kodiId: %s type: %s" % (embyId, kodiid, mediatype), 1)
|
||||
except:
|
||||
self.logMsg("Id: %s not found in the emby database table." % embyId, 1)
|
||||
else:
|
||||
if mediatype in ("song"):
|
||||
playcount = userdata['PlayCount']
|
||||
dateplayed = userdata['LastPlayedDate']
|
||||
|
||||
query = "UPDATE song SET iTimesPlayed = ?, lastplayed = ? WHERE idSong = ?"
|
||||
cursor.execute(query, (playcount, dateplayed, kodiid))
|
||||
|
||||
#update the checksum in emby table
|
||||
query = "UPDATE emby SET checksum = ? WHERE emby_id = ?"
|
||||
cursor.execute(query, (checksum, embyId))
|
Loading…
Reference in a new issue