def callback(cls, func, account, section=None): if section: return Callback(func, account_id=account.id, section=section.key, t=timestamp()) return Callback(func, account_id=account.id, t=timestamp())
def create_active_item(oc): task, handler = SyncManager.get_current() if not task: return # Format values remaining = format_remaining(task.statistics.seconds_remaining) progress = format_percentage(task.statistics.progress) # Title title = '%s - Status' % normalize(handler.title) if progress: title += ' (%s)' % progress # Summary summary = task.statistics.message or 'Working' if remaining: summary += ', ~%s second%s remaining' % (remaining, plural(remaining)) # Create items oc.add(DirectoryObject( key=Callback(SyncMenu, refresh=timestamp()), title=pad_title(title), summary=summary + ' (click to refresh)' )) oc.add(DirectoryObject( key=Callback(Cancel), title=pad_title('%s - Cancel' % normalize(handler.title)) ))
def create_active_item(oc): task, handler = SyncManager.get_current() if not task: return # Format values remaining = format_remaining(task.statistics.seconds_remaining) progress = format_percentage(task.statistics.progress) # Title title = '%s - Status' % handler.title if progress: title += ' (%s)' % progress # Summary summary = task.statistics.message or 'Working' if remaining: summary += ', ~%s second%s remaining' % (remaining, plural(remaining)) # Create items oc.add( DirectoryObject(key=Callback(SyncMenu, refresh=timestamp()), title=pad_title(title), summary=summary + ' (click to refresh)')) oc.add( DirectoryObject(key=Callback(Cancel), title=pad_title('%s - Cancel' % handler.title)))
def AccountsMenu(refresh=None, *args, **kwargs): oc = ObjectContainer(title2=_("Accounts"), no_cache=True) # Active sync status Active.create( oc, callback=Callback(AccountsMenu, refresh=timestamp()), ) # Accounts for account in Accounts.list(): oc.add( DirectoryObject(key=Callback(ControlsMenu, account_id=account.id), title=account.name, art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts), thumb=function_path('Thumb.png', account_id=account.id, refresh=account.refreshed_ts))) return oc
def AccountsMenu(refresh=None, *args, **kwargs): oc = ObjectContainer( title2=_("Accounts"), no_cache=True ) # Active sync status Active.create( oc, callback=Callback(AccountsMenu, refresh=timestamp()), ) # Accounts for account in Accounts.list(): oc.add(DirectoryObject( key=Callback(ControlsMenu, account_id=account.id), title=account.name, art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts), thumb=function_path('Thumb.png', account_id=account.id, refresh=account.refreshed_ts) )) return oc
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
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
def callback(cls, func, account, section=None): if section: return Callback(func, account_id=account.id, section=section.key, t=timestamp()) return Callback(func, account_id=account.id, t=timestamp())
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 )
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=Callback(Push, account_id=account.id, section=section.key, refresh=timestamp()), title=pad_title('%s "%s" to trakt' % (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=Callback(Push, account_id=account.id, refresh=timestamp()), title=pad_title('%s all to trakt' % SyncMode.title(SyncMode.Push)), summary=Status.build(account, SyncMode.Push), thumb=R("icon-sync_up.png"),