jellyfin-kodi/service.py

76 lines
2.1 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
#################################################################################################
import logging
import os
import sys
2015-03-13 21:24:59 +00:00
import xbmc
import xbmcvfs
import xbmcaddon
2015-03-13 21:24:59 +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')
if not xbmcvfs.exists(__pcache__ + '/'):
from resources.lib.helper.utils import copytree
copytree(os.path.join(__base__, 'objects').decode('utf-8'), os.path.join(__pcache__, 'objects').decode('utf-8'))
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
#################################################################################################
2018-09-06 08:36:32 +00:00
from entrypoint import Service
from helper import settings
from emby import Emby
#################################################################################################
2018-09-06 08:36:32 +00:00
LOG = logging.getLogger("EMBY.service")
DELAY = int(settings('startupDelay') or 0)
2015-04-06 17:17:32 +00:00
#################################################################################################
2018-09-06 08:36:32 +00:00
2016-09-09 03:13:25 +00:00
if __name__ == "__main__":
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)
while True:
2018-10-03 23:25:51 +00:00
try:
session = Service()
2018-09-06 08:36:32 +00:00
try:
if DELAY and xbmc.Monitor().waitForAbort(DELAY):
raise Exception("Aborted during startup delay")
session.service()
except Exception as error: # TODO, build exceptions
LOG.exception(error)
session.shutdown()
2018-10-15 11:26:25 +00:00
if 'RestartService' in error:
continue
except Exception as error:
''' Issue initializing the service.
'''
2018-10-03 23:25:51 +00:00
LOG.exception(error)
break
2018-09-06 08:36:32 +00:00
2018-10-15 11:26:25 +00:00
break
2018-10-03 23:25:51 +00:00
LOG.warn("--<[ service ]")