fixed the restart message
not start sync before settings are changed in the kodi xml files
This commit is contained in:
parent
ea8c810a05
commit
a0099a69db
2 changed files with 95 additions and 93 deletions
|
@ -55,19 +55,29 @@ def checkKodiSources():
|
||||||
tvLibrary = os.path.join(dataPath,'tvshows')
|
tvLibrary = os.path.join(dataPath,'tvshows')
|
||||||
|
|
||||||
rebootRequired = False
|
rebootRequired = False
|
||||||
|
|
||||||
if not xbmcvfs.exists(dataPath + os.sep):
|
if not xbmcvfs.exists(dataPath + os.sep):
|
||||||
xbmcvfs.mkdir(dataPath)
|
xbmcvfs.mkdir(dataPath)
|
||||||
if not xbmcvfs.exists(movieLibrary + os.sep):
|
if not xbmcvfs.exists(movieLibrary + os.sep):
|
||||||
xbmcvfs.mkdir(movieLibrary)
|
xbmcvfs.mkdir(movieLibrary)
|
||||||
rebootRequired = addKodiSource("mediabrowser_movies",movieLibrary,"movies")
|
rebootRequired = True
|
||||||
|
addKodiSource("mediabrowser_movies",movieLibrary,"movies")
|
||||||
if not xbmcvfs.exists(tvLibrary + os.sep):
|
if not xbmcvfs.exists(tvLibrary + os.sep):
|
||||||
xbmcvfs.mkdir(tvLibrary)
|
xbmcvfs.mkdir(tvLibrary)
|
||||||
rebootRequired = addKodiSource("mediabrowser_tvshows",tvLibrary,"tvshows")
|
rebootRequired = True
|
||||||
|
addKodiSource("mediabrowser_tvshows",tvLibrary,"tvshows")
|
||||||
|
|
||||||
|
rebootRequired = KodiAdvancedSettingsCheck()
|
||||||
|
|
||||||
if rebootRequired:
|
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:
|
if ret:
|
||||||
xbmc.executebuiltin("RestartApp")
|
xbmc.executebuiltin("RestartApp")
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def addKodiSource(name, path, type):
|
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
|
#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, "name").text = name
|
||||||
SubElement(source, "path").text = path
|
SubElement(source, "path").text = path
|
||||||
tree.write(sourcesFile)
|
tree.write(sourcesFile)
|
||||||
#return bool that reboot is needed and manual add of path to kodi
|
|
||||||
return KodiAdvancedSettingsCheck()
|
|
||||||
|
|
||||||
def KodiAdvancedSettingsCheck():
|
def KodiAdvancedSettingsCheck():
|
||||||
#setting that kodi should import watched state and resume points from the nfo files
|
#setting that kodi should import watched state and resume points from the nfo files
|
||||||
|
@ -128,6 +136,7 @@ def KodiAdvancedSettingsCheck():
|
||||||
video = SubElement(sources, "videolibrary")
|
video = SubElement(sources, "videolibrary")
|
||||||
ET.ElementTree(sources).write(settingsFile)
|
ET.ElementTree(sources).write(settingsFile)
|
||||||
|
|
||||||
|
writeNeeded = False
|
||||||
if xbmcvfs.exists(settingsFile):
|
if xbmcvfs.exists(settingsFile):
|
||||||
tree = ET.ElementTree(file=settingsFile)
|
tree = ET.ElementTree(file=settingsFile)
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
@ -135,11 +144,18 @@ def KodiAdvancedSettingsCheck():
|
||||||
if video == None:
|
if video == None:
|
||||||
video = SubElement(sources, "videolibrary")
|
video = SubElement(sources, "videolibrary")
|
||||||
# add the settings
|
# add the settings
|
||||||
SubElement(video, "importwatchedstate").text = "true"
|
if video.find("importwatchedstate") == None:
|
||||||
SubElement(video, "importresumepoint").text = "true"
|
writeNeeded = True
|
||||||
tree.write(settingsFile)
|
SubElement(video, "importwatchedstate").text = "true"
|
||||||
#return bool that reboot is needed and manual add of path to kodi
|
if video.find("importresumepoint") == None:
|
||||||
return True
|
writeNeeded = True
|
||||||
|
SubElement(video, "importresumepoint").text = "true"
|
||||||
|
|
||||||
|
if writeNeeded:
|
||||||
|
tree.write(settingsFile)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def checkAuthentication():
|
def checkAuthentication():
|
||||||
#check authentication
|
#check authentication
|
||||||
|
@ -155,19 +171,6 @@ def prettifyXml(elem):
|
||||||
reparsed = minidom.parseString(rough_string)
|
reparsed = minidom.parseString(rough_string)
|
||||||
return reparsed.toprettyxml(indent="\t")
|
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 ):
|
def get_params( paramstring ):
|
||||||
xbmc.log("Parameter string: " + paramstring)
|
xbmc.log("Parameter string: " + paramstring)
|
||||||
param={}
|
param={}
|
||||||
|
|
137
service.py
137
service.py
|
@ -37,11 +37,9 @@ class Service():
|
||||||
player = Player()
|
player = Player()
|
||||||
lastProgressUpdate = datetime.today()
|
lastProgressUpdate = datetime.today()
|
||||||
|
|
||||||
#perform kodi cleanup (needed while testing, can be removed later if needed)
|
|
||||||
utils.doKodiCleanup()
|
|
||||||
|
|
||||||
# check kodi library sources
|
# check kodi library sources
|
||||||
utils.checkKodiSources()
|
mayRun = utils.checkKodiSources()
|
||||||
|
|
||||||
interval_FullSync = 120
|
interval_FullSync = 120
|
||||||
interval_IncrementalSync = 30
|
interval_IncrementalSync = 30
|
||||||
|
@ -49,74 +47,75 @@ class Service():
|
||||||
cur_seconds_fullsync = interval_FullSync
|
cur_seconds_fullsync = interval_FullSync
|
||||||
cur_seconds_incrsync = interval_IncrementalSync
|
cur_seconds_incrsync = interval_IncrementalSync
|
||||||
|
|
||||||
while not xbmc.abortRequested:
|
if mayRun:
|
||||||
|
while not xbmc.abortRequested:
|
||||||
xbmc.sleep(1000)
|
|
||||||
|
xbmc.sleep(1000)
|
||||||
if xbmc.Player().isPlaying():
|
|
||||||
try:
|
if xbmc.Player().isPlaying():
|
||||||
playTime = xbmc.Player().getTime()
|
try:
|
||||||
currentFile = xbmc.Player().getPlayingFile()
|
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
|
|
||||||
|
|
||||||
# check if we need to run lib updates
|
if(player.played_information.get(currentFile) != None):
|
||||||
WINDOW = xbmcgui.Window( 10000 )
|
player.played_information[currentFile]["currentPossition"] = playTime
|
||||||
if(WINDOW.getProperty("cleanNeeded") == "true"):
|
|
||||||
xbmc.executebuiltin("CleanLibrary(video)")
|
# send update
|
||||||
WINDOW.clearProperty("cleanNeeded")
|
td = datetime.today() - lastProgressUpdate
|
||||||
|
secDiff = td.seconds
|
||||||
if(WINDOW.getProperty("updateNeeded") == "true"):
|
if(secDiff > 10):
|
||||||
xbmc.executebuiltin("UpdateLibrary(video)")
|
try:
|
||||||
WINDOW.clearProperty("updateNeeded")
|
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:
|
else:
|
||||||
xbmc.log("Not authenticated yet")
|
# background worker for database sync
|
||||||
|
if DownloadUtils().authenticate(retreive=False) != "":
|
||||||
utils.logMsg("MB3 Sync Service" "stopping Service",0)
|
|
||||||
|
#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
|
#start the service
|
||||||
|
|
Loading…
Reference in a new issue