From 9f6741484fb40561b0557f3cabca235732e49595 Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 15 Aug 2020 23:27:39 +0200 Subject: [PATCH] don't crash cipher util when youtubedown can't decode cipher --- app/common/utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/common/utils.py b/app/common/utils.py index 0893295..fae03c8 100755 --- a/app/common/utils.py +++ b/app/common/utils.py @@ -155,12 +155,16 @@ def refresh_cipher(verbose=1, force=False): (cipher_id,) = re.match(r"/s/player/(.*?)\.js", new_url).groups() sts, algo = ytdown_guess(cipher_id, verbose, force) + if not sts or not algo: + return False c.execute(""" INSERT OR REPLACE INTO cipher (rowid, url, sts, algorithm) VALUES (0,?,?,?) """, (new_url, sts, algo)) + return True + def find_player_url(verbose, id="jNQXAC9IVRw"): """ Extract the player.js URL, which can be passed to youtubedown. @@ -224,11 +228,16 @@ def ytdown_guess(cipher_id, verbose, force): ], stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, - stderr=subprocess.DEVNULL + stderr=subprocess.PIPE ) + if perl.returncode > 0: + if verbose: + sys.stderr.write(f'FAILED guess_cipher (exit:{perl.returncode}):\n') + sys.stderr.write(perl.stderr.decode()) + return None, None sts, algo = perl.stdout.decode('ascii').strip().split(" ", 1) if verbose >= 2: - sys.stderr.write(f'sts, algo = {sts}, {algo} (exit:{perl.returncode})\n') + sys.stderr.write(f'sts, algo = {sts}, {algo}\n') return sts, algo -- 2.39.3