From 10e365f695adcb5ee2f90fbc7c1100ac109acc89 Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Tue, 27 Apr 2021 19:44:09 +0200 Subject: [PATCH] pyupgrade fixes --- .pre-commit-config.yaml | 6 +++--- lib/svtplay_dl/__init__.py | 2 +- lib/svtplay_dl/__version__.py | 2 +- lib/svtplay_dl/fetcher/dash.py | 2 +- lib/svtplay_dl/postprocess/__init__.py | 12 ++++++------ lib/svtplay_dl/service/aftonbladet.py | 2 +- lib/svtplay_dl/service/dplay.py | 10 +++++----- lib/svtplay_dl/service/facebook.py | 2 +- lib/svtplay_dl/service/flowonline.py | 2 +- lib/svtplay_dl/service/lemonwhale.py | 2 +- lib/svtplay_dl/service/mtvnn.py | 2 +- lib/svtplay_dl/service/nrk.py | 2 +- lib/svtplay_dl/service/oppetarkiv.py | 2 +- lib/svtplay_dl/service/picsearch.py | 4 ++-- lib/svtplay_dl/service/pokemon.py | 2 +- lib/svtplay_dl/service/svtplay.py | 4 ++-- lib/svtplay_dl/service/youplay.py | 2 +- lib/svtplay_dl/subtitle/__init__.py | 12 ++++++------ lib/svtplay_dl/utils/getmedia.py | 2 +- lib/svtplay_dl/utils/http.py | 2 +- lib/svtplay_dl/utils/output.py | 4 ++-- lib/svtplay_dl/utils/stream.py | 2 +- versioneer.py | 4 ++-- 23 files changed, 43 insertions(+), 43 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0fd0f78..f400750 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,16 +15,16 @@ repos: - id: black language_version: python3 - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + rev: 3.9.1 hooks: - id: flake8 - repo: https://github.com/asottile/pyupgrade - rev: v2.10.0 + rev: v2.13.0 hooks: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/asottile/reorder_python_imports - rev: v2.4.0 + rev: v2.5.0 hooks: - id: reorder-python-imports - repo: https://github.com/asottile/add-trailing-comma diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index c6f1fe9..e561f49 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -72,5 +72,5 @@ def main(): except KeyboardInterrupt: print("") except (yaml.YAMLError, yaml.MarkedYAMLError) as e: - logging.error("Your settings file(s) contain invalid YAML syntax! Please fix and restart!, {}".format(str(e))) + logging.error(f"Your settings file(s) contain invalid YAML syntax! Please fix and restart!, {str(e)}") sys.exit(2) diff --git a/lib/svtplay_dl/__version__.py b/lib/svtplay_dl/__version__.py index 03af7cb..5c290f7 100644 --- a/lib/svtplay_dl/__version__.py +++ b/lib/svtplay_dl/__version__.py @@ -116,7 +116,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): root = os.path.dirname(root) # up a level if verbose: - print("Tried directories {} but none started with prefix {}".format(str(rootdirs), parentdir_prefix)) + print(f"Tried directories {str(rootdirs)} but none started with prefix {parentdir_prefix}") raise NotThisMethod("rootdir doesn't start with parentdir_prefix") diff --git a/lib/svtplay_dl/fetcher/dash.py b/lib/svtplay_dl/fetcher/dash.py index 3b3bac1..b91aa63 100644 --- a/lib/svtplay_dl/fetcher/dash.py +++ b/lib/svtplay_dl/fetcher/dash.py @@ -204,7 +204,7 @@ def dashparse(config, res, url, **kwargs): streams[0] = ServiceError(f"Can't read DASH playlist. {res.status_code}") return streams if len(res.text) < 1: - streams[0] = ServiceError("Can't read DASH playlist. {}, size: {}".format(res.status_code, len(res.text))) + streams[0] = ServiceError(f"Can't read DASH playlist. {res.status_code}, size: {len(res.text)}") return streams return _dashparse(config, res.text, url, res.cookies, **kwargs) diff --git a/lib/svtplay_dl/postprocess/__init__.py b/lib/svtplay_dl/postprocess/__init__.py index 6c73e59..a405a7e 100644 --- a/lib/svtplay_dl/postprocess/__init__.py +++ b/lib/svtplay_dl/postprocess/__init__.py @@ -70,7 +70,7 @@ class postprocess: ] if self.subfixes and len(self.subfixes) >= 2: for subfix in self.subfixes: - subfile = "{}.srt".format(name + subfix) + subfile = f"{name + subfix}.srt" cmd += ["-i", subfile] else: subfile = f"{name}.srt" @@ -86,7 +86,7 @@ class postprocess: logging.info("Muxing done, removing the old files.") if self.subfixes and len(self.subfixes) >= 2: for subfix in self.subfixes: - subfile = "{}.srt".format(name + subfix) + subfile = f"{name + subfix}.srt" os.remove(subfile) else: os.remove(subfile) @@ -151,7 +151,7 @@ class postprocess: ] if self.subfixes and len(self.subfixes) >= 2: for subfix in self.subfixes: - subfile = "{}.srt".format(name + subfix) + subfile = f"{name + subfix}.srt" cmd += ["-i", subfile] else: subfile = f"{name}.srt" @@ -172,7 +172,7 @@ class postprocess: if self.config.get("merge_subtitle") and not self.config.get("subtitle"): if self.subfixes and len(self.subfixes) >= 2: for subfix in self.subfixes: - subfile = "{}.srt".format(name + subfix) + subfile = f"{name + subfix}.srt" os.remove(subfile) else: os.remove(subfile) @@ -258,10 +258,10 @@ def _sublanguage(stream, config, subfixes): subfix = subfix.strip("-") langs += [exceptions[subfix]] continue - subfile = "{}.srt".format(os.path.splitext(formatname(stream.output, config, stream.output_extention))[0] + subfix) + subfile = f"{os.path.splitext(formatname(stream.output, config, stream.output_extention))[0] + subfix}.srt" langs += [query(subfile)] else: - subfile = "{}.srt".format(os.path.splitext(formatname(stream.output, config, stream.output_extention))[0]) + subfile = f"{os.path.splitext(formatname(stream.output, config, stream.output_extention))[0]}.srt" langs += [query(subfile)] if len(langs) >= 2: logging.info("Language codes: " + ", ".join(langs)) diff --git a/lib/svtplay_dl/service/aftonbladet.py b/lib/svtplay_dl/service/aftonbladet.py index eb8f3ab..940511d 100644 --- a/lib/svtplay_dl/service/aftonbladet.py +++ b/lib/svtplay_dl/service/aftonbladet.py @@ -43,7 +43,7 @@ class Aftonbladet(Service): try: janson = json.loads(match.group(1)) except json.decoder.JSONDecodeError: - yield ServiceError("Can't decode api request: {}".format(match.group(1))) + yield ServiceError(f"Can't decode api request: {match.group(1)}") return videos = self._get_video(janson) diff --git a/lib/svtplay_dl/service/dplay.py b/lib/svtplay_dl/service/dplay.py index 5c5bd20..69cad2c 100644 --- a/lib/svtplay_dl/service/dplay.py +++ b/lib/svtplay_dl/service/dplay.py @@ -38,7 +38,7 @@ class Dplay(Service): if not match: yield ServiceError("Can't detect 'kanaler'") return - path = "/channels/{}".format(match.group(1)) + path = f"/channels/{match.group(1)}" url = f"https://disco-api.{self.domain}/content{path}" channel = True self.config.set("live", True) @@ -47,7 +47,7 @@ class Dplay(Service): if not match: yield ServiceError("Can't find program url") return - path = "/shows/{}".format(match.group(2)) + path = f"/shows/{match.group(2)}" url = f"https://disco-api.{self.domain}/content{path}" res = self.http.get(url, headers={"x-disco-client": "WEB:UNKNOWN:dplay-client:0.0.1"}) programid = res.json()["data"]["id"] @@ -70,7 +70,7 @@ class Dplay(Service): return else: match = re.search("(videos|videoer)/(.*)$", parse.path) - url = "https://disco-api.{}/content/videos/{}".format(self.domain, match.group(2)) + url = f"https://disco-api.{self.domain}/content/videos/{match.group(2)}" res = self.http.get(url, headers={"x-disco-client": "WEB:UNKNOWN:dplay-client:0.0.1"}) janson = res.json() if "errors" in janson: @@ -142,7 +142,7 @@ class Dplay(Service): if self.domain in ["discoveryplus.no", "discoveryplus.dk"]: urllocal = "mer" - url = "http://disco-api.{}/cms/routes/program{}/{}?decorators=viewingHistory&include=default".format(self.domain, urllocal, match.group(2)) + url = f"http://disco-api.{self.domain}/cms/routes/program{urllocal}/{match.group(2)}?decorators=viewingHistory&include=default" res = self.http.get(url) if res.status_code > 400: logging.error("Cant find any videos. wrong url?") @@ -200,7 +200,7 @@ class Dplay(Service): def _token(self) -> bool: # random device id for cookietoken deviceid = hashlib.sha256(bytes(int(random.random() * 1000))).hexdigest() - url = "https://disco-api.{}/token?realm={}&deviceId={}&shortlived=true".format(self.domain, REALMS[self.domain], deviceid) + url = f"https://disco-api.{self.domain}/token?realm={REALMS[self.domain]}&deviceId={deviceid}&shortlived=true" res = self.http.get(url) if res.status_code >= 400: return False diff --git a/lib/svtplay_dl/service/facebook.py b/lib/svtplay_dl/service/facebook.py index e404a85..aca0dbd 100644 --- a/lib/svtplay_dl/service/facebook.py +++ b/lib/svtplay_dl/service/facebook.py @@ -19,7 +19,7 @@ class Facebook(Service, OpenGraphThumbMixin): if not match: yield ServiceError("Cant find params info. video need to be public.") return - data2 = json.loads('["{}"]'.format(match.group(1))) + data2 = json.loads(f'["{match.group(1)}"]') data2 = json.loads(unquote_plus(data2[0])) if "sd_src_no_ratelimit" in data2["video_data"]["progressive"][0]: yield HTTP(copy.copy(self.config), data2["video_data"]["progressive"][0]["sd_src_no_ratelimit"], "240", output=self.output) diff --git a/lib/svtplay_dl/service/flowonline.py b/lib/svtplay_dl/service/flowonline.py index 9192018..a23fcbb 100644 --- a/lib/svtplay_dl/service/flowonline.py +++ b/lib/svtplay_dl/service/flowonline.py @@ -21,7 +21,7 @@ class Flowonline(Service, OpenGraphThumbMixin): return parse = urlparse(self.url) - url = "{}://{}{}".format(parse.scheme, parse.netloc, match.group(1)) + url = f"{parse.scheme}://{parse.netloc}{match.group(1)}" data = self.http.get(url) diff --git a/lib/svtplay_dl/service/lemonwhale.py b/lib/svtplay_dl/service/lemonwhale.py index d36a16a..1d36667 100644 --- a/lib/svtplay_dl/service/lemonwhale.py +++ b/lib/svtplay_dl/service/lemonwhale.py @@ -28,7 +28,7 @@ class Lemonwhale(Service): for n in list(streams.keys()): yield streams[n] - url = "http://ljsp.lwcdn.com/web/public/video.json?id={}&delivery=hls".format(decode_html_entities(vid)) + url = f"http://ljsp.lwcdn.com/web/public/video.json?id={decode_html_entities(vid)}&delivery=hls" data = self.http.request("get", url).text jdata = json.loads(data) if "videos" in jdata: diff --git a/lib/svtplay_dl/service/mtvnn.py b/lib/svtplay_dl/service/mtvnn.py index 54c333c..e7b0860 100644 --- a/lib/svtplay_dl/service/mtvnn.py +++ b/lib/svtplay_dl/service/mtvnn.py @@ -127,7 +127,7 @@ class MtvMusic(Service, OpenGraphThumbMixin): try: janson = json.loads(match.group(1)) except Exception: - yield ServiceError("Can't decode api request: {}".format(match.group(1))) + yield ServiceError(f"Can't decode api request: {match.group(1)}") return parse = urlparse(self.url) diff --git a/lib/svtplay_dl/service/nrk.py b/lib/svtplay_dl/service/nrk.py index f389104..c95ad9b 100644 --- a/lib/svtplay_dl/service/nrk.py +++ b/lib/svtplay_dl/service/nrk.py @@ -29,7 +29,7 @@ class Nrk(Service, OpenGraphThumbMixin): if not match: yield ServiceError("Cant find apiurl.") return - dataurl = "{}/mediaelement/{}".format(match.group(1), video_id) + dataurl = f"{match.group(1)}/mediaelement/{video_id}" data = self.http.request("get", dataurl).text data = json.loads(data) manifest_url = data["mediaUrl"] diff --git a/lib/svtplay_dl/service/oppetarkiv.py b/lib/svtplay_dl/service/oppetarkiv.py index d874732..138ebba 100644 --- a/lib/svtplay_dl/service/oppetarkiv.py +++ b/lib/svtplay_dl/service/oppetarkiv.py @@ -126,7 +126,7 @@ class OppetArkiv(Service, OpenGraphThumbMixin): for match in regex.finditer(data): if n == self.config.get("all_last"): break - episodes.append("http://www.oppetarkiv.se{}".format(match.group(1))) + episodes.append(f"http://www.oppetarkiv.se{match.group(1)}") n += 1 page += 1 diff --git a/lib/svtplay_dl/service/picsearch.py b/lib/svtplay_dl/service/picsearch.py index e3392e5..e3ea927 100644 --- a/lib/svtplay_dl/service/picsearch.py +++ b/lib/svtplay_dl/service/picsearch.py @@ -82,7 +82,7 @@ class Picsearch(Service, OpenGraphThumbMixin): if not match: match = re.search('iframe src="(//csp.screen9.com[^"]+)"', self.get_urldata()) if match: - url = "http:{}".format(match.group(1)) + url = f"http:{match.group(1)}" data = self.http.request("get", url) self.backupapi = url match = re.search(r"picsearch_ajax_auth = '([^']+)'", data.text) @@ -111,7 +111,7 @@ class Picsearch(Service, OpenGraphThumbMixin): if not match: match = re.search('iframe src="(//csp.screen9.com[^"]+)"', self.get_urldata()) if match: - url = "http:{}".format(match.group(1)) + url = f"http:{match.group(1)}" data = self.http.request("get", url) match = re.search(r"mediaid: '([^']+)'", data.text) if not match: diff --git a/lib/svtplay_dl/service/pokemon.py b/lib/svtplay_dl/service/pokemon.py index 5c0aaff..fad7c53 100644 --- a/lib/svtplay_dl/service/pokemon.py +++ b/lib/svtplay_dl/service/pokemon.py @@ -19,7 +19,7 @@ class Pokemon(Service, OpenGraphThumbMixin): yield ServiceError("Cant county code") return - res = self.http.get("http://www.pokemon.com/api/pokemontv/channels?region={}".format(match.group(1))) + res = self.http.get(f"http://www.pokemon.com/api/pokemontv/channels?region={match.group(1)}") janson = res.json() match = re.search('data-video-season="([0-9]+)"', data) season = match.group(1) diff --git a/lib/svtplay_dl/service/svtplay.py b/lib/svtplay_dl/service/svtplay.py index ae5b5ef..a60a50f 100644 --- a/lib/svtplay_dl/service/svtplay.py +++ b/lib/svtplay_dl/service/svtplay.py @@ -246,8 +246,8 @@ class Svtplay(Service, MetadataThumbMixin): if season_nr is None or episode_nr is None: return season, episode - season = "{:02d}".format(int(season_nr)) - episode = "{:02d}".format(int(episode_nr)) + season = f"{int(season_nr):02d}" + episode = f"{int(episode_nr):02d}" return season, episode diff --git a/lib/svtplay_dl/service/youplay.py b/lib/svtplay_dl/service/youplay.py index 12b6c7d..44f5471 100644 --- a/lib/svtplay_dl/service/youplay.py +++ b/lib/svtplay_dl/service/youplay.py @@ -21,7 +21,7 @@ class Youplay(Service, OpenGraphThumbMixin): yield ServiceError(f"Cant find video info for {self.url}") return - data = self.http.request("get", "http:{}".format(match.group(1)).content) + data = self.http.request("get", f"http:{match.group(1)}".content) match = re.search(r'decodeURIComponent\("([^"]+)"\)\)', data) if not match: yield ServiceError("Can't decode video info") diff --git a/lib/svtplay_dl/subtitle/__init__.py b/lib/svtplay_dl/subtitle/__init__.py index 73723d8..3541399 100644 --- a/lib/svtplay_dl/subtitle/__init__.py +++ b/lib/svtplay_dl/subtitle/__init__.py @@ -149,7 +149,7 @@ class subtitle: line = "" for txt in text.itertext(): line += f"{txt}" - all += "{}\n".format(decode_html_entities(line.lstrip())) + all += f"{decode_html_entities(line.lstrip())}\n" subs += "{}\n{} --> {}\n{}\n".format(n, timecolon(sub.attrib["TimeIn"]), timecolon(sub.attrib["TimeOut"]), all) subs = re.sub("&", r"&", subs) return subs @@ -173,7 +173,7 @@ class subtitle: if sync: if int(sync.group(1)) != int(timea): if data and data != " ": - subs += "{}\n{} --> {}\n".format(number, timestr(timea), timestr(sync.group(1))) + subs += f"{number}\n{timestr(timea)} --> {timestr(sync.group(1))}\n" text = "%s\n" % TAG_RE.sub("", data.replace("
", "\n")) text = decode_html_entities(text) if text[len(text) - 2] != "\n": @@ -310,7 +310,7 @@ class subtitle: ha = strdate(subs[-1][0]) ha3 = strdate(item) second = str2sec(ha3.group(2)) + time - subs[-1][0] = "{} --> {}".format(ha.group(1), sec2str(second)) + subs[-1][0] = f"{ha.group(1)} --> {sec2str(second)}" skip = True pre_date_skip = False continue @@ -322,7 +322,7 @@ class subtitle: skip = False first = str2sec(has_date.group(1)) + time second = str2sec(has_date.group(2)) + time - sub.append("{} --> {}".format(sec2str(first), sec2str(second))) + sub.append(f"{sec2str(first)} --> {sec2str(second)}") several_items = True pre_date_skip = False elif has_date is None and skip is False and pre_date_skip is False: @@ -420,7 +420,7 @@ def timestr(msec): def timecolon(data): match = re.search(r"(\d+:\d+:\d+):(\d+)", data) - return "{},{}".format(match.group(1), match.group(2)) + return f"{match.group(1)},{match.group(2)}" def norm(name): @@ -452,7 +452,7 @@ def strdate(datestring): def sec2str(seconds): m, s = divmod(seconds, 60) h, m = divmod(m, 60) - return "{:02d}:{:02d}:{:06.3f}".format(int(h), int(m), s) + return f"{int(h):02d}:{int(m):02d}:{s:06.3f}" def str2sec(string): diff --git a/lib/svtplay_dl/utils/getmedia.py b/lib/svtplay_dl/utils/getmedia.py index 569bd47..e531975 100644 --- a/lib/svtplay_dl/utils/getmedia.py +++ b/lib/svtplay_dl/utils/getmedia.py @@ -192,7 +192,7 @@ def get_one_media(stream): errormsg = None for exc in error: if errormsg: - errormsg = "{}. {}".format(errormsg, str(exc)) + errormsg = f"{errormsg}. {str(exc)}" else: errormsg = str(exc) if errormsg: diff --git a/lib/svtplay_dl/utils/http.py b/lib/svtplay_dl/utils/http.py index 85d173f..211ec2b 100644 --- a/lib/svtplay_dl/utils/http.py +++ b/lib/svtplay_dl/utils/http.py @@ -72,7 +72,7 @@ def get_full_url(url, srcurl): return url if url[0] == "/": baseurl = re.search(r"^(http[s]{0,1}://[^/]+)/", srcurl) - return "{}{}".format(baseurl.group(1), url) + return f"{baseurl.group(1)}{url}" # remove everything after last / in the path of the URL baseurl = re.sub(r"^([^\?]+)/[^/]*(\?.*)?$", r"\1/", srcurl) diff --git a/lib/svtplay_dl/utils/output.py b/lib/svtplay_dl/utils/output.py index e450098..012cbdd 100644 --- a/lib/svtplay_dl/utils/output.py +++ b/lib/svtplay_dl/utils/output.py @@ -158,10 +158,10 @@ def _formatname(output, config, extension): if key == "title" and output[key]: name = name.replace("{title}", filenamify(output[key])) if key == "season" and output[key]: - number = "{:02d}".format(int(output[key])) + number = f"{int(output[key]):02d}" name = name.replace("{season}", number) if key == "episode" and output[key]: - number = "{:02d}".format(int(output[key])) + number = f"{int(output[key]):02d}" name = name.replace("{episode}", number) if key == "episodename" and output[key]: name = name.replace("{episodename}", filenamify(output[key])) diff --git a/lib/svtplay_dl/utils/stream.py b/lib/svtplay_dl/utils/stream.py index 53e65f4..66a6d59 100644 --- a/lib/svtplay_dl/utils/stream.py +++ b/lib/svtplay_dl/utils/stream.py @@ -120,7 +120,7 @@ def select_quality(config, streams): # If none remains, the bitrate filtering was too tight. if len(wanted) == 0: data = sort_quality(streams) - quality = ", ".join("{} ({})".format(str(x), str(y)) for x, y in data) + quality = ", ".join(f"{str(x)} ({str(y)})" for x, y in data) raise error.UIException("Can't find that quality. Try one of: %s (or " "try --flexible-quality)" % quality) http = HTTP(config) diff --git a/versioneer.py b/versioneer.py index b77ecfb..e9a14d1 100644 --- a/versioneer.py +++ b/versioneer.py @@ -324,7 +324,7 @@ def get_root(): me_dir = os.path.normcase(os.path.splitext(me)[0]) vsr_dir = os.path.normcase(os.path.splitext(versioneer_py)[0]) if me_dir != vsr_dir: - print("Warning: build in {} is using versioneer.py from {}".format(os.path.dirname(me), versioneer_py)) + print(f"Warning: build in {os.path.dirname(me)} is using versioneer.py from {versioneer_py}") except NameError: pass return root @@ -1159,7 +1159,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): root = os.path.dirname(root) # up a level if verbose: - print("Tried directories {} but none started with prefix {}".format(str(rootdirs), parentdir_prefix)) + print(f"Tried directories {str(rootdirs)} but none started with prefix {parentdir_prefix}") raise NotThisMethod("rootdir doesn't start with parentdir_prefix")