mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
changed checksum to use both userdata and etag to detect changes
added favotite shows and movies tags
This commit is contained in:
parent
812e3090a5
commit
91a73128b1
2 changed files with 41 additions and 88 deletions
|
@ -123,13 +123,12 @@ class API():
|
||||||
}
|
}
|
||||||
|
|
||||||
def getChecksum(self, item):
|
def getChecksum(self, item):
|
||||||
# use the etags or serverside checksum for this if available
|
# use the etags checksum for this if available
|
||||||
# else just add some fields to a string
|
# AND the userdata
|
||||||
checksum = ""
|
checksum = ""
|
||||||
|
|
||||||
if item.get("Etag") != None:
|
if item.get("Etag") != None:
|
||||||
checksum = item.get("Etag")
|
checksum = item.get("Etag")
|
||||||
else:
|
|
||||||
userData = item.get("UserData")
|
userData = item.get("UserData")
|
||||||
if(userData != None):
|
if(userData != None):
|
||||||
checksum += str(userData.get("Played"))
|
checksum += str(userData.get("Played"))
|
||||||
|
@ -152,9 +151,9 @@ class API():
|
||||||
else:
|
else:
|
||||||
watched="False"
|
watched="False"
|
||||||
if userData.get("IsFavorite") == True:
|
if userData.get("IsFavorite") == True:
|
||||||
favorite="True"
|
favorite=True
|
||||||
else:
|
else:
|
||||||
favorite="False"
|
favorite=False
|
||||||
if(userData.get("Played") == True):
|
if(userData.get("Played") == True):
|
||||||
playcount="1"
|
playcount="1"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -194,6 +194,12 @@ class WriteKodiDB():
|
||||||
#add streamdetails
|
#add streamdetails
|
||||||
self.AddStreamDetailsToMedia(API().getMediaStreams(MBitem), fileid, cursor)
|
self.AddStreamDetailsToMedia(API().getMediaStreams(MBitem), fileid, cursor)
|
||||||
|
|
||||||
|
#add to favorites tag --> todo translated label for favorites ?
|
||||||
|
if userData.get("Favorite"):
|
||||||
|
self.AddTagToMedia(movieid, "Favorite movies", "movie", cursor)
|
||||||
|
else:
|
||||||
|
self.AddTagToMedia(movieid, "Favorite movies", "movie", cursor, True)
|
||||||
|
|
||||||
#set resume point
|
#set resume point
|
||||||
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
||||||
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
||||||
|
@ -444,6 +450,12 @@ class WriteKodiDB():
|
||||||
#update studios
|
#update studios
|
||||||
self.AddStudiosToMedia(showid, studios, "tvshow", cursor)
|
self.AddStudiosToMedia(showid, studios, "tvshow", cursor)
|
||||||
|
|
||||||
|
#add to favorites tag --> todo translated label for favorites ?
|
||||||
|
if userData.get("Favorite"):
|
||||||
|
self.AddTagToMedia(showid, "Favorite tvshows", "tvshow", cursor)
|
||||||
|
else:
|
||||||
|
self.AddTagToMedia(showid, "Favorite tvshows", "tvshow", cursor, True)
|
||||||
|
|
||||||
#update artwork
|
#update artwork
|
||||||
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), showid, "tvshow", "thumb", cursor)
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), showid, "tvshow", "thumb", cursor)
|
||||||
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), showid, "tvshow", "poster", cursor)
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), showid, "tvshow", "poster", cursor)
|
||||||
|
@ -457,72 +469,6 @@ class WriteKodiDB():
|
||||||
#update season details
|
#update season details
|
||||||
self.updateSeasons(MBitem["Id"], showid, connection, cursor)
|
self.updateSeasons(MBitem["Id"], showid, connection, cursor)
|
||||||
|
|
||||||
|
|
||||||
def addMusicVideoToKodiLibrary( self, MBitem, connection, cursor ):
|
|
||||||
|
|
||||||
#adds a musicvideo to Kodi by directly inserting it to connectionthe DB while there is no addMusicVideo available on the json API
|
|
||||||
#TODO: PR at Kodi team for a addMusicVideo endpoint on their API
|
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
|
||||||
port = addon.getSetting('port')
|
|
||||||
host = addon.getSetting('ipaddress')
|
|
||||||
server = host + ":" + port
|
|
||||||
|
|
||||||
timeInfo = API().getTimeInfo(MBitem)
|
|
||||||
userData=API().getUserData(MBitem)
|
|
||||||
|
|
||||||
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
|
||||||
playurl = utils.convertEncoding(playurl)
|
|
||||||
|
|
||||||
if MBitem.get("DateCreated") != None:
|
|
||||||
dateadded = MBitem["DateCreated"].replace("T"," ")
|
|
||||||
dateadded = dateadded.replace(".0000000Z","")
|
|
||||||
else:
|
|
||||||
dateadded = None
|
|
||||||
|
|
||||||
path = "plugin://plugin.video.emby/musicvideos/"
|
|
||||||
filename = "plugin://plugin.video.emby/musicvideos/?mode=play&id=" + MBitem["Id"]
|
|
||||||
|
|
||||||
#create the path
|
|
||||||
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
|
|
||||||
result = cursor.fetchone()
|
|
||||||
if result != None:
|
|
||||||
pathid = result[0]
|
|
||||||
else:
|
|
||||||
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
|
|
||||||
pathid = cursor.fetchone()[0]
|
|
||||||
pathid = pathid + 1
|
|
||||||
pathsql = "insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
||||||
cursor.execute(pathsql, (pathid,path,"movies","metadata.local",1))
|
|
||||||
|
|
||||||
playcount = None
|
|
||||||
if userData.get("PlayCount") == "1":
|
|
||||||
playcount = 1
|
|
||||||
|
|
||||||
#create the file if not exists
|
|
||||||
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ?",(filename,))
|
|
||||||
result = cursor.fetchone()
|
|
||||||
if result != None:
|
|
||||||
fileid = result[0]
|
|
||||||
if result == None:
|
|
||||||
cursor.execute("select coalesce(max(idFile),0) as fileid from files")
|
|
||||||
fileid = cursor.fetchone()[0]
|
|
||||||
fileid = fileid + 1
|
|
||||||
pathsql="insert into files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
|
|
||||||
cursor.execute(pathsql, (fileid,pathid,filename,playcount,userData.get("LastPlayedDate"),dateadded))
|
|
||||||
|
|
||||||
runtime = int(timeInfo.get('Duration'))*60
|
|
||||||
plot = utils.convertEncoding(API().getOverview(MBitem))
|
|
||||||
title = utils.convertEncoding(MBitem["Name"])
|
|
||||||
|
|
||||||
#create the musicvideo
|
|
||||||
cursor.execute("select coalesce(max(idMVideo),0) as musicvideoid from musicvideo")
|
|
||||||
musicvideoid = cursor.fetchone()[0]
|
|
||||||
musicvideoid = musicvideoid + 1
|
|
||||||
pathsql="insert into musicvideo(idMVideo, idFile, c00, c04, c08, c23) values(?, ?, ?, ?, ?, ?)"
|
|
||||||
cursor.execute(pathsql, (musicvideoid, fileid, title, runtime, plot, MBitem["Id"]))
|
|
||||||
|
|
||||||
|
|
||||||
def addOrUpdateEpisodeToKodiLibrary(self, embyId, showid, connection, cursor):
|
def addOrUpdateEpisodeToKodiLibrary(self, embyId, showid, connection, cursor):
|
||||||
|
|
||||||
# If the episode already exist in the local Kodi DB we'll perform a full item update
|
# If the episode already exist in the local Kodi DB we'll perform a full item update
|
||||||
|
@ -939,7 +885,7 @@ class WriteKodiDB():
|
||||||
sql="INSERT OR REPLACE into studiolinkepisode(idstudio, idEpisode) values(?, ?)"
|
sql="INSERT OR REPLACE into studiolinkepisode(idstudio, idEpisode) values(?, ?)"
|
||||||
cursor.execute(sql, (idstudio,id))
|
cursor.execute(sql, (idstudio,id))
|
||||||
|
|
||||||
def AddTagToMedia(self, id, tag, mediatype, cursor):
|
def AddTagToMedia(self, id, tag, mediatype, cursor, doRemove=False):
|
||||||
|
|
||||||
if tag:
|
if tag:
|
||||||
|
|
||||||
|
@ -963,6 +909,10 @@ class WriteKodiDB():
|
||||||
utils.logMsg("AddTagToMedia", "Adding tag: " + tag)
|
utils.logMsg("AddTagToMedia", "Adding tag: " + tag)
|
||||||
|
|
||||||
#assign tag to item
|
#assign tag to item
|
||||||
|
if doRemove:
|
||||||
|
sql="DELETE FROM tag_link WHERE media_id = ? AND media_type = ? AND tag_id = ?"
|
||||||
|
cursor.execute(sql, (id, mediatype, tag_id))
|
||||||
|
else:
|
||||||
sql="INSERT OR REPLACE into tag_link(tag_id, media_id, media_type) values(?, ?, ?)"
|
sql="INSERT OR REPLACE into tag_link(tag_id, media_id, media_type) values(?, ?, ?)"
|
||||||
cursor.execute(sql, (tag_id, id, mediatype))
|
cursor.execute(sql, (tag_id, id, mediatype))
|
||||||
|
|
||||||
|
@ -981,6 +931,10 @@ class WriteKodiDB():
|
||||||
cursor.execute(sql, (idTag,tag))
|
cursor.execute(sql, (idTag,tag))
|
||||||
|
|
||||||
#assign tag to item
|
#assign tag to item
|
||||||
|
if doRemove:
|
||||||
|
sql="DELETE FROM taglinks WHERE idMedia = ? AND media_type = ? AND idTag = ?"
|
||||||
|
cursor.execute(sql, (id, mediatype, idTag))
|
||||||
|
else:
|
||||||
sql="INSERT OR REPLACE into taglinks(idTag, idMedia, media_type) values(?, ?, ?)"
|
sql="INSERT OR REPLACE into taglinks(idTag, idMedia, media_type) values(?, ?, ?)"
|
||||||
cursor.execute(sql, (idTag, id, mediatype))
|
cursor.execute(sql, (idTag, id, mediatype))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue