def __exit__(self, exc_type, exc_val, exc_tb):

        ''' Exiting sync
        '''
        self.running = False
        window('emby_sync', clear=True)

        if not settings('dbSyncScreensaver.bool'):

            xbmc.executebuiltin('InhibitIdleShutdown(false)')
            set_screensaver(value=self.screensaver)
Exemple #2
0
    def __exit__(self, exc_type, exc_val, exc_tb):
        ''' Exiting sync
        '''
        self.running = False
        window('jellyfin_sync', clear=True)

        if not settings(
                'dbSyncScreensaver.bool') and self.screensaver is not None:

            xbmc.executebuiltin('InhibitIdleShutdown(false)')
            set_screensaver(value=self.screensaver)

        LOG.info("--<[ fullsync ]")
    def __init__(self, library, library_id=None, update=False):

        ''' Map the syncing process and start the sync. Ensure only one sync is running.
        '''
        self.__dict__ = self._shared_state
        window('emby_sync.bool', True)

        if not settings('dbSyncScreensaver.bool'):

            xbmc.executebuiltin('InhibitIdleShutdown(true)')
            self.screensaver = get_screensaver()
            set_screensaver(value="")

        if not self.running:

            self.running = True
            self.library = library
            self.direct_path = settings('useDirectPaths') == "1"
            self.update_library = update
            self.server = Emby()
            self.sync = get_sync()

            if library_id:
                libraries = library_id.split(',')

                for selected in libraries:

                    if selected not in [x.replace('Mixed:', "") for x in self.sync['Libraries']]:
                        library = self.get_libraries(selected)

                        if library:

                            self.sync['Libraries'].append("Mixed:%s" % selected if library[1] == 'mixed' else selected)

                            if library[1] in ('mixed', 'movies'):
                                self.sync['Libraries'].append('Boxsets:%s' % selected)
                        else:
                            self.sync['Libraries'].append(selected)
            else:
                self.mapping()

            xmls.sources()

            if not xmls.advanced_settings() and self.sync['Libraries']:
                self.start()
            else:
                self.running = False
        else:
            dialog("ok", heading="{emby}", line1=_(33197))

            raise Exception("Sync is already running.")
Exemple #4
0
    def __enter__(self):
        ''' Do everything we need before the sync
        '''
        LOG.info("-->[ fullsync ]")

        if not settings('dbSyncScreensaver.bool'):

            xbmc.executebuiltin('InhibitIdleShutdown(true)')
            self.screensaver = get_screensaver()
            set_screensaver(value="")

        self.running = True
        window('jellyfin_sync.bool', True)

        return self
    def __exit__(self, exc_type, exc_val, exc_tb):
        ''' Exiting sync
        '''
        self.running = False
        window('emby_sync', clear=True)

        if self.screensaver is not None:

            xbmc.executebuiltin('InhibitIdleShutdown(false)')
            set_screensaver(value=self.screensaver)
            self.screensaver = None

        if self.artwork is not None:

            settings('enableTextureCache.bool', True)
            self.artwork = None
            LOG.info("[ enable artwork cache ]")

        LOG.info("--<[ fullsync ]")
    def start(self):
        
        ''' Main sync process.
        '''
        LOG.info("starting sync with %s", self.sync['Libraries'])
        save_sync(self.sync)
        start_time = datetime.datetime.now()

        if not settings('dbSyncScreensaver.bool'):

            xbmc.executebuiltin('InhibitIdleShutdown(true)')
            screensaver = get_screensaver()
            set_screensaver(value="")

        try:
            for library in list(self.sync['Libraries']):

                self.process_library(library)

                if not library.startswith('Boxsets:') and library not in self.sync['Whitelist']:
                    self.sync['Whitelist'].append(library)

                self.sync['Libraries'].pop(self.sync['Libraries'].index(library))
                self.sync['RestorePoint'] = {}
        except Exception as error:

            if not settings('dbSyncScreensaver.bool'):

                xbmc.executebuiltin('InhibitIdleShutdown(false)')
                set_screensaver(value=screensaver)

            raise

        elapsed = datetime.datetime.now() - start_time
        settings('SyncInstallRunDone.bool', True)
        self.library.save_last_sync()
        save_sync(self.sync)

        xbmc.executebuiltin('UpdateLibrary(video)')
        dialog("notification", heading="{emby}", message="%s %s" % (_(33025), str(elapsed).split('.')[0]),
               icon="{emby}", sound=False)
        LOG.info("Full sync completed in: %s", str(elapsed).split('.')[0])
    def __enter__(self):
        ''' Do everything we need before the sync
        '''
        LOG.info("-->[ fullsync ]")

        if not settings('dbSyncScreensaver.bool'):

            xbmc.executebuiltin('InhibitIdleShutdown(true)')
            self.screensaver = get_screensaver()
            set_screensaver(value="")

        self.running = True

        if settings('enableTextureCache.bool') and settings('lowPowered.bool'):

            self.artwork = True
            settings('enableTextureCache.bool', False)
            LOG.info("[ disable artwork cache ]")

        window('emby_sync.bool', True)

        return self
Exemple #8
0
    def service(self):
        ''' If error is encountered, it will rerun this function.
            Start new "daemon threads" to process library updates.
            (actual daemon thread is not supported in Kodi)
        '''
        for threads in (self.download_threads, self.writer_threads['updated'],
                        self.writer_threads['userdata'],
                        self.writer_threads['removed']):
            for thread in threads:
                if thread.is_done:
                    threads.remove(thread)

        if not self.player.isPlayingVideo() or settings(
                'syncDuringPlay.bool') or xbmc.getCondVisibility(
                    'VideoPlayer.Content(livetv)'):

            self.worker_downloads()
            self.worker_sort()

            self.worker_updates()
            self.worker_userdata()
            self.worker_remove()
            self.worker_notify()

        if self.pending_refresh:
            window('emby_sync.bool', True)

            if self.total_updates > self.progress_display:
                queue_size = self.worker_queue_size()

                if self.progress_updates is None:

                    self.progress_updates = xbmcgui.DialogProgressBG()
                    self.progress_updates.create(_('addon_name'), _(33178))
                    self.progress_updates.update(
                        int((float(self.total_updates - queue_size) /
                             float(self.total_updates)) * 100),
                        message="%s: %s" % (_(33178), queue_size))
                elif queue_size:
                    self.progress_updates.update(
                        int((float(self.total_updates - queue_size) /
                             float(self.total_updates)) * 100),
                        message="%s: %s" % (_(33178), queue_size))
                else:
                    self.progress_updates.update(int(
                        (float(self.total_updates - queue_size) /
                         float(self.total_updates)) * 100),
                                                 message=_(33178))

            if not settings(
                    'dbSyncScreensaver.bool') and self.screensaver is None:

                xbmc.executebuiltin('InhibitIdleShutdown(true)')
                self.screensaver = get_screensaver()
                set_screensaver(value="")

        if (self.pending_refresh and not self.download_threads
                and not self.writer_threads['updated']
                and not self.writer_threads['userdata']
                and not self.writer_threads['removed']):
            self.pending_refresh = False
            self.save_last_sync()
            self.total_updates = 0
            window('emby_sync', clear=True)

            if self.progress_updates:

                self.progress_updates.close()
                self.progress_updates = None

            if not settings(
                    'dbSyncScreensaver.bool') and self.screensaver is not None:

                xbmc.executebuiltin('InhibitIdleShutdown(false)')
                set_screensaver(value=self.screensaver)
                self.screensaver = None

            if not xbmc.getCondVisibility('Window.IsMedia'):
                xbmc.executebuiltin('UpdateLibrary(video)')
            else:  # Prevent cursor from moving
                xbmc.executebuiltin('Container.Refresh')
                window('emby.updatewidgets.bool', True)

        elif window('emby.updatewidgets.bool'
                    ) and not xbmc.getCondVisibility('Window.IsMedia'):
            ''' In case an update happened but we were not on the homescreen and 
                now we are, force widget to update.
            '''
            window('emby.updatewidgets', clear=True)
            xbmc.executebuiltin('UpdateLibrary(video)')
    def service(self):
        ''' If error is encountered, it will rerun this function.
            Start new "daemon threads" to process library updates.
            (actual daemon thread is not supported in Kodi)
        '''
        for thread in self.download_threads:
            if thread.is_done:

                self.removed(thread.removed)
                self.download_threads.remove(thread)

        for threads in (self.emby_threads, self.writer_threads['updated'],
                        self.writer_threads['userdata'],
                        self.writer_threads['removed']):
            for thread in threads:

                if thread.is_done:
                    threads.remove(thread)

        if not self.player.isPlayingVideo() or settings(
                'syncDuringPlay.bool') or xbmc.getCondVisibility(
                    'VideoPlayer.Content(livetv)'):
            if not self.player.isPlayingVideo() or xbmc.getCondVisibility(
                    'VideoPlayer.Content(livetv)'):

                if self.verify_libs:
                    self.verify_libs = False

                    if get_sync()['Libraries']:
                        self.sync_libraries(True)

                self.worker_remove_lib()
                self.worker_add_lib()

            self.worker_verify()
            self.worker_downloads()
            self.worker_sort()

            self.worker_updates()
            self.worker_userdata()
            self.worker_remove()
            self.worker_notify()

        if self.pending_refresh:
            window('emby_sync.bool', True)
            self.set_progress_dialog()

            if not settings(
                    'dbSyncScreensaver.bool') and self.screensaver is None:

                xbmc.executebuiltin('InhibitIdleShutdown(true)')
                self.screensaver = get_screensaver()
                set_screensaver(value="")

        if (self.pending_refresh and not self.download_threads
                and not self.writer_threads['updated']
                and not self.writer_threads['userdata']
                and not self.writer_threads['removed']):
            self.pending_refresh = False
            self.save_last_sync()
            self.total_updates = 0
            window('emby_sync', clear=True)

            if self.progress_updates:

                LOG.info("--<[ pdialog ]")
                self.progress_updates.close()
                self.progress_updates = None

            if not settings(
                    'dbSyncScreensaver.bool') and self.screensaver is not None:

                xbmc.executebuiltin('InhibitIdleShutdown(false)')
                set_screensaver(value=self.screensaver)
                self.screensaver = None

            if not xbmc.getCondVisibility('Window.IsMedia'):
                xbmc.executebuiltin('UpdateLibrary(video)')
            else:  # Prevent cursor from moving
                xbmc.executebuiltin('Container.Refresh')
                window('emby.updatewidgets.bool', True)

        elif window('emby.updatewidgets.bool'
                    ) and not xbmc.getCondVisibility('Window.IsMedia'):
            ''' In case an update happened but we were not on the homescreen and 
                now we are, force widget to update.
            '''
            window('emby.updatewidgets', clear=True)
            xbmc.executebuiltin('UpdateLibrary(video)')