From 47700aee5e829749a24aa19c8d92be9cc0ff68a0 Mon Sep 17 00:00:00 2001 From: girst Date: Fri, 7 Aug 2020 21:40:25 +0200 Subject: [PATCH] fix writing youtubedown (unicode chars) the cron job runs in LANG=C, so python defaults to ASCII encoding. also redownload youtubedown if the on-disk size if 0 (e.g. due to this bug) --- app/common/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/common/utils.py b/app/common/utils.py index 9272175..0893295 100755 --- a/app/common/utils.py +++ b/app/common/utils.py @@ -197,7 +197,8 @@ def ytdown_guess(cipher_id, verbose, force): # update youtubedown once a week: if force or not os.path.isfile(ytdown) or \ - os.stat(ytdown).st_mtime < time.time()-7*24*60*60: + os.stat(ytdown).st_mtime < time.time()-7*24*60*60 or \ + os.stat(ytdown).st_size == 0: # if previous write failed if verbose >= 2: sys.stderr.write('downloading youtubedown\n') r = requests.get("https://www.jwz.org/hacks/youtubedown") # UA sniffing! @@ -212,7 +213,7 @@ def ytdown_guess(cipher_id, verbose, force): # using it as a module: contents = "\n".join(r.text.splitlines()[:-2] + ["1;"]) - with open(ytdown, 'w') as f: + with open(ytdown, 'w', encoding='utf-8') as f: f.write(contents) perl = subprocess.run( -- 2.39.3