From a0099a69dbe070c2bc4c7d160b3f483cab663ec2 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Thu, 19 Mar 2015 13:43:02 +0100 Subject: [PATCH] fixed the restart message not start sync before settings are changed in the kodi xml files --- resources/lib/Utils.py | 51 +++++++-------- service.py | 137 ++++++++++++++++++++--------------------- 2 files changed, 95 insertions(+), 93 deletions(-) diff --git a/resources/lib/Utils.py b/resources/lib/Utils.py index f4788622..4887fac5 100644 --- a/resources/lib/Utils.py +++ b/resources/lib/Utils.py @@ -55,19 +55,29 @@ def checkKodiSources(): tvLibrary = os.path.join(dataPath,'tvshows') rebootRequired = False + if not xbmcvfs.exists(dataPath + os.sep): xbmcvfs.mkdir(dataPath) if not xbmcvfs.exists(movieLibrary + os.sep): xbmcvfs.mkdir(movieLibrary) - rebootRequired = addKodiSource("mediabrowser_movies",movieLibrary,"movies") + rebootRequired = True + addKodiSource("mediabrowser_movies",movieLibrary,"movies") if not xbmcvfs.exists(tvLibrary + os.sep): xbmcvfs.mkdir(tvLibrary) - rebootRequired = addKodiSource("mediabrowser_tvshows",tvLibrary,"tvshows") - + rebootRequired = True + addKodiSource("mediabrowser_tvshows",tvLibrary,"tvshows") + + rebootRequired = KodiAdvancedSettingsCheck() + if rebootRequired: - ret = xbmcgui.Dialog().yesno(heading="MediaBrowser Sync service", line1="A restart of Kodi is needed to apply changes. After the reboot you need to manually assign the MediaBrowser sources to your library. See documentation. Do you want to reboot now ?") + ret = xbmcgui.Dialog().yesno(heading="Emby Sync service", line1="A restart of Kodi is needed to apply changes.", line2="Synchronisation will not start before the reboot.", line3="Do you want to reboot now ?") if ret: xbmc.executebuiltin("RestartApp") + else: + return False + + return True + def addKodiSource(name, path, type): #add new source to database, common way is to add it directly to the Kodi DB. Fallback to adding it to the sources.xml @@ -116,8 +126,6 @@ def addKodiSource(name, path, type): SubElement(source, "name").text = name SubElement(source, "path").text = path tree.write(sourcesFile) - #return bool that reboot is needed and manual add of path to kodi - return KodiAdvancedSettingsCheck() def KodiAdvancedSettingsCheck(): #setting that kodi should import watched state and resume points from the nfo files @@ -128,6 +136,7 @@ def KodiAdvancedSettingsCheck(): video = SubElement(sources, "videolibrary") ET.ElementTree(sources).write(settingsFile) + writeNeeded = False if xbmcvfs.exists(settingsFile): tree = ET.ElementTree(file=settingsFile) root = tree.getroot() @@ -135,11 +144,18 @@ def KodiAdvancedSettingsCheck(): if video == None: video = SubElement(sources, "videolibrary") # add the settings - SubElement(video, "importwatchedstate").text = "true" - SubElement(video, "importresumepoint").text = "true" - tree.write(settingsFile) - #return bool that reboot is needed and manual add of path to kodi - return True + if video.find("importwatchedstate") == None: + writeNeeded = True + SubElement(video, "importwatchedstate").text = "true" + if video.find("importresumepoint") == None: + writeNeeded = True + SubElement(video, "importresumepoint").text = "true" + + if writeNeeded: + tree.write(settingsFile) + return True + else: + return False def checkAuthentication(): #check authentication @@ -155,19 +171,6 @@ def prettifyXml(elem): reparsed = minidom.parseString(rough_string) return reparsed.toprettyxml(indent="\t") -def doKodiCleanup(): - #remove old testdata and remove missing files - json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties" : ["file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMovies"}') - jsonobject = json.loads(json_response.decode('utf-8','replace')) - if(jsonobject.has_key('result')): - result = jsonobject['result'] - if(result.has_key('movies')): - movies = result['movies'] - for movie in movies: - if (xbmcvfs.exists(movie["file"]) == False) or ("plugin.video.xbmb3c" in movie["file"]): - xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveMovie", "params": { "movieid": %i}, "id": 1 }' %(movie["movieid"])) - - def get_params( paramstring ): xbmc.log("Parameter string: " + paramstring) param={} diff --git a/service.py b/service.py index 95403444..f46ba4bc 100644 --- a/service.py +++ b/service.py @@ -37,11 +37,9 @@ class Service(): player = Player() lastProgressUpdate = datetime.today() - #perform kodi cleanup (needed while testing, can be removed later if needed) - utils.doKodiCleanup() # check kodi library sources - utils.checkKodiSources() + mayRun = utils.checkKodiSources() interval_FullSync = 120 interval_IncrementalSync = 30 @@ -49,74 +47,75 @@ class Service(): cur_seconds_fullsync = interval_FullSync cur_seconds_incrsync = interval_IncrementalSync - while not xbmc.abortRequested: - - xbmc.sleep(1000) - - if xbmc.Player().isPlaying(): - try: - playTime = xbmc.Player().getTime() - currentFile = xbmc.Player().getPlayingFile() - - if(player.played_information.get(currentFile) != None): - player.played_information[currentFile]["currentPossition"] = playTime - - # send update - td = datetime.today() - lastProgressUpdate - secDiff = td.seconds - if(secDiff > 10): - try: - player.reportPlayback() - except Exception, msg: - xbmc.log("MB3 Sync Service -> Exception reporting progress : " + msg) - pass - lastProgressUpdate = datetime.today() - - except Exception, e: - xbmc.log("MB3 Sync Service -> Exception in Playback Monitor Service : " + str(e)) - pass - else: - # background worker for database sync - if DownloadUtils().authenticate(retreive=False) != "": - - #full sync - if(cur_seconds_fullsync >= interval_FullSync): - xbmc.log("Doing_Db_Sync: syncDatabase (Started)") - worked = librarySync.syncDatabase() - xbmc.log("Doing_Db_Sync: syncDatabase (Finished) " + str(worked)) - if(worked): - cur_seconds_fullsync = 0 - else: - cur_seconds_fullsync = interval_FullSync - 10 - else: - cur_seconds_fullsync += 1 - - #incremental sync - if(cur_seconds_incrsync >= interval_IncrementalSync): - xbmc.log("Doing_Db_Sync: updatePlayCounts (Started)") - worked = librarySync.updatePlayCounts() - xbmc.log("Doing_Db_Sync: updatePlayCounts (Finished) " + str(worked)) - if(worked): - cur_seconds_incrsync = 0 - else: - cur_seconds_incrsync = interval_IncrementalSync - 10 - else: - cur_seconds_incrsync += 1 + if mayRun: + while not xbmc.abortRequested: + + xbmc.sleep(1000) + + if xbmc.Player().isPlaying(): + try: + playTime = xbmc.Player().getTime() + currentFile = xbmc.Player().getPlayingFile() - # check if we need to run lib updates - WINDOW = xbmcgui.Window( 10000 ) - if(WINDOW.getProperty("cleanNeeded") == "true"): - xbmc.executebuiltin("CleanLibrary(video)") - WINDOW.clearProperty("cleanNeeded") - - if(WINDOW.getProperty("updateNeeded") == "true"): - xbmc.executebuiltin("UpdateLibrary(video)") - WINDOW.clearProperty("updateNeeded") - + if(player.played_information.get(currentFile) != None): + player.played_information[currentFile]["currentPossition"] = playTime + + # send update + td = datetime.today() - lastProgressUpdate + secDiff = td.seconds + if(secDiff > 10): + try: + player.reportPlayback() + except Exception, msg: + xbmc.log("MB3 Sync Service -> Exception reporting progress : " + msg) + pass + lastProgressUpdate = datetime.today() + + except Exception, e: + xbmc.log("MB3 Sync Service -> Exception in Playback Monitor Service : " + str(e)) + pass else: - xbmc.log("Not authenticated yet") - - utils.logMsg("MB3 Sync Service" "stopping Service",0) + # background worker for database sync + if DownloadUtils().authenticate(retreive=False) != "": + + #full sync + if(cur_seconds_fullsync >= interval_FullSync): + xbmc.log("Doing_Db_Sync: syncDatabase (Started)") + worked = librarySync.syncDatabase() + xbmc.log("Doing_Db_Sync: syncDatabase (Finished) " + str(worked)) + if(worked): + cur_seconds_fullsync = 0 + else: + cur_seconds_fullsync = interval_FullSync - 10 + else: + cur_seconds_fullsync += 1 + + #incremental sync + if(cur_seconds_incrsync >= interval_IncrementalSync): + xbmc.log("Doing_Db_Sync: updatePlayCounts (Started)") + worked = librarySync.updatePlayCounts() + xbmc.log("Doing_Db_Sync: updatePlayCounts (Finished) " + str(worked)) + if(worked): + cur_seconds_incrsync = 0 + else: + cur_seconds_incrsync = interval_IncrementalSync - 10 + else: + cur_seconds_incrsync += 1 + + # check if we need to run lib updates + WINDOW = xbmcgui.Window( 10000 ) + if(WINDOW.getProperty("cleanNeeded") == "true"): + xbmc.executebuiltin("CleanLibrary(video)") + WINDOW.clearProperty("cleanNeeded") + + if(WINDOW.getProperty("updateNeeded") == "true"): + xbmc.executebuiltin("UpdateLibrary(video)") + WINDOW.clearProperty("updateNeeded") + + else: + xbmc.log("Not authenticated yet") + + utils.logMsg("MB3 Sync Service" "stopping Service",0) #start the service