mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +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()
|
connectionvideo = utils.KodiSQL()
|
||||||
cursorvideo = connectionvideo.cursor()
|
cursorvideo = connectionvideo.cursor()
|
||||||
# Database connection to myMusicXX.db
|
# Database connection to myMusicXX.db
|
||||||
#connectionmusic = utils.KodiSQL('music')
|
connectionmusic = utils.KodiSQL('music')
|
||||||
#cursormusic = connectionmusic.cursor()
|
cursormusic = connectionmusic.cursor()
|
||||||
|
|
||||||
count = 1
|
count = 1
|
||||||
total = len(listItems) + 1
|
total = len(listItems) + 1
|
||||||
for userdata in listItems:
|
for userdata in listItems:
|
||||||
|
# Sort between video and music
|
||||||
itemId = userdata['ItemId']
|
itemId = userdata['ItemId']
|
||||||
|
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
|
@ -889,13 +890,12 @@ class LibrarySync(threading.Thread):
|
||||||
mediatype = cursorvideo.fetchone()[0]
|
mediatype = cursorvideo.fetchone()[0]
|
||||||
video.append(userdata)
|
video.append(userdata)
|
||||||
except:
|
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
|
try: # Search music database
|
||||||
self.logMsg("Check the music database.", 1)
|
self.logMsg("Check the music database.", 1)
|
||||||
mediatype = cursormusic.fetchone()[0]
|
mediatype = cursormusic.fetchone()[0]
|
||||||
music.append(userdata)
|
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:
|
if len(video) > 0:
|
||||||
connection = connectionvideo
|
connection = connectionvideo
|
||||||
|
@ -916,20 +916,27 @@ class LibrarySync(threading.Thread):
|
||||||
# Close connection
|
# Close connection
|
||||||
cursorvideo.close()
|
cursorvideo.close()
|
||||||
|
|
||||||
'''if len(music) > 0:
|
if len(music) > 0:
|
||||||
connection = connectionmusic
|
connection = connectionmusic
|
||||||
cursor = cursormusic
|
cursor = cursormusic
|
||||||
#Process music library
|
#Process music library
|
||||||
|
count = 1
|
||||||
|
total = len(video) + 1
|
||||||
musicenabled = utils.settings('enableMusicSync') == "true"
|
musicenabled = utils.settings('enableMusicSync') == "true"
|
||||||
# Process the userdata update for music library
|
# Process the userdata update for music library
|
||||||
if musicenabled:
|
if musicenabled:
|
||||||
for userdata in music:
|
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)
|
WriteKodiMusicDB().updateUserdata(userdata, connection, cursor)
|
||||||
|
|
||||||
connection.commit()
|
connection.commit()
|
||||||
xbmc.executebuiltin("UpdateLibrary(music)")'''
|
#xbmc.executebuiltin("UpdateLibrary(music)")
|
||||||
# Close connection
|
# Close connection
|
||||||
#cursormusic.close()
|
cursormusic.close()
|
||||||
|
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
pDialog.close()
|
pDialog.close()
|
||||||
|
|
|
@ -446,3 +446,37 @@ class WriteKodiMusicDB():
|
||||||
elif "song" in mediatype:
|
elif "song" in mediatype:
|
||||||
query = "INSERT OR REPLACE INTO song_genre(idGenre, idSong) values(?, ?)"
|
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