From 6cb892a811fabea5bec08fb231759aa9c2ddac11 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 9 Feb 2022 21:33:41 +0700 Subject: [PATCH] integrate auto generated subtitle cleaner --- tubearchivist/home/src/index/video.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tubearchivist/home/src/index/video.py b/tubearchivist/home/src/index/video.py index ab5c22b..4d0bfcb 100644 --- a/tubearchivist/home/src/index/video.py +++ b/tubearchivist/home/src/index/video.py @@ -113,11 +113,17 @@ class YoutubeSubtitle: self.config["application"]["videos"], subtitle["media_url"] ) response = requests.get(subtitle["url"]) + if subtitle["source"] == "auto": + parser = SubtitleParser(response.text) + parser.process() + subtitle_str_clean = parser.get_subtitle_str() + else: + subtitle_str_clean = response.text if response.ok: # create folder here for first video of channel os.makedirs(os.path.split(dest_path)[0], exist_ok=True) with open(dest_path, "w", encoding="utf-8") as subfile: - subfile.write(response.text) + subfile.write(subtitle_str_clean) else: print(f"{self.youtube_id}: failed to download subtitle")