Beispiel #1
0
    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()
Beispiel #2
0
    def _add_prowlarr_provider(self, data):
        if not data.get('subType'):
            return self._bad_request(
                "Missing subtype ('newznab' or 'torznab')")

        if data.get('subType') not in ('newznab', 'torznab'):
            return self._bad_request('Subtype needs to be newznab or torznab')

        if not data.get('id'):
            return self._bad_request('No provider id provided')

        if not data.get('name'):
            return self._bad_request('No provider name provided')

        if not app.PROWLARR_URL or not app.PROWLARR_APIKEY:
            return self._bad_request(
                'Missing prowlarr url and/or api. Cannot build the url.')

        provider_url = f"{urljoin(app.PROWLARR_URL, str(data.get('id')))}/api"

        provider_class = None
        if data.get('subType') == 'torznab':
            provider_class = TorznabProvider
        else:
            provider_class = NewznabProvider

        new_provider = provider_class(data.get('name'),
                                      provider_url,
                                      api_key=app.PROWLARR_APIKEY,
                                      manager=GenericProvider.PROWLARR)
        new_provider = self.provider_name_auto_numbered(new_provider)

        if data.get('subType') == 'torznab':
            app.torznab_providers_list.append(new_provider)
            app.TORZNAB_PROVIDERS = [
                provider.name for provider in app.torznab_providers_list
            ]
        else:
            app.newznabProviderList.append(new_provider)
            NewznabProvider.save_newznab_providers()

        app.instance.save_config()
        return self._created(data={'result': new_provider.to_json()})
Beispiel #3
0
    def _add_newznab_provider(self, data):
        if not data.get('name'):
            return self._bad_request('No provider name provided')

        if not data.get('url'):
            return self._bad_request('No provider url provided')

        if not data.get('apikey'):
            return self._bad_request('No provider api key provided')

        new_provider = NewznabProvider(data.get('name'),
                                       data.get('url'),
                                       api_key=data.get('apikey'))
        new_provider = self.provider_name_auto_numbered(new_provider)

        app.newznabProviderList.append(new_provider)
        NewznabProvider.save_newznab_providers()
        app.instance.save_config()
        return self._created(data={'result': new_provider.to_json()})
Beispiel #4
0
    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()