From 15a64cf198e73b554faba6fec28791eb0c7ef80d Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sun, 26 Nov 2023 22:07:23 +0100 Subject: [PATCH] Black cosmetic fixes --- lib/svtplay_dl/__version__.py | 7 ++++++- lib/svtplay_dl/fetcher/dash.py | 1 - lib/svtplay_dl/fetcher/hls.py | 7 ++++++- lib/svtplay_dl/fetcher/m3u8.py | 6 ------ lib/svtplay_dl/postprocess/__init__.py | 3 ++- lib/svtplay_dl/service/mtvnn.py | 2 -- lib/svtplay_dl/service/vimeo.py | 1 - setversion.py | 2 +- versioneer.py | 7 ++++++- 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/svtplay_dl/__version__.py b/lib/svtplay_dl/__version__.py index a472bb1..982141b 100644 --- a/lib/svtplay_dl/__version__.py +++ b/lib/svtplay_dl/__version__.py @@ -86,7 +86,12 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env= dispcmd = str([command] + args) # remember shell=False, so use git.cmd on windows, not just git process = subprocess.Popen( - [command] + args, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=(subprocess.PIPE if hide_stderr else None), **popen_kwargs + [command] + args, + cwd=cwd, + env=env, + stdout=subprocess.PIPE, + stderr=(subprocess.PIPE if hide_stderr else None), + **popen_kwargs, ) break except OSError: diff --git a/lib/svtplay_dl/fetcher/dash.py b/lib/svtplay_dl/fetcher/dash.py index 12ab38d..2781cf4 100644 --- a/lib/svtplay_dl/fetcher/dash.py +++ b/lib/svtplay_dl/fetcher/dash.py @@ -392,7 +392,6 @@ class DASH(VideoRetriever): file_d.write(data.content) eta = ETA(total_size) while bytes_so_far < total_size: - if not self.config.get("silent"): eta.update(bytes_so_far) progressbar(total_size, bytes_so_far, "".join(["ETA: ", str(eta)])) diff --git a/lib/svtplay_dl/fetcher/hls.py b/lib/svtplay_dl/fetcher/hls.py index 3cf990c..d774395 100644 --- a/lib/svtplay_dl/fetcher/hls.py +++ b/lib/svtplay_dl/fetcher/hls.py @@ -173,7 +173,12 @@ def _hlsparse(config, text, url, output, **kwargs): if subfix: subfix = f"{n[1]}-caption" yield from subtitle_probe( - copy.copy(config), get_full_url(n[0], url), output=copy.copy(output), subfix=subfix, cookies=cookies, **kwargs + copy.copy(config), + get_full_url(n[0], url), + output=copy.copy(output), + subfix=subfix, + cookies=cookies, + **kwargs, ) elif m3u8.media_segment: diff --git a/lib/svtplay_dl/fetcher/m3u8.py b/lib/svtplay_dl/fetcher/m3u8.py index ae9d3fe..c4e9b8a 100644 --- a/lib/svtplay_dl/fetcher/m3u8.py +++ b/lib/svtplay_dl/fetcher/m3u8.py @@ -20,7 +20,6 @@ class M3U8: TAG_TYPES = {"MEDIA_SEGMENT": 0, "MEDIA_PLAYLIST": 1, "MASTER_PLAYLIST": 2} def __init__(self, data): - self.version = None self.media_segment = [] @@ -55,7 +54,6 @@ class M3U8: if not l: continue elif l.startswith("#EXT"): - info = {} tag, attr = _get_tag_attribute(l) if tag == "EXT-X-VERSION": @@ -63,7 +61,6 @@ class M3U8: # 4.3.2. Media Segment Tags elif tag in M3U8.MEDIA_SEGMENT_TAGS: - tag_type = M3U8.TAG_TYPES["MEDIA_SEGMENT"] # 4.3.2.1. EXTINF if tag == "EXTINF": @@ -124,7 +121,6 @@ class M3U8: # 4.3.3. Media Playlist Tags elif tag in M3U8.MEDIA_PLAYLIST_TAGS: - tag_type = M3U8.TAG_TYPES["MEDIA_PLAYLIST"] # 4.3.3.1. EXT-X-TARGETDURATION if tag == "EXT-X-TARGETDURATION": @@ -154,7 +150,6 @@ class M3U8: # 4.3.4. Master Playlist Tags elif tag in M3U8.MASTER_PLAYLIST_TAGS: - tag_type = M3U8.TAG_TYPES["MASTER_PLAYLIST"] # 4.3.4.1. EXT-X-MEDIA if tag == "EXT-X-MEDIA": @@ -185,7 +180,6 @@ class M3U8: # 4.3.5. Media or Master Playlist Tags elif tag in M3U8.MEDIA_OR_MASTER_PLAYLIST_TAGS: - tag_type = M3U8.TAG_TYPES["MEDIA_PLAYLIST"] # 4.3.5.1. EXT-X-INDEPENDENT-SEGMENTS if tag == "EXT-X-INDEPENDENT-SEGMENTS": diff --git a/lib/svtplay_dl/postprocess/__init__.py b/lib/svtplay_dl/postprocess/__init__.py index 8977c99..8b36669 100644 --- a/lib/svtplay_dl/postprocess/__init__.py +++ b/lib/svtplay_dl/postprocess/__init__.py @@ -186,7 +186,8 @@ def _sublanguage(stream, config, subfixes): _ = parse(self) random_sentences = " ".join(sample(_, len(_) if len(_) < 8 else 8)).replace("\r\n", "") url = "https://svtplay-dl.se/langdetect/" - headers = {"User-Agent": f"{FIREFOX_UA} {platform.machine()}"} + bits = "64" if sys.maxsize > 2**32 else "32" + headers = {"User-Agent": f"{FIREFOX_UA} {platform.machine()} {platform.platform()} {bits}"} try: r = post(url, json={"query": random_sentences}, headers=headers, timeout=30) if r.status_code == codes.ok: diff --git a/lib/svtplay_dl/service/mtvnn.py b/lib/svtplay_dl/service/mtvnn.py index f9dc6ce..acdc6c4 100644 --- a/lib/svtplay_dl/service/mtvnn.py +++ b/lib/svtplay_dl/service/mtvnn.py @@ -56,7 +56,6 @@ class Mtvnn(Service, OpenGraphThumbMixin): and xml.find("./video").find("item").find("rendition") is not None and xml.find("./video").find("item").find("rendition").find("src") is not None ): - hls_url = xml.find("./video").find("item").find("rendition").find("src").text stream = hlsparse(self.config, self.http.request("get", hls_url), hls_url, output=self.output) for key in list(stream.keys()): @@ -144,6 +143,5 @@ class MtvMusic(Service, OpenGraphThumbMixin): and xml.find("./video").find("item").find("rendition") is not None and xml.find("./video").find("item").find("rendition").find("src") is not None ): - hls_url = xml.find("./video").find("item").find("rendition").find("src").text yield from hlsparse(self.config, self.http.request("get", hls_url), hls_url, output=self.output) diff --git a/lib/svtplay_dl/service/vimeo.py b/lib/svtplay_dl/service/vimeo.py index def3f25..47a506d 100644 --- a/lib/svtplay_dl/service/vimeo.py +++ b/lib/svtplay_dl/service/vimeo.py @@ -32,7 +32,6 @@ class Vimeo(Service, OpenGraphThumbMixin): player_data = self.http.request("get", player_url).text if player_data: - jsondata = json.loads(player_data) if ("hls" in jsondata["request"]["files"]) and ("fastly_skyfire" in jsondata["request"]["files"]["hls"]["cdns"]): diff --git a/setversion.py b/setversion.py index 4a7a43b..e1816f5 100644 --- a/setversion.py +++ b/setversion.py @@ -14,5 +14,5 @@ with open(initfile) as fd: data = fd.read() newstring = re.sub("(__version__ = get_version[^\n]+)", f'__version__ = "{version}"', data) -with open(initfile, "wt") as fd: +with open(initfile, "w") as fd: fd.write(newstring) diff --git a/versioneer.py b/versioneer.py index a6d26ca..7a8d1a5 100644 --- a/versioneer.py +++ b/versioneer.py @@ -446,7 +446,12 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env= dispcmd = str([command] + args) # remember shell=False, so use git.cmd on windows, not just git process = subprocess.Popen( - [command] + args, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=(subprocess.PIPE if hide_stderr else None), **popen_kwargs + [command] + args, + cwd=cwd, + env=env, + stdout=subprocess.PIPE, + stderr=(subprocess.PIPE if hide_stderr else None), + **popen_kwargs, ) break except OSError: