Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def register_plugin():
plugin.register(ExternalPlugin, 'external_plugin', api_ver=2)
@plugin.priority(plugin.PRIORITY_LAST)
def on_task_output(self, task, config):
if not task.accepted and not task.options.test:
return
try:
result = session.post(
'http://www.pogdesign.co.uk/cat/login',
data={
'username': config['username'],
'password': config['password'],
'sub_login': 'Account Login',
},
)
except requests.RequestException as e:
log.error('Error logging in to pog calendar: %s' % e)
return
if 'logout' not in result.text:
def send_notification(self, *args, **kwargs):
send_notification = plugin.get('notification_framework', 'notify').send_notification
try:
send_notification(*args, **kwargs)
except plugin.PluginError as e:
log.error(e)
except plugin.PluginWarning as e:
log.warning(e)
except Exception as e:
log.exception(e)
entries = set()
search_strings = [normalize_unicode(s) for s in entry.get('search_strings', [entry['title']])]
for search_string in search_strings:
url = 'http://isohunt.com/js/rss/%s?iht=%s&noSL' % (
urllib.quote(search_string.encode('utf-8')), optionlist.index(config))
log.debug('requesting: %s' % url)
rss = feedparser.parse(url)
status = rss.get('status', False)
if status != 200:
raise plugin.PluginWarning('Search result not 200 (OK), received %s' % status)
ex = rss.get('bozo_exception', False)
if ex:
raise plugin.PluginWarning('Got bozo_exception (bad feed)')
for item in rss.entries:
entry = Entry()
entry['title'] = item.title
entry['url'] = item.link
m = re.search(r'Size: ([\d]+).*Seeds: (\d+).*Leechers: (\d+)', item.description, re.IGNORECASE)
if not m:
log.debug('regexp did not find seeds / peer data')
continue
else:
log.debug('regexp found size(%s), Seeds(%s) and Leeches(%s)' % (m.group(1), m.group(2), m.group(3)))
entry['content_size'] = int(m.group(1))
entry['torrent_seeds'] = int(m.group(2))
entry['torrent_leeches'] = int(m.group(3))
@plugin.priority(135)
def on_task_output(self, task, config):
"""Add torrents to deluge at exit."""
config = self.prepare_config(config)
# don't add when learning
if task.options.learn:
return
if not config['enabled'] or not (task.accepted or task.options.test):
return
self.connect(task, config)
# Clean up temp file if download plugin is not configured for this task
if 'download' not in task.config:
for entry in task.accepted + task.failed:
if os.path.exists(entry.get('file', '')):
os.remove(entry['file'])
del (entry['file'])
def all_builtins():
"""Helper function to return an iterator over all builtin plugins."""
return (p for p in plugin.plugins.values() if p.builtin)
@plugin.internet(log)
def search(self, task, entry, config):
"""
Search for entries on 1337x
"""
if not isinstance(config, dict):
config = {}
order_by = ''
sort_order = ''
if isinstance(config.get('order_by'), str):
if config['order_by'] != 'leechers':
order_by = '/{0}/desc'.format(config['order_by'])
sort_order = 'sort-'
entries = set()
@plugin.priority(250) # run before other plugins
def on_task_metainfo(self, task, config):
selector = selector_map[config['select']]
# Convert within to bytes (int) or percent (float)
within = config.get('within')
if isinstance(within, str) and '%' in within:
within = parse_percent(within)
else:
within = parse_size(within)
path = selector(config['paths'], within=within)
if path:
log.debug('Path %s selected due to (%s)' % (path, config['select']))
for entry in task.all_entries:
def on_task_filter(self, task, config):
for item in config:
for plugin_name, plugin_config in item.items():
try:
thelist = plugin.get_plugin_by_name(plugin_name).instance.get_list(plugin_config)
except AttributeError:
raise PluginError('Plugin %s does not support list interface' % plugin_name)
for entry in task.entries:
if entry in thelist:
entry.reject()
@plugin.priority(2)
def estimate(self, entry):
if 'movie_name' not in entry:
return
movie_name = entry['movie_name']
movie_year = entry.get('movie_year')
if movie_year is not None and movie_year > datetime.datetime.now().year:
logger.debug('Skipping Blu-ray.com lookup since movie year is {}', movie_year)
return
logger.debug('Searching Blu-ray.com for release date of {} ({})', movie_name, movie_year)
release_date = None
try:
with Session() as session: