예제 #1
0
    def create(self, name):
        try:
            AccountManager.create(name=name)
        except (apsw.ConstraintError, peewee.IntegrityError):
            raise NameConflictError

        return True
예제 #2
0
    def create(self, name):
        try:
            AccountManager.create(
                name=name
            )
        except (apsw.ConstraintError, peewee.IntegrityError):
            raise NameConflictError

        return True
예제 #3
0
    def delete(self, id):
        if id <= 1:
            # Block deletion of system/administrator accounts
            raise DeletionBlockedError

        # Delete account
        return AccountManager.delete(id=id)
예제 #4
0
def Thumb(account_id, refresh=None, *args, **kwargs):
    # Retrieve account
    account = AccountManager.get(Account.id == account_id)

    if not account.trakt:
        # TODO better account placeholder image
        return Redirect(R('icon-default.png'))

    # Retrieve thumb url
    thumb_url = account.thumb_url()

    if not thumb_url:
        # TODO better account placeholder image
        return Redirect(R('icon-default.png'))

    # Request thumb
    try:
        response = requests.get(thumb_url)
    except Exception:
        log.warn('Unable to retrieve account thumbnail', exc_info=True)
        return Redirect(R('icon-default.png'))

    if response.status_code != 200:
        return Redirect(R('icon-default.png'))

    return response.content
예제 #5
0
def Cover(account_id, refresh=None, *args, **kwargs):
    account = AccountManager.get(Account.id == account_id)

    if not account.trakt:
        return Redirect(R('art-default.png'))

    try:
        # Refresh trakt account details
        account.trakt.refresh()
    except Exception:
        log.warn('Unable to refresh trakt account details', exc_info=True)
        return Redirect(R('art-default.png'))

    if account.trakt.cover is None:
        return Redirect(R('art-default.png'))

    try:
        # Request cover image
        response = requests.get(account.trakt.cover)
    except Exception:
        log.warn('Unable to retrieve account cover', exc_info=True)
        return Redirect(R('art-default.png'))

    if response.status_code != 200:
        return Redirect(R('art-default.png'))

    return response.content
예제 #6
0
def Thumb(account_id, refresh=None, *args, **kwargs):
    # Retrieve account
    account = AccountManager.get(Account.id == account_id)

    if not account.trakt:
        # TODO better account placeholder image
        return Redirect(R('icon-default.png'))

    # Retrieve thumb url
    thumb_url = account.thumb_url()

    if not thumb_url:
        # TODO better account placeholder image
        return Redirect(R('icon-default.png'))

    # Request thumb
    try:
        response = requests.get(thumb_url)
    except Exception:
        log.warn('Unable to retrieve account thumbnail', exc_info=True)
        return Redirect(R('icon-default.png'))

    if response.status_code != 200:
        return Redirect(R('icon-default.png'))

    return response.content
예제 #7
0
def Cover(account_id, refresh=None, *args, **kwargs):
    account = AccountManager.get(Account.id == account_id)

    if not account.trakt:
        return Redirect(R('art-default.png'))

    try:
        # Refresh trakt account details
        account.trakt.refresh()
    except Exception:
        log.warn('Unable to refresh trakt account details', exc_info=True)
        return Redirect(R('art-default.png'))

    if account.trakt.cover is None:
        return Redirect(R('art-default.png'))

    try:
        # Request cover image
        response = requests.get(account.trakt.cover)
    except Exception:
        log.warn('Unable to retrieve account cover', exc_info=True)
        return Redirect(R('art-default.png'))

    if response.status_code != 200:
        return Redirect(R('art-default.png'))

    return response.content
예제 #8
0
    def get(self, full=False, **kwargs):
        query = dict([(key, value) for (key, value) in kwargs.items()
                      if key in ['id', 'username']])

        if len(query) < 1:
            return None

        return AccountManager.get(**query).to_json(full=full)
예제 #9
0
    def delete(self, id):
        if id <= 1:
            # Block deletion of system/administrator accounts
            raise DeletionBlockedError

        # Delete account
        return AccountManager.delete(
            id=id
        )
예제 #10
0
    def get(self, full=False, **kwargs):
        query = dict([
            (key, value)
            for (key, value) in kwargs.items()
            if key in ['id', 'username']
        ])

        if len(query) < 1:
            return None

        return AccountManager.get(**query).to_json(full=full)
예제 #11
0
def ControlsMenu(account_id=1,
                 title=None,
                 message=None,
                 refresh=None,
                 message_only=False,
                 *args,
                 **kwargs):
    account = AccountManager.get(Account.id == account_id)

    # Build sync controls menu
    oc = ObjectContainer(title2=_("Sync (%s)") % account.name,
                         no_cache=True,
                         art=function_path('Cover.png',
                                           account_id=account.id,
                                           refresh=account.refreshed_ts))

    # Start result message
    if title and message:
        oc.add(
            DirectoryObject(key=Callback(ControlsMenu,
                                         account_id=account.id,
                                         refresh=timestamp()),
                            title=pad_title(title),
                            summary=message))

        if message_only:
            return oc

    # Active sync status
    Active.create(oc,
                  callback=Callback(ControlsMenu,
                                    account_id=account.id,
                                    refresh=timestamp()),
                  account=account)

    #
    # Full
    #

    oc.add(
        DirectoryObject(key=Trigger.callback(Synchronize, account),
                        title=pad_title(SyncMode.title(SyncMode.Full)),
                        summary=Status.build(account, SyncMode.Full),
                        thumb=R("icon-sync.png"),
                        art=function_path('Cover.png',
                                          account_id=account.id,
                                          refresh=account.refreshed_ts)))

    #
    # Pull
    #

    oc.add(
        DirectoryObject(key=Trigger.callback(Pull, account),
                        title=pad_title(
                            _('%s from Trakt.tv') %
                            SyncMode.title(SyncMode.Pull)),
                        summary=Status.build(account, SyncMode.Pull),
                        thumb=R("icon-sync_down.png"),
                        art=function_path('Cover.png',
                                          account_id=account.id,
                                          refresh=account.refreshed_ts)))

    oc.add(
        DirectoryObject(key=Trigger.callback(FastPull, account),
                        title=pad_title(
                            _('%s from Trakt.tv') %
                            SyncMode.title(SyncMode.FastPull)),
                        summary=Status.build(account, SyncMode.FastPull),
                        thumb=R("icon-sync_down.png"),
                        art=function_path('Cover.png',
                                          account_id=account.id,
                                          refresh=account.refreshed_ts)))

    #
    # Push
    #

    p_account = account.plex

    try:
        # Retrieve account libraries/sections
        with p_account.authorization():
            sections = Plex['library'].sections()
    except Exception as ex:
        # Build message
        if p_account is None:
            message = _("Plex account hasn't been authenticated")
        else:
            message = str(ex.message or ex)

        # Redirect to error message
        log.warn('Unable to retrieve account libraries/sections: %s',
                 message,
                 exc_info=True)

        return redirect('/sync',
                        account_id=account_id,
                        title=_('Error'),
                        message=message,
                        message_only=True)

    section_keys = []

    f_allow, f_deny = Filters.get('filter_sections')

    for section in sections.filter(['show', 'movie'], titles=f_allow):
        oc.add(
            DirectoryObject(
                key=Trigger.callback(Push, account, section),
                title=pad_title(
                    _('%s "%s" to Trakt.tv') %
                    (SyncMode.title(SyncMode.Push), section.title)),
                summary=Status.build(account, SyncMode.Push, section.key),
                thumb=R("icon-sync_up.png"),
                art=function_path('Cover.png',
                                  account_id=account.id,
                                  refresh=account.refreshed_ts)))
        section_keys.append(section.key)

    if len(section_keys) > 1:
        oc.add(
            DirectoryObject(key=Trigger.callback(Push, account),
                            title=pad_title(
                                _('%s all to Trakt.tv') %
                                SyncMode.title(SyncMode.Push)),
                            summary=Status.build(account, SyncMode.Push),
                            thumb=R("icon-sync_up.png"),
                            art=function_path('Cover.png',
                                              account_id=account.id,
                                              refresh=account.refreshed_ts)))

    return oc
