Checksum for season

This commit is contained in:
tomkat83 2016-01-11 17:37:01 +01:00
parent 3b2176574a
commit 5e8fd41938
3 changed files with 73 additions and 31 deletions

View file

@ -1378,7 +1378,7 @@ class API():
DATEFORMAT = xbmc.getRegion('dateshort')
TIMEFORMAT = xbmc.getRegion('meridiem')
date_time = time.localtime(float(stamp))
localdate = time.strftime('%Y-%m-%d', date_time)
localdate = time.strftime('%Y-%m-%dT%H:%M:%SZ', date_time)
return localdate
def getType(self):

View file

@ -20,6 +20,7 @@ import kodidb_functions as kodidb
import read_embyserver as embyserver
import PlexAPI
import sys
##################################################################################################
@ -1345,14 +1346,30 @@ class TVShows(Items):
artwork = self.artwork
seasonnum = API.getIndex()
seasonid = kodi_db.addSeason(showid, seasonnum)
# Create the reference in emby table
emby_db.addReference(itemid, seasonid, "Season", "season", parentid=showid)
checksum = API.getChecksum()
# Check whether Season already exists
update_item = True
emby_dbitem = emby_db.getItem_byId(itemid)
try:
embyDbItemId = emby_dbitem[0]
self.logMsg("Updating Season: %s" % itemid, 2)
except TypeError:
update_item = False
self.logMsg("Season: %s not found." % itemid, 2)
# Process artwork
allartworks = API.getAllArtwork()
artwork.addArtwork(allartworks, seasonid, "season", kodicursor)
self.logMsg("Updated season %s, Plex Id: %s of Plex show Id: %s" % (
seasonnum, itemid, showid), 2)
if update_item:
# Update a reference: checksum in emby table
emby_db.updateReference(itemid, checksum)
else:
# Create the reference in emby table
emby_db.addReference(itemid, seasonid, "Season", "season", parentid=showid, checksum=checksum)
def add_updateEpisode(self, item, viewtag=None, viewid=None):
"""
viewtag and viewid are irrelevant!

View file

@ -247,10 +247,55 @@ class LibrarySync(threading.Thread):
return dialog
def startSync(self):
# Always do a fullSync. It will be faster automatically.
completed = self.fullSync(manualrun=True)
# Run at start up - optional to use the server plugin
if utils.settings('SyncInstallRunDone') == "true":
# Validate views
self.maintainViews()
completed = False
completed = self.fastSync()
if not completed:
# Fast sync failed or server plugin is not found
completed = self.fullSync(manualrun=True)
else:
# Install sync is not completed
completed = self.fullSync()
return completed
def fastSync(self):
lastSync = utils.settings('LastIncrementalSync')
if not lastSync:
lastSync = "2010-01-01T00:00:00Z"
self.logMsg("Last sync run: %s" % lastSync, 1)
url = "{server}/emby/Emby.Kodi.SyncQueue/{UserId}/GetItems?format=json"
params = {'LastUpdateDT': lastSync}
result = self.doUtils.downloadUrl(url, parameters=params)
try:
processlist = {
'added': result['ItemsAdded'],
'update': result['ItemsUpdated'],
'userdata': result['UserDataChanged'],
'remove': result['ItemsRemoved']
}
except (KeyError, TypeError):
self.logMsg("Failed to retrieve latest updates using fast sync.", 1)
return False
else:
self.logMsg("Fast sync changes: %s" % result, 1)
for action in processlist:
self.triage_items(action, processlist[action])
return True
def saveLastSync(self):
# Save last sync time
overlap = 2
@ -284,27 +329,6 @@ class LibrarySync(threading.Thread):
else: # Keep going
return False
def dbCommit(self, connection):
# Central commit, verifies if Kodi database update is running
kodidb_scan = utils.window('emby_kodiScan') == "true"
while kodidb_scan:
self.logMsg("Kodi scan is running. Waiting...", 1)
kodidb_scan = utils.window('emby_kodiScan') == "true"
if self.shouldStop():
self.logMsg("Commit unsuccessful. Sync terminated.", 1)
break
if self.monitor.waitForAbort(1):
# Abort was requested while waiting. We should exit
self.logMsg("Commit unsuccessful.", 1)
break
else:
connection.commit()
self.logMsg("Commit successful.", 1)
def initializeDBs(self):
"""
Run once during startup to verify that emby db exists.
@ -423,11 +447,6 @@ class LibrarySync(threading.Thread):
def maintainViews(self):
"""
Compare the views to Plex
Output:
vnodes.viewNode(totalnodes, foldername, mediatype, viewtype)
kodi_db.createTag(foldername)
kodi_db.updateTag(current_tagid, tagid, item[0],Current_viewtype[:-1])
"""
# Open DB links
embyconn = utils.kodiSQL('emby')
@ -962,6 +981,12 @@ class LibrarySync(threading.Thread):
self.allKodiElementsId.update(all_koditvshows)
except ValueError:
pass
# Same for seasons
try:
all_kodiseasons = dict(emby_db.getChecksum('Season'))
self.allKodiElementsId.update(all_kodiseasons)
except ValueError:
pass
# Same for the episodes (sub-element of shows/series)
try:
all_kodiepisodes = dict(emby_db.getChecksum('Episode'))