def canAddProvider(kind, name, url, api_key=None): """See if a Newznab or Torznab provider can be added.""" if not name: return json.dumps({'error': 'No Provider Name specified'}) found_chars = [c for c in INVALID_CHARS if c in name] if found_chars: return json.dumps({ 'error': 'Invalid character in provider name: {0}'.format( ', '.join(found_chars)) }) if kind == 'newznab': provider_dict = dict( list( zip([x.get_id() for x in app.newznabProviderList], app.newznabProviderList))) temp_provider = NewznabProvider(name, url) elif kind == 'torznab': provider_dict = dict( list( zip([x.get_id() for x in app.torznab_providers_list], app.torznab_providers_list))) temp_provider = TorznabProvider(name, url, api_key) if temp_provider.get_id() in provider_dict: return json.dumps({ 'error': 'Provider name already exists as {name}'.format( name=provider_dict[temp_provider.get_id()].name) }) else: return json.dumps({'success': temp_provider.get_id()})
def saveNewznabProvider(name, url, api_key=''): """Save a Newznab Provider.""" if not name or not url: return '0' provider_dict = dict(list(zip([x.name for x in app.newznabProviderList], app.newznabProviderList))) if name in provider_dict: if not provider_dict[name].default: provider_dict[name].name = name provider_dict[name].url = config.clean_url(url) provider_dict[name].api_key = api_key # a 0 in the api key spot indicates that no api key is needed if api_key == '0': provider_dict[name].needs_auth = False else: provider_dict[name].needs_auth = True return '|'.join([provider_dict[name].get_id(), provider_dict[name].config_string()]) else: new_provider = NewznabProvider(name, url, api_key=api_key) app.newznabProviderList.append(new_provider) return '|'.join([new_provider.get_id(), new_provider.config_string()])
def saveNewznabProvider(name, url, api_key=''): """ Save a Newznab Provider """ if not name or not url: return '0' provider_dict = dict( zip([x.name for x in app.newznabProviderList], app.newznabProviderList)) if name in provider_dict: if not provider_dict[name].default: provider_dict[name].name = name provider_dict[name].url = config.clean_url(url) provider_dict[name].api_key = api_key # a 0 in the api key spot indicates that no api key is needed if api_key == '0': provider_dict[name].needs_auth = False else: provider_dict[name].needs_auth = True return '|'.join([ provider_dict[name].get_id(), provider_dict[name].config_string() ]) else: new_provider = NewznabProvider(name, url, api_key=api_key) app.newznabProviderList.append(new_provider) return '|'.join( [new_provider.get_id(), new_provider.config_string()])
def canAddNewznabProvider(name): """ See if a Newznab provider can be added """ if not name: return json.dumps({'error': 'No Provider Name specified'}) provider_dict = dict(zip([x.get_id() for x in app.newznabProviderList], app.newznabProviderList)) temp_provider = NewznabProvider(name, '') if temp_provider.get_id() in provider_dict: return json.dumps({'error': 'Provider Name already exists as {name}'.format(name=provider_dict[temp_provider.get_id()].name)}) else: return json.dumps({'success': temp_provider.get_id()})
def canAddProvider(kind, name, url, api_key=None): """See if a Newznab or Torznab provider can be added.""" if not name: return json.dumps({'error': 'No Provider Name specified'}) provider_dict = dict(zip([x.get_id() for x in app.newznabProviderList], app.newznabProviderList)) if kind == 'newznab': temp_provider = NewznabProvider(name, url) elif kind == 'torznab': temp_provider = TorznabProvider(name, url, api_key) if temp_provider.get_id() in provider_dict: return json.dumps({'error': 'Provider name already exists as {name}'.format( name=provider_dict[temp_provider.get_id()].name)}) else: return json.dumps({'success': temp_provider.get_id()})
def canAddProvider(kind, name, url, api_key=None): """See if a Newznab or Torznab provider can be added.""" if not name: return json.dumps({'error': 'No Provider Name specified'}) found_chars = [c for c in INVALID_CHARS if c in name] if found_chars: return json.dumps({'error': 'Invalid character in provider name: {0}'.format(', '.join(found_chars))}) if kind == 'newznab': provider_dict = dict(list(zip([x.get_id() for x in app.newznabProviderList], app.newznabProviderList))) temp_provider = NewznabProvider(name, url) elif kind == 'torznab': provider_dict = dict(list(zip([x.get_id() for x in app.torznab_providers_list], app.torznab_providers_list))) temp_provider = TorznabProvider(name, url, api_key) if temp_provider.get_id() in provider_dict: return json.dumps({'error': 'Provider name already exists as {name}'.format( name=provider_dict[temp_provider.get_id()].name)}) else: return json.dumps({'success': temp_provider.get_id()})
def _save_newznab_providers(providers_settings): providers = [] settings = providers_settings.split('!!!') providers_dict = dict( list( zip([x.get_id() for x in app.newznabProviderList], app.newznabProviderList))) for provider_settings in settings: if not provider_settings: continue name, url, api_key, categories = provider_settings.split('|') url = config.clean_url(url) categories = split_and_strip(categories) new_provider = NewznabProvider(name, url=url, api_key=api_key, cat_ids=categories) provider_id = new_provider.get_id() # if it already exists then update it if provider_id in providers_dict: providers_dict[provider_id].name = name providers_dict[provider_id].url = url providers_dict[provider_id].api_key = api_key providers_dict[provider_id].cat_ids = categories # a 0 in the key spot indicates that no key is needed if api_key == '0': providers_dict[provider_id].needs_auth = False else: providers_dict[provider_id].needs_auth = True else: app.newznabProviderList.append(new_provider) providers.append(provider_id) # delete anything that is missing for provider in app.newznabProviderList: if provider.get_id() not in providers: app.newznabProviderList.remove(provider) # Update the custom newznab provider list NewznabProvider.save_newznab_providers()
def _save_newznab_providers(providers_settings): providers = [] settings = providers_settings.split('!!!') providers_dict = dict( list(zip([x.get_id() for x in app.newznabProviderList], app.newznabProviderList))) for provider_settings in settings: if not provider_settings: continue name, url, api_key, categories = provider_settings.split('|') url = config.clean_url(url) categories = split_and_strip(categories) new_provider = NewznabProvider(name, url=url, api_key=api_key, cat_ids=categories) provider_id = new_provider.get_id() # if it already exists then update it if provider_id in providers_dict: providers_dict[provider_id].name = name providers_dict[provider_id].url = url providers_dict[provider_id].api_key = api_key providers_dict[provider_id].cat_ids = categories # a 0 in the key spot indicates that no key is needed if api_key == '0': providers_dict[provider_id].needs_auth = False else: providers_dict[provider_id].needs_auth = True else: app.newznabProviderList.append(new_provider) providers.append(provider_id) # delete anything that is missing for provider in app.newznabProviderList: if provider.get_id() not in providers: app.newznabProviderList.remove(provider) # Update the custom newznab provider list NewznabProvider.save_newznab_providers()
def saveProviders(self, newznab_string='', torrentrss_string='', provider_order=None, **kwargs): """ Save Provider related settings """ results = [] provider_str_list = provider_order.split() provider_list = [] newznab_provider_dict = dict( zip([x.get_id() for x in app.newznabProviderList], app.newznabProviderList)) finished_names = [] # add all the newznab info we got into our list if newznab_string: for curNewznabProviderStr in newznab_string.split('!!!'): if not curNewznabProviderStr: continue cur_name, cur_url, cur_key, cur_cat = curNewznabProviderStr.split( '|') cur_url = config.clean_url(cur_url) new_provider = NewznabProvider(cur_name, cur_url, api_key=cur_key, cat_ids=cur_cat) cur_id = new_provider.get_id() # if it already exists then update it if cur_id in newznab_provider_dict: newznab_provider_dict[cur_id].name = cur_name newznab_provider_dict[cur_id].url = cur_url newznab_provider_dict[cur_id].api_key = cur_key newznab_provider_dict[cur_id].cat_ids = split_and_strip( cur_cat) # a 0 in the key spot indicates that no key is needed if cur_key == '0': newznab_provider_dict[cur_id].needs_auth = False else: newznab_provider_dict[cur_id].needs_auth = True try: newznab_provider_dict[cur_id].search_mode = str( kwargs['{id}_search_mode'.format( id=cur_id)]).strip() except (AttributeError, KeyError): pass # these exceptions are actually catching unselected checkboxes try: newznab_provider_dict[ cur_id].search_fallback = config.checkbox_to_value( kwargs['{id}_search_fallback'.format( id=cur_id)]) except (AttributeError, KeyError): newznab_provider_dict[ cur_id].search_fallback = 0 # these exceptions are actually catching unselected checkboxes try: newznab_provider_dict[ cur_id].enable_daily = config.checkbox_to_value( kwargs['{id}_enable_daily'.format(id=cur_id)]) except (AttributeError, KeyError): newznab_provider_dict[ cur_id].enable_daily = 0 # these exceptions are actually catching unselected checkboxes try: newznab_provider_dict[ cur_id].enable_manualsearch = config.checkbox_to_value( kwargs['{id}_enable_manualsearch'.format( id=cur_id)]) except (AttributeError, KeyError): newznab_provider_dict[ cur_id].enable_manualsearch = 0 # these exceptions are actually catching unselected checkboxes try: newznab_provider_dict[ cur_id].enable_backlog = config.checkbox_to_value( kwargs['{id}_enable_backlog'.format( id=cur_id)]) except (AttributeError, KeyError): newznab_provider_dict[ cur_id].enable_backlog = 0 # these exceptions are actually catching unselected checkboxes else: app.newznabProviderList.append(new_provider) finished_names.append(cur_id) # delete anything that is missing for cur_provider in app.newznabProviderList: if cur_provider.get_id() not in finished_names: app.newznabProviderList.remove(cur_provider) # Update the custom newznab provider list NewznabProvider.save_newnab_providers() torrent_rss_provider_dict = dict( zip([x.get_id() for x in app.torrentRssProviderList], app.torrentRssProviderList)) finished_names = [] if torrentrss_string: for curTorrentRssProviderStr in torrentrss_string.split('!!!'): if not curTorrentRssProviderStr: continue cur_name, cur_url, cur_cookies, cur_title_tag = curTorrentRssProviderStr.split( '|') cur_url = config.clean_url(cur_url) new_provider = TorrentRssProvider(cur_name, cur_url, cur_cookies, cur_title_tag) cur_id = new_provider.get_id() # if it already exists then update it if cur_id in torrent_rss_provider_dict: torrent_rss_provider_dict[cur_id].name = cur_name torrent_rss_provider_dict[cur_id].url = cur_url torrent_rss_provider_dict[cur_id].cookies = cur_cookies torrent_rss_provider_dict[ cur_id].curTitleTAG = cur_title_tag else: app.torrentRssProviderList.append(new_provider) finished_names.append(cur_id) # delete anything that is missing for cur_provider in app.torrentRssProviderList: if cur_provider.get_id() not in finished_names: app.torrentRssProviderList.remove(cur_provider) # Update the torrentrss provider list app.TORRENTRSS_PROVIDERS = [ provider.name for provider in app.torrentRssProviderList ] disabled_list = [] # do the enable/disable for cur_providerStr in provider_str_list: cur_provider, cur_enabled = cur_providerStr.split(':') cur_enabled = try_int(cur_enabled) cur_prov_obj = [ x for x in providers.sorted_provider_list() if x.get_id() == cur_provider and hasattr(x, 'enabled') ] if cur_prov_obj: cur_prov_obj[0].enabled = bool(cur_enabled) if cur_enabled: provider_list.append(cur_provider) else: disabled_list.append(cur_provider) if cur_provider in newznab_provider_dict: newznab_provider_dict[cur_provider].enabled = bool(cur_enabled) elif cur_provider in torrent_rss_provider_dict: torrent_rss_provider_dict[cur_provider].enabled = bool( cur_enabled) provider_list.extend(disabled_list) # dynamically load provider settings for cur_torrent_provider in [ prov for prov in providers.sorted_provider_list() if prov.provider_type == GenericProvider.TORRENT ]: if hasattr(cur_torrent_provider, 'custom_url'): try: cur_torrent_provider.custom_url = str( kwargs['{id}_custom_url'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): cur_torrent_provider.custom_url = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'minseed'): try: cur_torrent_provider.minseed = int( str(kwargs['{id}_minseed'.format( id=cur_torrent_provider.get_id())]).strip()) except (AttributeError, KeyError): cur_torrent_provider.minseed = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'minleech'): try: cur_torrent_provider.minleech = int( str(kwargs['{id}_minleech'.format( id=cur_torrent_provider.get_id())]).strip()) except (AttributeError, KeyError): cur_torrent_provider.minleech = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'ratio'): try: ratio = float( str(kwargs['{id}_ratio'.format( id=cur_torrent_provider.get_id())]).strip()) cur_torrent_provider.ratio = (ratio, -1)[ratio < 0] except (AttributeError, KeyError, ValueError): cur_torrent_provider.ratio = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'digest'): try: cur_torrent_provider.digest = str( kwargs['{id}_digest'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): cur_torrent_provider.digest = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'hash'): try: cur_torrent_provider.hash = str(kwargs['{id}_hash'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): cur_torrent_provider.hash = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'api_key'): try: cur_torrent_provider.api_key = str( kwargs['{id}_api_key'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): cur_torrent_provider.api_key = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'username'): try: cur_torrent_provider.username = str( kwargs['{id}_username'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): cur_torrent_provider.username = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'password'): try: cur_torrent_provider.password = str( kwargs['{id}_password'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): cur_torrent_provider.password = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'passkey'): try: cur_torrent_provider.passkey = str( kwargs['{id}_passkey'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): cur_torrent_provider.passkey = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'pin'): try: cur_torrent_provider.pin = str(kwargs['{id}_pin'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): cur_torrent_provider.pin = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'confirmed'): try: cur_torrent_provider.confirmed = config.checkbox_to_value( kwargs['{id}_confirmed'.format( id=cur_torrent_provider.get_id())]) except (AttributeError, KeyError): cur_torrent_provider.confirmed = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'ranked'): try: cur_torrent_provider.ranked = config.checkbox_to_value( kwargs['{id}_ranked'.format( id=cur_torrent_provider.get_id())]) except (AttributeError, KeyError): cur_torrent_provider.ranked = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'engrelease'): try: cur_torrent_provider.engrelease = config.checkbox_to_value( kwargs['{id}_engrelease'.format( id=cur_torrent_provider.get_id())]) except (AttributeError, KeyError): cur_torrent_provider.engrelease = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'onlyspasearch'): try: cur_torrent_provider.onlyspasearch = config.checkbox_to_value( kwargs['{id}_onlyspasearch'.format( id=cur_torrent_provider.get_id())]) except (AttributeError, KeyError): cur_torrent_provider.onlyspasearch = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'sorting'): try: cur_torrent_provider.sorting = str( kwargs['{id}_sorting'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): cur_torrent_provider.sorting = 'seeders' # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'freeleech'): try: cur_torrent_provider.freeleech = config.checkbox_to_value( kwargs['{id}_freeleech'.format( id=cur_torrent_provider.get_id())]) except (AttributeError, KeyError): cur_torrent_provider.freeleech = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'search_mode'): try: cur_torrent_provider.search_mode = str( kwargs['{id}_search_mode'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): cur_torrent_provider.search_mode = 'eponly' # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'search_fallback'): try: cur_torrent_provider.search_fallback = config.checkbox_to_value( kwargs['{id}_search_fallback'.format( id=cur_torrent_provider.get_id())]) except (AttributeError, KeyError): cur_torrent_provider.search_fallback = 0 # these exceptions are catching unselected checkboxes if hasattr(cur_torrent_provider, 'enable_daily'): try: cur_torrent_provider.enable_daily = config.checkbox_to_value( kwargs['{id}_enable_daily'.format( id=cur_torrent_provider.get_id())]) except (AttributeError, KeyError): cur_torrent_provider.enable_daily = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'enable_manualsearch'): try: cur_torrent_provider.enable_manualsearch = config.checkbox_to_value( kwargs['{id}_enable_manualsearch'.format( id=cur_torrent_provider.get_id())]) except (AttributeError, KeyError): cur_torrent_provider.enable_manualsearch = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'enable_backlog'): try: cur_torrent_provider.enable_backlog = config.checkbox_to_value( kwargs['{id}_enable_backlog'.format( id=cur_torrent_provider.get_id())]) except (AttributeError, KeyError): cur_torrent_provider.enable_backlog = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'cat'): try: cur_torrent_provider.cat = int( str(kwargs['{id}_cat'.format( id=cur_torrent_provider.get_id())]).strip()) except (AttributeError, KeyError): cur_torrent_provider.cat = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_torrent_provider, 'subtitle'): try: cur_torrent_provider.subtitle = config.checkbox_to_value( kwargs['{id}_subtitle'.format( id=cur_torrent_provider.get_id())]) except (AttributeError, KeyError): cur_torrent_provider.subtitle = 0 # these exceptions are actually catching unselected checkboxes if cur_torrent_provider.enable_cookies: try: cur_torrent_provider.cookies = str( kwargs['{id}_cookies'.format( id=cur_torrent_provider.get_id())]).strip() except (AttributeError, KeyError): pass # I don't want to configure a default value here, as it can also be configured intially as a custom rss torrent provider for cur_nzb_provider in [ prov for prov in providers.sorted_provider_list() if prov.provider_type == GenericProvider.NZB ]: # We don't want to overwrite the api key, as that's not available in the second tab for newznab providers. if hasattr(cur_nzb_provider, 'api_key') and not isinstance( cur_nzb_provider, NewznabProvider): try: cur_nzb_provider.api_key = str( kwargs['{id}_api_key'.format( id=cur_nzb_provider.get_id())]).strip() except (AttributeError, KeyError): cur_nzb_provider.api_key = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_nzb_provider, 'username'): try: cur_nzb_provider.username = str( kwargs['{id}_username'.format( id=cur_nzb_provider.get_id())]).strip() except (AttributeError, KeyError): cur_nzb_provider.username = None # these exceptions are actually catching unselected checkboxes if hasattr(cur_nzb_provider, 'search_mode'): try: cur_nzb_provider.search_mode = str( kwargs['{id}_search_mode'.format( id=cur_nzb_provider.get_id())]).strip() except (AttributeError, KeyError): cur_nzb_provider.search_mode = 'eponly' # these exceptions are actually catching unselected checkboxes if hasattr(cur_nzb_provider, 'search_fallback'): try: cur_nzb_provider.search_fallback = config.checkbox_to_value( kwargs['{id}_search_fallback'.format( id=cur_nzb_provider.get_id())]) except (AttributeError, KeyError): cur_nzb_provider.search_fallback = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_nzb_provider, 'enable_daily'): try: cur_nzb_provider.enable_daily = config.checkbox_to_value( kwargs['{id}_enable_daily'.format( id=cur_nzb_provider.get_id())]) except (AttributeError, KeyError): cur_nzb_provider.enable_daily = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_nzb_provider, 'enable_manualsearch'): try: cur_nzb_provider.enable_manualsearch = config.checkbox_to_value( kwargs['{id}_enable_manualsearch'.format( id=cur_nzb_provider.get_id())]) except (AttributeError, KeyError): cur_nzb_provider.enable_manualsearch = 0 # these exceptions are actually catching unselected checkboxes if hasattr(cur_nzb_provider, 'enable_backlog'): try: cur_nzb_provider.enable_backlog = config.checkbox_to_value( kwargs['{id}_enable_backlog'.format( id=cur_nzb_provider.get_id())]) except (AttributeError, KeyError): cur_nzb_provider.enable_backlog = 0 # these exceptions are actually catching unselected checkboxes # app.NEWZNAB_DATA = '!!!'.join([x.config_string() for x in app.newznabProviderList]) app.PROVIDER_ORDER = provider_list app.instance.save_config() if results: for x in results: logger.log(x, logger.ERROR) ui.notifications.error('Error(s) Saving Configuration', '<br>\n'.join(results)) else: ui.notifications.message('Configuration Saved', os.path.join(app.CONFIG_FILE)) return self.redirect('/config/providers/')