예제 #12
0
def ControlsMenu(account_id=1, title=None, message=None, refresh=None, message_only=False, *args, **kwargs):
    account = AccountManager.get(Account.id == account_id)

    # Build sync controls menu
    oc = ObjectContainer(
        title2=_("Sync (%s)") % account.name,
        no_cache=True,

        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    )

    # Start result message
    if title and message:
        oc.add(DirectoryObject(
            key=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()),
            title=pad_title(title),
            summary=message
        ))

        if message_only:
            return oc

    # Active sync status
    Active.create(
        oc,
        callback=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()),
        account=account
    )

    #
    # Full
    #

    oc.add(DirectoryObject(
        key=Trigger.callback(Synchronize, account),
        title=pad_title(SyncMode.title(SyncMode.Full)),
        summary=Status.build(account, SyncMode.Full),

        thumb=R("icon-sync.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    #
    # Pull
    #

    oc.add(DirectoryObject(
        key=Trigger.callback(Pull, account),
        title=pad_title(_('%s from Trakt.tv') % SyncMode.title(SyncMode.Pull)),
        summary=Status.build(account, SyncMode.Pull),

        thumb=R("icon-sync_down.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    oc.add(DirectoryObject(
        key=Trigger.callback(FastPull, account),
        title=pad_title(_('%s from Trakt.tv') % SyncMode.title(SyncMode.FastPull)),
        summary=Status.build(account, SyncMode.FastPull),

        thumb=R("icon-sync_down.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    #
    # Push
    #

    p_account = account.plex

    try:
        # Retrieve account libraries/sections
        with p_account.authorization():
            sections = Plex['library'].sections()
    except Exception as ex:
        # Build message
        if p_account is None:
            message = _("Plex account hasn't been authenticated")
        else:
            message = str(ex.message or ex)

        # Redirect to error message
        log.warn('Unable to retrieve account libraries/sections: %s', message, exc_info=True)

        return redirect('/sync',
            account_id=account_id,
            title=_('Error'),
            message=message,
            message_only=True
        )

    section_keys = []

    f_allow, f_deny = Filters.get('filter_sections')

    for section in sections.filter(['show', 'movie'], titles=f_allow):
        oc.add(DirectoryObject(
            key=Trigger.callback(Push, account, section),
            title=pad_title(_('%s "%s" to Trakt.tv') % (SyncMode.title(SyncMode.Push), section.title)),
            summary=Status.build(account, SyncMode.Push, section.key),

            thumb=R("icon-sync_up.png"),
            art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
        ))
        section_keys.append(section.key)

    if len(section_keys) > 1:
        oc.add(DirectoryObject(
            key=Trigger.callback(Push, account),
            title=pad_title(_('%s all to Trakt.tv') % SyncMode.title(SyncMode.Push)),
            summary=Status.build(account, SyncMode.Push),

            thumb=R("icon-sync_up.png"),
            art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
        ))

    return oc
예제 #13
0
def ControlsMenu(account_id=1, title=None, message=None, refresh=None, message_only=False):
    account = AccountManager.get(Account.id == account_id)

    # Build sync controls menu
    oc = ObjectContainer(
        title2=LF('controls:title', account.name),
        no_cache=True,

        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    )

    # Start result message
    if title and message:
        oc.add(DirectoryObject(
            key=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()),
            title=pad_title(title),
            summary=message
        ))

        if message_only:
            return oc

    # Active sync status
    Active.create(
        oc,
        callback=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()),
        account=account
    )

    #
    # Full
    #

    oc.add(DirectoryObject(
        key=Callback(Synchronize, account_id=account.id, refresh=timestamp()),
        title=pad_title(SyncMode.title(SyncMode.Full)),
        summary=Status.build(account, SyncMode.Full),

        thumb=R("icon-sync.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    #
    # Pull
    #

    oc.add(DirectoryObject(
        key=Callback(Pull, account_id=account.id, refresh=timestamp()),
        title=pad_title('%s from trakt' % SyncMode.title(SyncMode.Pull)),
        summary=Status.build(account, SyncMode.Pull),

        thumb=R("icon-sync_down.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    oc.add(DirectoryObject(
        key=Callback(FastPull, account_id=account.id, refresh=timestamp()),
        title=pad_title('%s from trakt' % SyncMode.title(SyncMode.FastPull)),
        summary=Status.build(account, SyncMode.FastPull),

        thumb=R("icon-sync_down.png"),
        art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)
    ))

    #
    # Push
    #

    p_account = account.plex

    try:
        # Retrieve account libraries/sections
        with p_account.authorization():
            sections = Plex['library'].sections()
    except Exception, ex:
        # Build message
        if p_account is None:
            message = "Plex account hasn't been authenticated"
        else:
            message = str(ex.message or ex)

        # Redirect to error message
        log.warn('Unable to retrieve account libraries/sections: %s', message, exc_info=True)

        return redirect('/sync',
            account_id=account_id,
            title='Error',
            message=message,
            message_only=True
        )