Skip to content

Commit

Permalink
Blacken and isort all files with latest versions/settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gazpachoking committed Sep 8, 2020
1 parent de3cde1 commit b623605
Show file tree
Hide file tree
Showing 33 changed files with 135 additions and 89 deletions.
5 changes: 4 additions & 1 deletion dev_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def download_extract(url, dest_path):
shutil.rmtree(app_path)
# Just stashed the old webui zip on a random github release for easy hosting.
# It doesn't get updated anymore, we should probably stop bundling it with releases soon.
download_extract('https://github.com/Flexget/Flexget/releases/download/v3.0.6/webui_v1.zip', os.path.join(ui_path, 'v1'))
download_extract(
'https://github.com/Flexget/Flexget/releases/download/v3.0.6/webui_v1.zip',
os.path.join(ui_path, 'v1'),
)
except OSError as e:
click.echo('Unable to download and extract WebUI v1 due to %e' % str(e))
raise click.Abort()
Expand Down
2 changes: 1 addition & 1 deletion flexget/components/archive/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def consolidate():
logger.verbose('Found {} items to migrate, this can be aborted with CTRL-C safely.', count)

# consolidate old data
from progressbar import ProgressBar, Percentage, Bar, ETA
from progressbar import ETA, Bar, Percentage, ProgressBar

widgets = ['Process - ', ETA(), ' ', Percentage(), ' ', Bar(left='[', right=']')]
bar = ProgressBar(widgets=widgets, maxval=count).start()
Expand Down
2 changes: 1 addition & 1 deletion flexget/components/ftp/ftp_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from flexget.plugin import DependencyError, PluginError

try:
from ftputil.error import FTPOSError
import ftputil
import ftputil.session
from ftputil.error import FTPOSError

imported = True
except ImportError:
Expand Down
8 changes: 6 additions & 2 deletions flexget/components/imdb/imdb_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class ImdbLookup:
(writer.imdb_id, writer.name) for writer in movie.writers
),
'imdb_mpaa_rating': 'mpaa_rating',
'imdb_plot_keywords': lambda movie: [plot_keyword.name for plot_keyword in movie.plot_keywords],
'imdb_plot_keywords': lambda movie: [
plot_keyword.name for plot_keyword in movie.plot_keywords
],
# Generic fields filled by all movie lookup plugins:
'movie_name': 'title',
'movie_year': 'year',
Expand Down Expand Up @@ -301,7 +303,9 @@ def _parse_new_movie(self, imdb_url, session):
writer = db.Writer(imdb_id, name)
movie.writers.append(writer) # pylint:disable=E1101
for name in parser.plot_keywords:
plot_keyword = session.query(db.PlotKeyword).filter(db.PlotKeyword.name == name).first()
plot_keyword = (
session.query(db.PlotKeyword).filter(db.PlotKeyword.name == name).first()
)
if not plot_keyword:
plot_keyword = db.PlotKeyword(name)
movie.plot_keywords.append(plot_keyword) # pylint:disable=E1101
Expand Down
6 changes: 4 additions & 2 deletions flexget/components/imdb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def __init__(self):
self.imdb_id = None
self.photo = None
self.mpaa_rating = ''
self.plot_keywords=[]
self.plot_keywords = []

def __str__(self):
return '<ImdbParser(name=%s,imdb_id=%s)>' % (self.name, self.imdb_id)
Expand Down Expand Up @@ -399,7 +399,9 @@ def parse(self, imdb_id, soup=None):
keyword_elem = storyline.find('h4').parent
if keyword_elem:
# The last "a" tag is a link to the full list
self.plot_keywords = [keyword_elem.text.strip() for keyword_elem in keyword_elem.find_all("a")[:-1]]
self.plot_keywords = [
keyword_elem.text.strip() for keyword_elem in keyword_elem.find_all("a")[:-1]
]

genres = data.get('genre', [])
if not isinstance(genres, list):
Expand Down
2 changes: 1 addition & 1 deletion flexget/components/irc/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from flexget.utils.tools import get_config_hash

try:
from irc_bot.simple_irc_bot import SimpleIRCBot, partial
from irc_bot import utils as irc_bot
from irc_bot.simple_irc_bot import SimpleIRCBot, partial
except ImportError as e:
irc_bot = None
SimpleIRCBot = object
Expand Down
14 changes: 7 additions & 7 deletions flexget/components/notify/notifiers/toast.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,31 @@ def windows_notify(self, title, message, config):
from win32api import GetModuleHandle, PostQuitMessage
from win32con import (
CW_USEDEFAULT,
IMAGE_ICON,
IDI_APPLICATION,
IMAGE_ICON,
LR_DEFAULTSIZE,
LR_LOADFROMFILE,
WM_DESTROY,
WM_USER,
WS_OVERLAPPED,
WS_SYSMENU,
WM_USER,
)
from win32gui import (
CreateWindow,
DestroyWindow,
LoadIcon,
LoadImage,
NIF_ICON,
NIF_INFO,
NIF_MESSAGE,
NIF_TIP,
NIM_ADD,
NIM_DELETE,
NIM_MODIFY,
WNDCLASS,
CreateWindow,
DestroyWindow,
LoadIcon,
LoadImage,
RegisterClass,
Shell_NotifyIcon,
UpdateWindow,
WNDCLASS,
)
except ImportError:
raise DependencyError(
Expand Down
2 changes: 1 addition & 1 deletion flexget/components/seen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

try:
# NOTE: Importing other plugins is discouraged!
from flexget.components.imdb.utils import is_imdb_url, extract_id
from flexget.components.imdb.utils import extract_id, is_imdb_url
except ImportError:
raise plugin.DependencyError(issued_by=__name__, missing='imdb')

Expand Down
10 changes: 4 additions & 6 deletions flexget/components/sites/sites/filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,14 @@ def get_login_cookie(self, username, password, force=False):
# get validator token
response = requests.get(BASE_URL + 'login.php')
soup = get_soup(response.content)

login_validator = soup.find("input", {"name": "validator"})

if not login_validator:
raise plugin.PluginError(
'FileList.ro could not get login validator'
)
raise plugin.PluginError('FileList.ro could not get login validator')
logger.debug('Login Validator: {}'.format(login_validator.get('value')))
logger.debug('Attempting to retrieve FileList.ro cookie')

response = requests.post(
url,
data={
Expand Down
22 changes: 17 additions & 5 deletions flexget/components/sites/sites/filelist_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from http import HTTPStatus

from loguru import logger

from flexget import plugin
from flexget.config_schema import one_or_more
from flexget.entry import Entry
Expand Down Expand Up @@ -49,7 +51,7 @@ class SearchFileList:
}

valid_extras = ['internal', 'moderated', 'freeleech', 'doubleup']

schema = {
'type': 'object',
'properties': {
Expand All @@ -76,7 +78,9 @@ def get(self, url, params):
http_status = HTTPStatus(response.status_code)
error_message = response.json().get('error', http_status.description)

raise plugin.PluginError(f'FileList request failed; err code: {http_status}; err msg: `{error_message}`')
raise plugin.PluginError(
f'FileList request failed; err code: {http_status}; err msg: `{error_message}`'
)

return response

Expand All @@ -88,7 +92,11 @@ def search(self, task, entry, config):
entries = []

# mandatory params
params = {'username': config['username'], 'passkey': config['passkey'], 'action': 'search-torrents'}
params = {
'username': config['username'],
'passkey': config['passkey'],
'action': 'search-torrents',
}

# category
if config.get('category'):
Expand Down Expand Up @@ -127,7 +135,9 @@ def search(self, task, entry, config):
if not results:
logger.verbose('No torrent found on Filelist for `{}`', search_title)
else:
logger.verbose('{} torrent(s) were found on Filelist for `{}`', len(results), search_title)
logger.verbose(
'{} torrent(s) were found on Filelist for `{}`', len(results), search_title
)

for result in results:
entry = Entry()
Expand All @@ -143,7 +153,9 @@ def search(self, task, entry, config):
entry['torrent_internal'] = bool(result['internal'])
entry['torrent_moderated'] = bool(result['moderated'])
entry['torrent_freeleech'] = bool(result['freeleech'])
entry['torrent_genres'] = [genres.strip() for genres in result['small_description'].split(',')]
entry['torrent_genres'] = [
genres.strip() for genres in result['small_description'].split(',')
]

entries.append(entry)

Expand Down
15 changes: 10 additions & 5 deletions flexget/components/sites/sites/iptorrents.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
SEARCH_URL = 'https://iptorrents.com/t?'
FREE_SEARCH_URL = 'https://iptorrents.com/t?free=on'


class UrlRewriteIPTorrents:
"""
IpTorrents urlrewriter and search plugin.
Expand Down Expand Up @@ -128,24 +129,28 @@ def search(self, task, entry, config=None):

# If there are any text categories, turn them into their id number
categories = [c if isinstance(c, int) else CATEGORIES[c] for c in categories]
category_params = {str(c):'' for c in categories if str(c)}
category_params = {str(c): '' for c in categories if str(c)}

entries = set()

for search_string in entry.get('search_strings', [entry['title']]):
search_params = {key:value for (key,value) in category_params.items()}
search_params = {key: value for (key, value) in category_params.items()}

query = normalize_unicode(search_string)
search_params.update({'q':query, 'qf':''})
search_params.update({'q': query, 'qf': ''})

logger.debug('searching with params: {}', search_params)
if config.get('free'):
req = requests.get(
FREE_SEARCH_URL, params=search_params, cookies={'uid': str(config['uid']), 'pass': config['password']}
FREE_SEARCH_URL,
params=search_params,
cookies={'uid': str(config['uid']), 'pass': config['password']},
)
else:
req = requests.get(
SEARCH_URL, params=search_params, cookies={'uid': str(config['uid']), 'pass': config['password']}
SEARCH_URL,
params=search_params,
cookies={'uid': str(config['uid']), 'pass': config['password']},
)
logger.debug('full search URL: {}', req.url)

Expand Down
15 changes: 12 additions & 3 deletions flexget/components/sites/sites/newznab.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class Newznab:
schema = {
'type': 'object',
'properties': {
'category': {'type': 'string', 'enum': ['movie', 'tvsearch', 'tv', 'music', 'book', 'all']},
'category': {
'type': 'string',
'enum': ['movie', 'tvsearch', 'tv', 'music', 'book', 'all'],
},
'url': {'type': 'string', 'format': 'url'},
'website': {'type': 'string', 'format': 'url'},
'apikey': {'type': 'string'},
Expand All @@ -49,7 +52,11 @@ def build_config(self, config):

if 'url' not in config:
if 'apikey' in config and 'website' in config:
config['params'] = {'t': config['category'], 'apikey': config['apikey'], 'extended': 1}
config['params'] = {
't': config['category'],
'apikey': config['apikey'],
'extended': 1,
}
config['url'] = f"{config['website']}/api"

return config
Expand Down Expand Up @@ -92,7 +99,9 @@ def search(self, task, entry, config=None):
return self.do_search_all(entry, task, config)
else:
entries = []
logger.warning("Work in progress. Searching for the specified category is not supported yet...")
logger.warning(
"Work in progress. Searching for the specified category is not supported yet..."
)
return entries

def do_search_tvsearch(self, arg_entry, task, config=None):
Expand Down
7 changes: 3 additions & 4 deletions flexget/components/sites/sites/site_rutracker.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# -*- coding: utf-8 -*-

from urllib.parse import parse_qs, urlencode, urlparse

from loguru import logger
from requests.exceptions import RequestException

from flexget import plugin
from flexget.components.sites.urlrewriting import UrlRewritingError
from flexget.event import event

from urllib.parse import urlparse, parse_qs, urlencode


logger = logger.bind(name='rutracker')


Expand Down Expand Up @@ -49,7 +48,7 @@ def url_rewrite(self, task, entry):
magnet = {
'xt': f"urn:btih:{topic['info_hash']}",
'tr': [f'http://bt{i}.t-ru.org/ann?magnet' for i in ['', '2', '3', '4']],
'dn': topic['topic_title']
'dn': topic['topic_title'],
}
magnet_qs = urlencode(magnet, doseq=True, safe=':')
magnet_uri = f"magnet:?{magnet_qs}"
Expand Down
6 changes: 5 additions & 1 deletion flexget/components/thetvdb/api_tvdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,11 @@ def find_series_id(name, language=None):
try:
s['firstAired'] = datetime.strptime(s['firstAired'], "%Y-%m-%d")
except ValueError:
logger.warning('Invalid firstAired date "{}" when parsing series {} ', s['firstAired'], s['seriesName'])
logger.warning(
'Invalid firstAired date "{}" when parsing series {} ',
s['firstAired'],
s['seriesName'],
)
s['firstAired'] = datetime(1970, 1, 1)
else:
s['firstAired'] = datetime(1970, 1, 1)
Expand Down
4 changes: 3 additions & 1 deletion flexget/components/trakt/trakt_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def on_task_input(self, task, config):

try:
results = (
db.get_session(config.get('account')).get(url, params={'extended': 'full'}).json()
db.get_session(config.get('account'))
.get(url, params={'extended': 'full'})
.json()
)
logger.debug('Found {} calendar entries', len(results))
except RequestException as e:
Expand Down
7 changes: 4 additions & 3 deletions flexget/plugins/cli/perf_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ def cli_perf_test(manager, options):
def imdb_query(session):
import time

from progressbar import ETA, Bar, Percentage, ProgressBar
from sqlalchemy.orm import joinedload_all
from sqlalchemy.sql.expression import select

# NOTE: importing other plugins directly is discouraged
from flexget.components.imdb.db import Movie
from flexget.plugins.cli.performance import log_query_count
from sqlalchemy.sql.expression import select
from progressbar import ProgressBar, Percentage, Bar, ETA
from sqlalchemy.orm import joinedload_all

imdb_urls = []

Expand Down
9 changes: 3 additions & 6 deletions flexget/plugins/clients/pyload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from flexget.event import event
from flexget.utils import json
from flexget.utils.template import RenderError

logger = logger.bind(name='pyload')


Expand Down Expand Up @@ -175,11 +176,7 @@ def add_entries(self, task, config):
content = json.dumps(content)

if is_pyload_ng:
url = (
entry['url']
if config.get('parse_url', self.DEFAULT_PARSE_URL)
else ''
)
url = entry['url'] if config.get('parse_url', self.DEFAULT_PARSE_URL) else ''
else:
url = (
json.dumps(entry['url'])
Expand Down Expand Up @@ -251,7 +248,7 @@ def add_entries(self, task, config):
'name': json.dumps(name.encode('ascii', 'ignore').decode()),
'links': json.dumps(urls),
'dest': json.dumps(dest),
'session': session
'session': session,
}

pid = api.post(add_package_command, data=data).text
Expand Down
Loading

0 comments on commit b623605

Please sign in to comment.