From d514d6ea2bd1df3a15fc8cfecdb9c1a71536ceda Mon Sep 17 00:00:00 2001 From: dtlnor Date: Mon, 26 Sep 2022 02:49:30 +0900 Subject: [PATCH 1/2] fix encoding issue - windows can't read utf-8 json properly without explicit define the encoding format --- danmaku/youtube-live-chat-danmaku-ass.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/danmaku/youtube-live-chat-danmaku-ass.py b/danmaku/youtube-live-chat-danmaku-ass.py index bb62377..f53421a 100755 --- a/danmaku/youtube-live-chat-danmaku-ass.py +++ b/danmaku/youtube-live-chat-danmaku-ass.py @@ -547,8 +547,8 @@ def update_common_props(renderer): def main(): - input_buffer = sys.stdin if sys.argv[1] == '-' else open(sys.argv[1], 'r') - output_buffer = sys.stdout if sys.argv[2] == '-' else open(sys.argv[2], 'w') + input_buffer = sys.stdin if sys.argv[1] == '-' else open(sys.argv[1], 'r', encoding="utf-8") + output_buffer = sys.stdout if sys.argv[2] == '-' else open(sys.argv[2], 'w', encoding="utf-8") ass_generator = DanmakuASSGenerator() parser = YoutubeLiveChatReplayParser() From 1e861954f8e52b04c6dfbaf714342506e77d8bf4 Mon Sep 17 00:00:00 2001 From: dtlnor Date: Fri, 4 Nov 2022 12:19:01 +0900 Subject: [PATCH 2/2] explicit encoding for all json read/write --- danmaku/youtube-live-chat-danmaku-ass.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/danmaku/youtube-live-chat-danmaku-ass.py b/danmaku/youtube-live-chat-danmaku-ass.py index f53421a..2421ff1 100755 --- a/danmaku/youtube-live-chat-danmaku-ass.py +++ b/danmaku/youtube-live-chat-danmaku-ass.py @@ -380,12 +380,12 @@ def _load_mapped_emoji(self): path = self._get_mapped_emoji_path() if not os.path.isfile(path): return {} - with open(path) as f: + with open(path, encoding='utf-8') as f: return json.loads(f.read()) def _save_mapped_emoji(self): path = self._get_mapped_emoji_path() - with open(path, 'w') as f: + with open(path, 'w', encoding='utf-8') as f: f.write(json.dumps(self._url_by_emoji)) def _get_mapped_emoji_path(self):