2015-07-22 13:16:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-06-05 06:05:40 +00:00
|
|
|
|
2015-09-24 11:59:26 +00:00
|
|
|
#################################################################################################
|
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
import logging
|
2015-06-05 06:05:40 +00:00
|
|
|
import os
|
2019-01-09 21:46:22 +00:00
|
|
|
import threading
|
2015-06-05 06:05:40 +00:00
|
|
|
import sys
|
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
import xbmc
|
2018-09-07 08:22:08 +00:00
|
|
|
import xbmcvfs
|
2015-12-24 19:51:47 +00:00
|
|
|
import xbmcaddon
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-09-24 11:59:26 +00:00
|
|
|
#################################################################################################
|
|
|
|
|
2018-10-12 01:24:33 +00:00
|
|
|
__addon__ = xbmcaddon.Addon(id='plugin.video.emby')
|
|
|
|
__base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib')).decode('utf-8')
|
|
|
|
__pcache__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('profile'), 'emby')).decode('utf-8')
|
|
|
|
__cache__ = xbmc.translatePath('special://temp/emby').decode('utf-8')
|
2018-09-07 08:22:08 +00:00
|
|
|
|
2018-10-12 01:24:33 +00:00
|
|
|
if not xbmcvfs.exists(__pcache__ + '/'):
|
|
|
|
from resources.lib.helper.utils import copytree
|
2018-09-07 08:22:08 +00:00
|
|
|
|
2018-10-18 12:07:14 +00:00
|
|
|
copytree(os.path.join(__base__, 'objects'), os.path.join(__pcache__, 'objects'))
|
2018-10-12 01:24:33 +00:00
|
|
|
|
|
|
|
sys.path.insert(0, __cache__)
|
|
|
|
sys.path.insert(0, __pcache__)
|
2018-09-06 08:36:32 +00:00
|
|
|
sys.path.append(__base__)
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-09-24 11:59:26 +00:00
|
|
|
#################################################################################################
|
|
|
|
|
2018-09-06 08:36:32 +00:00
|
|
|
from entrypoint import Service
|
|
|
|
from helper import settings
|
|
|
|
from emby import Emby
|
2016-07-24 08:59:48 +00:00
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
2018-09-06 08:36:32 +00:00
|
|
|
LOG = logging.getLogger("EMBY.service")
|
2019-01-11 07:07:31 +00:00
|
|
|
DELAY = int(settings('startupDelay') if settings('SyncInstallRunDone.bool') else 4 or 0)
|
2015-04-06 17:17:32 +00:00
|
|
|
|
2015-09-24 11:59:26 +00:00
|
|
|
#################################################################################################
|
|
|
|
|
2018-09-06 08:36:32 +00:00
|
|
|
|
2019-01-09 21:46:22 +00:00
|
|
|
class ServiceManager(threading.Thread):
|
|
|
|
|
|
|
|
''' Service thread.
|
|
|
|
To allow to restart and reload modules internally.
|
|
|
|
'''
|
|
|
|
exception = None
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
|
|
|
|
def run(self):
|
2019-01-13 10:21:35 +00:00
|
|
|
service = None
|
2019-01-09 21:46:22 +00:00
|
|
|
|
|
|
|
try:
|
2019-01-13 10:21:35 +00:00
|
|
|
service = Service()
|
|
|
|
|
|
|
|
if DELAY and xbmc.Monitor().waitForAbort(DELAY):
|
|
|
|
raise Exception("Aborted during startup delay")
|
|
|
|
|
2019-01-09 21:46:22 +00:00
|
|
|
service.service()
|
|
|
|
except Exception as error:
|
2019-01-13 10:21:35 +00:00
|
|
|
|
|
|
|
if not 'ExitService' in error and service is not None:
|
2019-01-09 21:46:22 +00:00
|
|
|
service.shutdown()
|
2019-01-20 07:21:37 +00:00
|
|
|
elif 'RestartService' in error:
|
|
|
|
service.reload_objects()
|
2019-01-09 21:46:22 +00:00
|
|
|
|
|
|
|
self.exception = error
|
|
|
|
|
|
|
|
|
2016-09-09 03:13:25 +00:00
|
|
|
if __name__ == "__main__":
|
2016-09-21 07:39:50 +00:00
|
|
|
|
2018-10-03 23:25:51 +00:00
|
|
|
LOG.warn("-->[ service ]")
|
2018-09-06 08:36:32 +00:00
|
|
|
LOG.warn("Delay startup by %s seconds.", DELAY)
|
|
|
|
|
2018-10-13 08:51:10 +00:00
|
|
|
while True:
|
2017-01-14 23:46:38 +00:00
|
|
|
|
2018-10-03 23:25:51 +00:00
|
|
|
try:
|
2019-01-09 21:46:22 +00:00
|
|
|
session = ServiceManager()
|
|
|
|
session.start()
|
|
|
|
session.join() # Block until the thread exits.
|
2018-10-13 08:51:10 +00:00
|
|
|
|
2019-01-09 21:46:22 +00:00
|
|
|
if 'RestartService' in session.exception:
|
|
|
|
continue
|
2018-10-13 08:51:10 +00:00
|
|
|
|
|
|
|
except Exception as error:
|
|
|
|
''' Issue initializing the service.
|
|
|
|
'''
|
2018-10-03 23:25:51 +00:00
|
|
|
LOG.exception(error)
|
|
|
|
|
2018-10-15 11:26:25 +00:00
|
|
|
break
|
|
|
|
|
2018-10-03 23:25:51 +00:00
|
|
|
LOG.warn("--<[ service ]")
|