Pass shaka-packager & aria CTRL+C to caller as KeyboardInterrupt()s

This commit is contained in:
rlaphoenix 2023-02-28 17:14:02 +00:00
parent ad1990cc42
commit 8365d798a4
2 changed files with 56 additions and 44 deletions

View File

@ -83,6 +83,7 @@ def aria2c(
return aria2c(uri, out, headers, pproxy_)
arguments += ["--all-proxy", proxy]
try:
p = subprocess.Popen(
[executable, *arguments],
stdin=subprocess.PIPE,
@ -94,7 +95,6 @@ def aria2c(
),
universal_newlines=True
)
p._stdin_write(uri) # noqa
if progress:
@ -130,6 +130,15 @@ def aria2c(
if p.returncode != 0:
raise subprocess.CalledProcessError(p.returncode, arguments)
except ConnectionResetError:
# interrupted while passing URI to download
raise KeyboardInterrupt()
except subprocess.CalledProcessError as e:
if e.returncode in (7, 0xC000013A):
# 7 is when Aria2(c) handled the CTRL+C
# 0xC000013A is when it never got the chance to
raise KeyboardInterrupt()
raise
return p.returncode

View File

@ -234,6 +234,7 @@ class Widevine:
decrypted_path = path.with_suffix(f".decrypted{path.suffix}")
config.directories.temp.mkdir(parents=True, exist_ok=True)
try:
subprocess.check_call([
executable,
@ -253,6 +254,8 @@ class Widevine:
"--temp_dir", config.directories.temp
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except subprocess.CalledProcessError as e:
if e.returncode == 0xC000013A: # STATUS_CONTROL_C_EXIT
raise KeyboardInterrupt()
raise subprocess.SubprocessError(f"Failed to Decrypt! Shaka Packager Error: {e}")
path.unlink()