Skip to content

Instantly share code, notes, and snippets.

@rodhfr
Last active October 10, 2025 02:23
Show Gist options
  • Save rodhfr/f03cffad002d5556ab5f93030164a757 to your computer and use it in GitHub Desktop.
Save rodhfr/f03cffad002d5556ab5f93030164a757 to your computer and use it in GitHub Desktop.
from flexget import plugin
from flexget.entry import Entry
from flexget.task import Task
from flexget.event import event
import logging
log = logging.getLogger('RoundRobinRSS')
class RoundRobinRSS(object):
"""
Seleciona feeds RSS de forma round-robin.
Mantém o índice entre execuções usando task.manager.persistent
"""
schema = {
'type': 'object',
'properties': {
'feeds': {'type': 'array', 'items': {'type': 'string'}}
},
'required': ['feeds'],
'additionalProperties': False
}
def on_task_input(self, task: Task, config):
feeds = config['feeds']
if not feeds:
log.warning('Nenhum feed definido para round_robin_rss.')
return
# Recupera o índice persistente
index = task.manager.persistent.get('round_robin_index', 0)
feed_url = feeds[index % len(feeds)]
log.info(f'Round-robin RSS: selecionando feed {feed_url}')
# Atualiza índice para próxima execução
task.manager.persistent['round_robin_index'] = (index + 1) % len(feeds)
task.manager.persistent.commit()
# Retorna entradas do feed usando o plugin RSS interno
rss_plugin = task.get_plugin_by_name('rss')
return rss_plugin.feed_entries(feed_url)
@event('plugin.register')
def register_plugin():
plugin.register(RoundRobinRSS, "round_robin_rss", api_ver=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment