Exemple #1
0
    def search(self, task, entry, config=None):
        from flexget.utils.template import environment
        from flexget.manager import manager

        search_strings = [
            urllib.quote(normalize_unicode(s).encode("utf-8")) for s in entry.get("search_strings", [entry["title"]])
        ]
        rss_plugin = plugin.get_plugin_by_name("rss")
        entries = set()
        rss_config = rss_plugin.instance.build_config(config)
        try:
            template = environment.from_string(rss_config["url"])
        except TemplateSyntaxError as e:
            raise plugin.PluginError("Invalid jinja template as rss url: %s" % e)
        rss_config["all_entries"] = True
        for search_string in search_strings:
            rss_config["url"] = template.render({"search_term": search_string})
            # TODO: capture some other_fields to try to find seed/peer/content_size numbers?
            try:
                results = rss_plugin.phase_handlers["input"](task, rss_config)
            except plugin.PluginError as e:
                log.error("Error attempting to get rss for %s: %s", rss_config["url"], e)
            else:
                entries.update(results)
        return entries
Exemple #2
0
 def search(self, entry, config=None):
     from flexget.utils.template import environment
     from flexget.manager import manager
     search_strings = [
         urllib.quote(normalize_unicode(s).encode('utf-8'))
         for s in entry.get('search_strings', [entry['title']])
     ]
     rss_plugin = plugin.get_plugin_by_name('rss')
     entries = set()
     rss_config = rss_plugin.instance.build_config(config)
     template = environment.from_string(rss_config['url'])
     rss_config['all_entries'] = True
     for search_string in search_strings:
         # Create a fake task to pass to the rss plugin input handler
         task = Task(manager, 'search_rss_task', config={})
         rss_config['url'] = template.render({'search_term': search_string})
         # TODO: capture some other_fields to try to find seed/peer/content_size numbers?
         try:
             results = rss_plugin.phase_handlers['input'](task, rss_config)
         except plugin.PluginError as e:
             log.error('Error attempting to get rss for %s: %s',
                       rss_config['url'], e)
         else:
             entries.update(results)
     return entries
Exemple #3
0
    def search(self, task, entry, config=None):
        from flexget.utils.template import environment

        search_strings = [
            quote(normalize_unicode(s).encode('utf-8'))
            for s in entry.get('search_strings', [entry['title']])
        ]
        rss_plugin = plugin.get_plugin_by_name('rss')
        entries = set()
        rss_config = rss_plugin.instance.build_config(config)
        try:
            template = environment.from_string(rss_config['url'])
        except TemplateSyntaxError as e:
            raise plugin.PluginError('Invalid jinja template as rss url: %s' %
                                     e)
        rss_config['all_entries'] = True
        for search_string in search_strings:
            rss_config['url'] = template.render({'search_term': search_string})
            # TODO: capture some other_fields to try to find seed/peer/content_size numbers?
            try:
                results = rss_plugin.phase_handlers['input'](task, rss_config)
            except plugin.PluginError as e:
                log.error('Error attempting to get rss for %s: %s',
                          rss_config['url'], e)
            else:
                entries.update(results)
        return entries
Exemple #4
0
    def search(self, task, entry, config=None):
        from flexget.utils.template import environment

        search_strings = [
            quote(normalize_unicode(s).encode('utf-8'))
            for s in entry.get('search_strings', [entry['title']])
        ]
        rss_plugin = plugin.get_plugin_by_name('rss')
        entries = set()
        rss_config = rss_plugin.instance.build_config(config)
        try:
            template = environment.from_string(rss_config['url'])
        except TemplateSyntaxError as e:
            raise plugin.PluginError('Invalid jinja template as rss url: %s' % e)
        rss_config['all_entries'] = True
        for search_string in search_strings:
            rss_config['url'] = template.render({'search_term': search_string})
            # TODO: capture some other_fields to try to find seed/peer/content_size numbers?
            try:
                results = rss_plugin.phase_handlers['input'](task, rss_config)
            except plugin.PluginError as e:
                log.error('Error attempting to get rss for %s: %s', rss_config['url'], e)
            else:
                entries.update(results)
        return entries
Exemple #5
0
    def test_undefined_preserved(self, test_filter):
        """
        Test that when an undefined field gets passed to one of our custom jinja filters that it stays undefined,
        instead of turning into some sort of other error. Covering up the undefined error makes it harder to figure
        out what went wrong with the template.
        """
        from flexget.utils.template import environment

        template = environment.from_string('{{non_existent_field|%s}}' %
                                           test_filter)
        with pytest.raises(jinja2.UndefinedError):
            template.render({})
Exemple #6
0
 def search(self, entry, config=None):
     from flexget.utils.template import environment
     from flexget.manager import manager
     query = entry['title']
     search_string = urllib.quote(normalize_unicode(query).encode('utf-8'))
     rss_plugin = get_plugin_by_name('rss')
     # Create a fake task to pass to the rss plugin input handler
     task = Task(manager, 'search_rss_task', {})
     # Use a copy of the config, so we don't overwrite jinja url when filling in search term
     config = rss_plugin.instance.build_config(config).copy()
     template = environment.from_string(config['url'])
     config['url'] = template.render({'search_term': search_string})
     config['all_entries'] = True
     # TODO: capture some other_fields to try to find seed/peer/content_size numbers?
     return rss_plugin.phase_handlers['input'](task, config)
Exemple #7
0
def _process(element, secrets):
    from flexget.utils.template import environment
    if isinstance(element, dict):
        for k in element:
            val = _process(element[k], secrets)
            if val:
                element[k] = val
    elif isinstance(element, list):
        for i, v in enumerate(element):
            val = _process(v, secrets)
            if val:
                element[i] = val
    elif isinstance(element, basestring) and '{{' in element:
        try:
            template = environment.from_string(element)
            return template.render(secrets)
        except:
            return None
Exemple #8
0
 def search(self, query, comparator, config=None):
     from flexget.utils.template import environment
     from flexget.manager import manager
     comparator.set_seq1(query)
     search_string = urllib.quote(comparator.search_string().encode('utf-8'))
     rss_plugin = get_plugin_by_name('rss')
     # Create a fake task to pass to the rss plugin input handler
     task = Task(manager, 'search_rss_task', {})
     # Use a copy of the config, so we don't overwrite jinja url when filling in search term
     config = rss_plugin.instance.build_config(config).copy()
     template = environment.from_string(config['url'])
     config['url'] = template.render({'search_term': search_string})
     # TODO: capture some other_fields to try to find seed/peer/content_size numbers?
     entries = []
     for entry in rss_plugin.phase_handlers['input'](task, config):
         if comparator.matches(entry['title']):
             entry['search_ratio'] = comparator.ratio()
             entries.append(entry)
     return entries
Exemple #9
0
def _process(element, secrets):
    # Environment isn't set up at import time, have to delay the import until here
    from flexget.utils.template import environment
    if isinstance(element, dict):
        for k in element:
            val = _process(element[k], secrets)
            if val:
                element[k] = val
    elif isinstance(element, list):
        for i, v in enumerate(element):
            val = _process(v, secrets)
            if val:
                element[i] = val
    elif isinstance(element, basestring) and '{{' in element:
        try:
            template = environment.from_string(element)
            return template.render(secrets)
        except TemplateError:
            return None
Exemple #10
0
def _process(element, environment):
    if isinstance(element, dict):
        for k, v in element.items():
            new_key = _process(k, environment)
            if new_key:
                element[new_key] = element.pop(k)
                k = new_key
            val = _process(element[k], environment)
            if val:
                element[k] = val
    elif isinstance(element, list):
        for i, v in enumerate(element):
            val = _process(v, environment)
            if val:
                element[i] = val
    elif isinstance(element, basestring) and '{{' in element:
        try:
            template = environment.from_string(element)
            return template.render()
        except (TemplateError, TypeError):
            return None
Exemple #11
0
 def search(self, entry, config=None):
     from flexget.utils.template import environment
     from flexget.manager import manager
     search_strings = [urllib.quote(normalize_unicode(s).encode('utf-8'))
                       for s in entry.get('search_strings', [entry['title']])]
     rss_plugin = plugin.get_plugin_by_name('rss')
     entries = set()
     rss_config = rss_plugin.instance.build_config(config)
     template = environment.from_string(rss_config['url'])
     rss_config['all_entries'] = True
     for search_string in search_strings:
         # Create a fake task to pass to the rss plugin input handler
         task = Task(manager, 'search_rss_task', config={})
         rss_config['url'] = template.render({'search_term': search_string})
         # TODO: capture some other_fields to try to find seed/peer/content_size numbers?
         try:
             results = rss_plugin.phase_handlers['input'](task, rss_config)
         except plugin.PluginError as e:
             log.error('Error attempting to get rss for %s: %s', rss_config['url'], e)
         else:
             entries.update(results)
     return entries
Exemple #12
0
def _process(element, secrets):
    # Environment isn't set up at import time, have to delay the import until here
    from flexget.utils.template import environment
    if isinstance(element, dict):
        for k, v in element.iteritems():
            new_key = _process(k, secrets)
            if new_key:
                element[new_key] = element.pop(k)
                k = new_key
            val = _process(element[k], secrets)
            if val:
                element[k] = val
    elif isinstance(element, list):
        for i, v in enumerate(element):
            val = _process(v, secrets)
            if val:
                element[i] = val
    elif isinstance(element, basestring) and '{{' in element:
        try:
            template = environment.from_string(element)
            return template.render(secrets)
        except (TemplateError, TypeError):
            return None