Пример #1
0
 def create_server_account(cls):
     try:
         Account.get(Account.id == 0)
     except Account.DoesNotExist:
         Account.create(
             id=0,
             name=''
         )
Пример #2
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)
Пример #4
0
    def create_administrator_account(cls, token_plex=None):
        username = cls.get_trakt_username()

        try:
            account = Account.get(Account.id == 1)
        except Account.DoesNotExist:
            account = Account.create(
                id=1,
                name=username
            )

            # Create default rules for account
            cls.create_rules(account)

        # Ensure plex account details exist
        p_created, p_account = cls.create_plex_account(account)

        cls.create_plex_basic_credential(p_account, token_plex=token_plex)

        # Refresh plex account details
        try:
            p_refreshed = p_account.refresh(force=p_created)
        except:
            log.warn('Unable to refresh plex account (not authenticated?)', exc_info=True)
            p_refreshed = False

        # Ensure trakt account details exist
        t_created, t_account = cls.create_trakt_account(account, username)

        cls.create_trakt_basic_credential(t_account)
        cls.create_trakt_oauth_credential(t_account)

        # Refresh trakt account details
        try:
            t_refreshed = t_account.refresh(force=t_created)
        except:
            log.warn('Unable to refresh trakt account (not authenticated?)', exc_info=True)
            t_refreshed = False

        # Refresh account
        account.refresh(force=p_refreshed or t_refreshed)
Пример #5
0
    def create_administrator_account(cls, token_plex=None):
        username = cls.get_trakt_username()

        try:
            account = Account.get(Account.id == 1)
        except Account.DoesNotExist:
            account = Account.create(id=1, name=username)

            # Create default rules for account
            cls.create_rules(account)

        # Ensure plex account details exist
        p_created, p_account = cls.create_plex_account(account)

        cls.create_plex_basic_credential(p_account, token_plex=token_plex)

        # Refresh plex account details
        try:
            p_refreshed = p_account.refresh(force=p_created)
        except:
            log.warn('Unable to refresh plex account (not authenticated?)',
                     exc_info=True)
            p_refreshed = False

        # Ensure trakt account details exist
        t_created, t_account = cls.create_trakt_account(account, username)

        cls.create_trakt_basic_credential(t_account)
        cls.create_trakt_oauth_credential(t_account)

        # Refresh trakt account details
        try:
            t_refreshed = t_account.refresh(force=t_created)
        except:
            log.warn('Unable to refresh trakt account (not authenticated?)',
                     exc_info=True)
            t_refreshed = False

        # Refresh account
        account.refresh(force=p_refreshed or t_refreshed)
Пример #6
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
Пример #7
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 _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)
Пример #9
0
 def create_server_account(cls):
     try:
         Account.get(Account.id == 0)
     except Account.DoesNotExist:
         Account.create(id=0, name='')
Пример #10
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()