Пример #1
0
    def __init__(self):

        self.__dict__ = self._shared_state

        self.clientInfo = clientinfo.ClientInfo()
        self.doUtils = downloadutils.DownloadUtils().downloadUrl
        self.ws = wsc.WebSocketClient()
        self.xbmcplayer = xbmc.Player()

        log.debug("Starting playback monitor.")
        xbmc.Player.__init__(self)
Пример #2
0
    def service_entry_point(self):
        # Important: Threads depending on abortRequest will not trigger
        # if profile switch happens more than once.
        self.monitor = kodimonitor.KodiMonitor()
        self.kodi_player = player.Player()
        kodi_profile = xbmc.translatePath('special://profile')

        # Server auto-detect
        initialsetup.InitialSetup().setup()

        # Initialize important threads
        self.userclient_thread = userclient.UserClient()
        user_client = self.userclient_thread
        self.websocket_thread = wsc.WebSocketClient()
        self.library_thread = librarysync.LibrarySync()

        while not self.monitor.abortRequested():

            if window('emby_kodiProfile') != kodi_profile:
                # Profile change happened, terminate this thread and others
                log.info(
                    "Kodi profile was: %s and changed to: %s. Terminating old Emby thread.",
                    kodi_profile, window('emby_kodiProfile'))
                exc = Exception("Kodi profile changed detected")
                exc.quiet = True
                raise exc

            # Before proceeding, need to make sure:
            # 1. Server is online
            # 2. User is set
            # 3. User has access to the server

            if window('emby_online') == "true":

                # Emby server is online
                # Verify if user is set and has access to the server
                if user_client.get_user(
                ) is not None and user_client.get_access():

                    # If an item is playing
                    if self.kodi_player.isPlaying():
                        # ping metrics server to keep sessions alive while playing
                        # ping every 5 min
                        timeSinceLastPing = time.time() - self.lastMetricPing
                        if (timeSinceLastPing > 300):
                            self.lastMetricPing = time.time()
                            ga = GoogleAnalytics()
                            ga.sendEventData("PlayAction", "PlayPing")

                        self._report_progress()

                    elif not self.startup:
                        self.startup = self._startup()

                    if not self.websocket_running:
                        # Start the Websocket Client
                        self.websocket_running = True
                        self.websocket_thread.start()
                    if not self.library_running:
                        # Start the syncing thread
                        self.library_running = True
                        self.library_thread.start()
                else:

                    if (user_client.get_user() is None) and self.warn_auth:
                        # Alert user is not authenticated and suppress future warning
                        self.warn_auth = False
                        log.info("Not authenticated yet.")

                    # User access is restricted.
                    # Keep verifying until access is granted
                    # unless server goes offline or Kodi is shut down.
                    self._access_check()
            else:
                # Wait until Emby server is online
                # or Kodi is shut down.
                self._server_online_check()

            if self.monitor.waitForAbort(1):
                # Abort was requested while waiting. We should exit
                break

        ##### Emby thread is terminating. #####
        self.shutdown()
Пример #3
0
    def _server_online_check(self):
        # Set emby_online true/false property
        user_client = self.userclient_thread
        while not self.monitor.abortRequested():

            if user_client.get_server() is None:
                # No server info set in add-on settings
                pass

            elif not user_client.verify_server():
                # Server is offline.
                # Alert the user and suppress future warning
                if self.server_online:
                    log.info("Server is offline")
                    window('emby_online', value="false")

                    if settings('offlineMsg') == "true":
                        dialog(type_="notification",
                               heading=lang(33001),
                               message="%s %s" %
                               (self.addon_name, lang(33002)),
                               icon="{emby}",
                               sound=False)

                self.server_online = False

            elif window('emby_online') in ("sleep", "reset"):
                # device going to sleep
                if self.websocket_running:
                    self.websocket_thread.stop_client()
                    self.websocket_thread = wsc.WebSocketClient()
                    self.websocket_running = False

                if self.library_running:
                    self.library_thread.stopThread()
                    self.library_thread = librarysync.LibrarySync()
                    self.library_running = False
            else:
                # Server is online
                if not self.server_online:
                    # Server was offline when Kodi started.
                    # Wait for server to be fully established.
                    if self.monitor.waitForAbort(5):
                        # Abort was requested while waiting.
                        break
                    # Alert the user that server is online.
                    dialog(type_="notification",
                           heading="{emby}",
                           message=lang(33003),
                           icon="{emby}",
                           time=2000,
                           sound=False)

                self.server_online = True
                window('emby_online', value="true")
                log.info("Server is online and ready")

                # Start the userclient thread
                if not self.userclient_running:
                    self.userclient_running = True
                    user_client.start()

                break

            if self.monitor.waitForAbort(1):
                # Abort was requested while waiting.
                break