mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-07-26 16:27:31 +00:00
fixed the plugin path for playback
This commit is contained in:
parent
cf2c5ef701
commit
b4dd9f58bd
5 changed files with 119 additions and 582 deletions
|
@ -51,10 +51,7 @@ class LibrarySync():
|
|||
|
||||
#TEMP --> add new columns
|
||||
try:
|
||||
cursor.execute("alter table movie ADD COLUMN 'embyId' TEXT")
|
||||
cursor.execute("alter table tvshow ADD COLUMN 'embyId' TEXT")
|
||||
cursor.execute("alter table episode ADD COLUMN 'embyId' TEXT")
|
||||
cursor.execute("alter table musicvideo ADD COLUMN 'embyId' TEXT")
|
||||
cursor.execute("CREATE TABLE IF NOT EXISTS emby(emby_id TEXT, kodi_id INTEGER, media_type TEXT, checksum TEXT, parent_id INTEGER)")
|
||||
connection.commit()
|
||||
except: pass
|
||||
|
||||
|
@ -109,8 +106,7 @@ class LibrarySync():
|
|||
allKodiMovieIds.append(item["Id"])
|
||||
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
|
||||
else:
|
||||
# TODO --> compare with eTag
|
||||
if kodiMovie[2] != item["Name"] or item["Id"] in itemList:
|
||||
if kodiMovie[2] != API().getChecksum(item) or item["Id"] in itemList:
|
||||
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
|
||||
|
||||
#### PROCESS DELETES #####
|
||||
|
@ -158,7 +154,7 @@ class LibrarySync():
|
|||
else:
|
||||
kodiId = kodishow[0]
|
||||
# If there are changes to the item, perform a full sync of the item
|
||||
if kodiShow[2] != item["Name"] or item["Id"] in itemList:
|
||||
if kodiShow[2] != API().getChecksum(item) or item["Id"] in itemList:
|
||||
WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
|
||||
|
||||
#### PROCESS EPISODES ######
|
||||
|
@ -203,18 +199,17 @@ class LibrarySync():
|
|||
WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor)
|
||||
else:
|
||||
# If there are changes to the item, perform a full sync of the item
|
||||
if kodiEpisode[2] != item["Name"] or item["Id"] in itemList:
|
||||
if kodiEpisode[2] != API().getChecksum(item) or item["Id"] in itemList:
|
||||
WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor)
|
||||
|
||||
#### EPISODES: PROCESS DELETES #####
|
||||
allEmbyEpisodeIds = set(allEmbyEpisodeIds)
|
||||
print allEmbyEpisodeIds
|
||||
for kodiId in allKodiEpisodeIds:
|
||||
print "kodiId-->" + kodiId
|
||||
if not kodiId in allEmbyEpisodeIds:
|
||||
WINDOW.setProperty(kodiId,"deleted")
|
||||
print "deleting ???-->" + kodiId
|
||||
#WriteKodiDB().deleteEpisodeFromKodiLibrary(kodiId, connection, cursor)
|
||||
|
||||
WriteKodiDB().deleteEpisodeFromKodiLibrary(kodiId, connection, cursor)
|
||||
|
||||
|
||||
def MusicVideosSync(self, fullsync, installFirstRun,connection, cursor):
|
||||
|
@ -328,260 +323,6 @@ class LibrarySync():
|
|||
|
||||
return True
|
||||
|
||||
def updatePlayCounts(self):
|
||||
#update all playcounts from MB3 to Kodi library
|
||||
|
||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||
WINDOW = xbmcgui.Window( 10000 )
|
||||
pDialog = None
|
||||
startedSync = datetime.today()
|
||||
processMovies = True
|
||||
processTvShows = True
|
||||
|
||||
if(WINDOW.getProperty("SyncDatabaseShouldStop") == "true"):
|
||||
utils.logMsg("Sync PlayCount", "Can not start SyncDatabaseShouldStop=True", 0)
|
||||
return True
|
||||
|
||||
if(WINDOW.getProperty("updatePlayCounts_Running") == "true"):
|
||||
utils.logMsg("Sync PlayCount", "updatePlayCounts Already Running", 0)
|
||||
return False
|
||||
|
||||
WINDOW.setProperty("updatePlayCounts_Running", "true")
|
||||
|
||||
try:
|
||||
playCountSyncIndication = addon.getSetting("playCountSyncIndication")
|
||||
playCountSyncFirstRun = addon.getSetting("SyncFirstCountsRunDone")
|
||||
|
||||
if(playCountSyncFirstRun != "true" or playCountSyncIndication == "Dialog Progress"):
|
||||
pDialog = xbmcgui.DialogProgress()
|
||||
elif(playCountSyncIndication == "BG Progress"):
|
||||
pDialog = xbmcgui.DialogProgressBG()
|
||||
|
||||
if(pDialog != None):
|
||||
pDialog.create('Sync PlayCounts', 'Sync PlayCounts')
|
||||
|
||||
totalCountsUpdated = 0
|
||||
totalPositionsUpdated = 0
|
||||
|
||||
#process movies
|
||||
if processMovies:
|
||||
if(pDialog != None):
|
||||
pDialog.update(0, "Processing Movies", "")
|
||||
|
||||
views = ReadEmbyDB().getCollections("movies")
|
||||
viewCount = len(views)
|
||||
viewCurrent = 1
|
||||
for view in views:
|
||||
allMB3Movies = ReadEmbyDB().getMovies(view.get('id'), fullinfo = False, fullSync = True)
|
||||
allKodiMovies = ReadKodiDB().getKodiMovies(False)
|
||||
|
||||
if(self.ShouldStop(pDialog)):
|
||||
return False
|
||||
|
||||
if(allMB3Movies != None and allKodiMovies != None):
|
||||
|
||||
if(pDialog != None):
|
||||
progressTitle = "Sync PlayCounts: Processing " + view.get('title') + " " + str(viewCurrent) + " of " + str(viewCount)
|
||||
pDialog.update(0, progressTitle)
|
||||
totalCount = len(allMB3Movies) + 1
|
||||
count = 1
|
||||
|
||||
for item in allMB3Movies:
|
||||
|
||||
if not item.get('IsFolder'):
|
||||
kodiItem = allKodiMovies.get(item["Id"], None)
|
||||
|
||||
userData = API().getUserData(item)
|
||||
timeInfo = API().getTimeInfo(item)
|
||||
|
||||
if kodiItem != None:
|
||||
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")
|
||||
totalPositionsUpdated += 1
|
||||
updated = WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")), "movie")
|
||||
updated |= WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "movie")
|
||||
if(updated):
|
||||
totalCountsUpdated += 1
|
||||
|
||||
if(self.ShouldStop(pDialog)):
|
||||
return False
|
||||
|
||||
# update progress bar
|
||||
if(pDialog != None):
|
||||
percentage = int(((float(count) / float(totalCount)) * 100))
|
||||
pDialog.update(percentage, progressTitle, "Updating Movie: " + str(count))
|
||||
count += 1
|
||||
|
||||
viewCurrent += 1
|
||||
|
||||
#process Tv shows
|
||||
if processTvShows:
|
||||
if(pDialog != None):
|
||||
pDialog.update(0, "Processing TV Episodes", "")
|
||||
views = ReadEmbyDB().getCollections("tvshows")
|
||||
viewCount = len(views)
|
||||
viewCurrent = 1
|
||||
progressTitle = ""
|
||||
for view in views:
|
||||
|
||||
tvshowData = ReadEmbyDB().getTVShows(id = view.get('id'), fullinfo = False, fullSync = True)
|
||||
|
||||
if(self.ShouldStop(pDialog)):
|
||||
return False
|
||||
|
||||
if (tvshowData != None):
|
||||
|
||||
showTotal = len(tvshowData)
|
||||
showCurrent = 1
|
||||
|
||||
for item in tvshowData:
|
||||
|
||||
episodeData = ReadEmbyDB().getEpisodes(item["Id"], False)
|
||||
allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
|
||||
kodishow = allKodiTVShows.get(item["Id"],None)
|
||||
if kodishow != None:
|
||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],False,True)
|
||||
else:
|
||||
kodiEpisodes = None
|
||||
|
||||
if (episodeData != None):
|
||||
if(pDialog != None):
|
||||
progressTitle = "Sync PlayCounts: Processing TV Show " + str(showCurrent) + " of " + str(showTotal)
|
||||
pDialog.update(0, progressTitle)
|
||||
totalCount = len(episodeData) + 1
|
||||
count = 1
|
||||
|
||||
for episode in episodeData:
|
||||
|
||||
kodiItem = None
|
||||
matchFound = False
|
||||
if kodiEpisodes != None:
|
||||
kodiItem = kodiEpisodes.get(episode.get("Id"), None)
|
||||
|
||||
userData=API().getUserData(episode)
|
||||
timeInfo = API().getTimeInfo(episode)
|
||||
|
||||
|
||||
if kodiItem != None:
|
||||
WINDOW = xbmcgui.Window( 10000 )
|
||||
WINDOW.setProperty("episodeid" + str(kodiItem['episodeid']), episode.get('Name') + ";;" + episode.get('Id'))
|
||||
WINDOW.setProperty(episode.get('Id'), "episode;;" + str(kodishow["tvshowid"]) + ";;" +str(kodiItem['episodeid']))
|
||||
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")
|
||||
totalPositionsUpdated += 1
|
||||
|
||||
updated = WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode")
|
||||
updated |= WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "episode")
|
||||
if(updated):
|
||||
totalCountsUpdated += 1
|
||||
|
||||
if(self.ShouldStop(pDialog)):
|
||||
return False
|
||||
|
||||
# update progress bar
|
||||
if(pDialog != None):
|
||||
percentage = int(((float(count) / float(totalCount)) * 100))
|
||||
pDialog.update(percentage, progressTitle, "Updating Episode: " + str(count))
|
||||
count += 1
|
||||
|
||||
showCurrent += 1
|
||||
|
||||
if(playCountSyncFirstRun != "true"):
|
||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||
addon.setSetting("SyncFirstCountsRunDone", "true")
|
||||
|
||||
# display notification if set up
|
||||
notificationString = ""
|
||||
if(totalPositionsUpdated > 0):
|
||||
notificationString += "Pos:" + str(totalPositionsUpdated) + " "
|
||||
if(totalCountsUpdated > 0):
|
||||
notificationString += "Counts:" + str(totalCountsUpdated) + " "
|
||||
|
||||
timeTaken = datetime.today() - startedSync
|
||||
timeTakenString = str(int(timeTaken.seconds / 60)) + ":" + str(timeTaken.seconds % 60)
|
||||
utils.logMsg("Sync PlayCount", "Finished " + timeTakenString + " " + notificationString, 0)
|
||||
|
||||
if(playCountSyncIndication == "Notify OnChange" and notificationString != ""):
|
||||
notificationString = "(" + timeTakenString + ") " + notificationString
|
||||
xbmc.executebuiltin("XBMC.Notification(PlayCount Sync: " + notificationString + ",)")
|
||||
elif(playCountSyncIndication == "Notify OnFinish"):
|
||||
if(notificationString == ""):
|
||||
notificationString = "Done"
|
||||
notificationString = "(" + timeTakenString + ") " + notificationString
|
||||
xbmc.executebuiltin("XBMC.Notification(PlayCount Sync: " + notificationString + ",)")
|
||||
|
||||
finally:
|
||||
WINDOW.setProperty("updatePlayCounts_Running", "false")
|
||||
if(pDialog != None):
|
||||
pDialog.close()
|
||||
|
||||
return True
|
||||
|
||||
def updatePlayCount(self, itemID):
|
||||
#update playcount of the itemID from MB3 to Kodi library
|
||||
|
||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||
WINDOW = xbmcgui.Window( 10000 )
|
||||
|
||||
embyItem = ReadEmbyDB().getItem(itemID)
|
||||
if(embyItem == None):
|
||||
return False
|
||||
|
||||
type = embyItem.get("Type")
|
||||
|
||||
#process movie
|
||||
if type == 'Movie':
|
||||
kodiItem = ReadKodiDB().getKodiMovie(itemID)
|
||||
|
||||
if(kodiItem == None):
|
||||
return False
|
||||
|
||||
if(self.ShouldStop(None)):
|
||||
return False
|
||||
|
||||
userData = API().getUserData(embyItem)
|
||||
timeInfo = API().getTimeInfo(embyItem)
|
||||
|
||||
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")
|
||||
#write property forced will refresh the item in the list so playcount change is immediately visible
|
||||
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie",True)
|
||||
WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "movie")
|
||||
|
||||
if(self.ShouldStop(None)):
|
||||
return False
|
||||
|
||||
#process episode
|
||||
elif type == 'Episode':
|
||||
if(self.ShouldStop(None)):
|
||||
return False
|
||||
|
||||
kodiItem = ReadKodiDB().getKodiEpisodeByMbItem(embyItem["Id"], embyItem["SeriesId"])
|
||||
|
||||
userData = API().getUserData(embyItem)
|
||||
timeInfo = API().getTimeInfo(embyItem)
|
||||
|
||||
if kodiItem != None:
|
||||
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")
|
||||
#write property forced will refresh the item in the list so playcount change is immediately visible
|
||||
WriteKodiDB().updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode",True)
|
||||
WriteKodiDB().updateProperty(kodiItem,"lastplayed",userData.get("LastPlayedDate"), "episode")
|
||||
|
||||
return True
|
||||
|
||||
def ShouldStop(self, prog):
|
||||
|
||||
if(prog != None and type(prog) == xbmcgui.DialogProgress):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue