Example #1
0
    def on_added(self, data, *args, **kwargs):
        if data.get('type') not in [1, 2, 4]:
            return

        log.debug(
            'Item added: %s (id: %r, type: %r)',
            data.get('title'),
            data.get('itemID'),
            data.get('type')
        )

        # Retrieve accounts
        accounts = Account.select(
            Account.id
        ).where(
            Account.id > 0
        )

        # Update library state for accounts
        for account in accounts:
            if account.deleted:
                continue

            # Ensure account has the library update trigger enabled
            enabled = Preferences.get('sync.library_update', account)

            if not enabled:
                continue

            # Update library state for account
            self.get(account.id).on_added(data)
    def _queue(self):
        accounts = Account.select(
            Account.id
        ).where(
            Account.id > 0
        )

        for account in accounts:
            if account.deleted:
                # Ignore library update trigger for deleted accounts
                continue

            enabled = Preferences.get('sync.library_update', account)

            log.debug('account: %r, enabled: %r', account.id, enabled)

            if not enabled:
                continue

            try:
                # Queue sync for account
                self.sync.queue(
                    account=account,
                    mode=SyncMode.Full,

                    priority=100,
                    trigger=SyncResult.Trigger.LibraryUpdate
                )
            except QueueError, ex:
                log.info('Queue error: %s', ex)
Example #3
0
    def run(self, token_plex=None):
        # Ensure server `Account` exists
        self.create_server_account()

        # Ensure administrator `Account` exists
        self.create_administrator_account(token_plex=token_plex)

        # Refresh extra accounts
        accounts = Account.select().where(Account.id > 1,
                                          Account.deleted == False)

        for account in accounts:
            self.refresh_account(account)

        return True
    def run(self, token_plex=None):
        # Ensure server `Account` exists
        self.create_server_account()

        # Ensure administrator `Account` exists
        self.create_administrator_account(token_plex=token_plex)

        # Refresh extra accounts
        accounts = Account.select().where(
            Account.id > 1,
            Account.deleted == False
        )

        for account in accounts:
            self.refresh_account(account)

        return True
    def _queue(self):
        accounts = Account.select(Account.id).where(Account.id > 0)

        for account in accounts:
            if account.deleted:
                # Ignore library update trigger for deleted accounts
                continue

            enabled = Preferences.get('sync.library_update', account)

            log.debug('account: %r, enabled: %r', account.id, enabled)

            if not enabled:
                continue

            try:
                # Queue sync for account
                self.sync.queue(account=account,
                                mode=SyncMode.Full,
                                priority=100,
                                trigger=SyncResult.Trigger.LibraryUpdate)
            except QueueError, ex:
                log.info('Queue error: %s', ex)
Example #6
0
    def _queue(self):
        started_at = self._state.started_at

        if started_at:
            log.info('Scanner started at: %r', started_at)

        # Retrieve accounts
        accounts = Account.select(
            Account.id
        ).where(
            Account.id > 0
        )

        # Trigger sync on enabled accounts
        for account in accounts:
            if account.deleted:
                continue

            # Ensure account has the library update trigger enabled
            enabled = Preferences.get('sync.library_update', account)

            if not enabled:
                continue

            # Retrieve recently added items
            items_added = self._state.get(account.id).pop_added()

            log.info(
                'Detected %d item(s) have been added for account %r',
                account.id,
                len(items_added)
            )

            # Build pull parameters
            pull = {
                # Run pull on items we explicitly know have been created
                'ids': set(items_added)
            }

            if started_at:
                # Run pull on items created since the scanner started
                pull['created_since'] = started_at - timedelta(seconds=30)

            # Queue sync for account
            try:
                self.sync.queue(
                    account=account,
                    mode=SyncMode.Full,

                    priority=100,
                    trigger=SyncResult.Trigger.LibraryUpdate,

                    pull=pull
                )
            except QueueError as ex:
                log.info('Queue error: %s', ex)

                # Unable to queue sync, add items back to the account library state
                self._state.get(account.id).extend_added(items_added)
            finally:
                # Reset library state
                self._state.reset()