mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
added individual playcount update
This commit is contained in:
parent
40b3231156
commit
27b21f214e
3 changed files with 89 additions and 1 deletions
|
@ -622,6 +622,75 @@ class LibrarySync():
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def updatePlayCount(self,itemID,type):
|
||||||
|
#update playcount of the itemID from MB3 to Kodi library
|
||||||
|
|
||||||
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
WINDOW = xbmcgui.Window( 10000 )
|
||||||
|
#process movie
|
||||||
|
if type=='Movie':
|
||||||
|
MB3Movie = ReadEmbyDB().getItem(itemID)
|
||||||
|
allKodiMovies = ReadKodiDB().getKodiMovies(False)
|
||||||
|
|
||||||
|
if(self.ShouldStop()):
|
||||||
|
return True
|
||||||
|
|
||||||
|
if(MB3Movie == None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if(allKodiMovies == None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
kodiItem = None
|
||||||
|
for kodimovie in allKodiMovies:
|
||||||
|
if itemID in kodimovie["file"]:
|
||||||
|
kodiItem = kodimovie
|
||||||
|
break
|
||||||
|
|
||||||
|
userData=API().getUserData(MB3Movie)
|
||||||
|
timeInfo = API().getTimeInfo(MB3Movie)
|
||||||
|
if kodiItem != None:
|
||||||
|
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie")
|
||||||
|
kodiresume = int(round(kodiItem['resume'].get("position")))
|
||||||
|
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
||||||
|
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
||||||
|
if kodiresume != resume:
|
||||||
|
WriteKodiDB().setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
|
||||||
|
|
||||||
|
if(self.ShouldStop()):
|
||||||
|
return True
|
||||||
|
|
||||||
|
#process episode
|
||||||
|
elif type=='Episode':
|
||||||
|
if(self.ShouldStop()):
|
||||||
|
return True
|
||||||
|
|
||||||
|
MB3Episode = ReadEmbyDB().getItem(itemID)
|
||||||
|
kodiEpisodes = ReadKodiDB().getKodiEpisodes(MB3Episode.get("SeriesId"),False)
|
||||||
|
if (MB3Episode != None):
|
||||||
|
kodiItem = None
|
||||||
|
comparestring1 = str(MB3Episode.get("ParentIndexNumber")) + "-" + str(MB3Episode.get("IndexNumber"))
|
||||||
|
matchFound = False
|
||||||
|
if kodiEpisodes != None:
|
||||||
|
xbmc.log("episode playcount kodiepisodes found")
|
||||||
|
kodiItem = kodiEpisodes.get(comparestring1, None)
|
||||||
|
|
||||||
|
userData=API().getUserData(MB3Episode)
|
||||||
|
timeInfo = API().getTimeInfo(MB3Episode)
|
||||||
|
if kodiItem != None:
|
||||||
|
if kodiItem['playcount'] != int(userData.get("PlayCount")):
|
||||||
|
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode")
|
||||||
|
kodiresume = int(round(kodiItem['resume'].get("position")))
|
||||||
|
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
||||||
|
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
||||||
|
if kodiresume != resume:
|
||||||
|
WriteKodiDB().setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode")
|
||||||
|
|
||||||
|
if(self.ShouldStop()):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def ShouldStop(self):
|
def ShouldStop(self):
|
||||||
if(xbmc.Player().isPlaying() or xbmc.abortRequested):
|
if(xbmc.Player().isPlaying() or xbmc.abortRequested):
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -88,10 +88,12 @@ class Player( xbmc.Player ):
|
||||||
item_id = data.get("item_id")
|
item_id = data.get("item_id")
|
||||||
refresh_id = data.get("refresh_id")
|
refresh_id = data.get("refresh_id")
|
||||||
currentFile = data.get("currentfile")
|
currentFile = data.get("currentfile")
|
||||||
|
type = data.get("Type")
|
||||||
|
|
||||||
if(refresh_id != None):
|
if(refresh_id != None):
|
||||||
#TODO: trigger update of single item, for now trigger full playcounts update
|
#TODO: trigger update of single item, for now trigger full playcounts update
|
||||||
librarySync.updatePlayCounts()
|
xbmc.log("Invoking refresh of playcounts")
|
||||||
|
librarySync.updatePlayCount(item_id,type)
|
||||||
|
|
||||||
if(currentPosition != None and self.hasData(runtime)):
|
if(currentPosition != None and self.hasData(runtime)):
|
||||||
runtimeTicks = int(runtime)
|
runtimeTicks = int(runtime)
|
||||||
|
|
|
@ -41,6 +41,23 @@ class ReadEmbyDB():
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def getItem(self, id):
|
||||||
|
result = None
|
||||||
|
|
||||||
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
port = addon.getSetting('port')
|
||||||
|
host = addon.getSetting('ipaddress')
|
||||||
|
server = host + ":" + port
|
||||||
|
|
||||||
|
downloadUtils = DownloadUtils()
|
||||||
|
userid = downloadUtils.getUserId()
|
||||||
|
|
||||||
|
jsonData = downloadUtils.downloadUrl("http://" + server + "/mediabrowser/Users/" + userid + "/Items/" + id + "?format=json&ImageTypeLimit=1", suppress=False, popup=1 )
|
||||||
|
if jsonData != None and jsonData != "":
|
||||||
|
result = json.loads(jsonData)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def getTVShows(self, fullinfo = False, fullSync = False):
|
def getTVShows(self, fullinfo = False, fullSync = False):
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue