integrate auto generated subtitle cleaner

This commit is contained in:
simon 2022-02-09 21:33:41 +07:00
parent 5f6158243e
commit 6cb892a811
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -113,11 +113,17 @@ class YoutubeSubtitle:
self.config["application"]["videos"], subtitle["media_url"] self.config["application"]["videos"], subtitle["media_url"]
) )
response = requests.get(subtitle["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: if response.ok:
# create folder here for first video of channel # create folder here for first video of channel
os.makedirs(os.path.split(dest_path)[0], exist_ok=True) os.makedirs(os.path.split(dest_path)[0], exist_ok=True)
with open(dest_path, "w", encoding="utf-8") as subfile: with open(dest_path, "w", encoding="utf-8") as subfile:
subfile.write(response.text) subfile.write(subtitle_str_clean)
else: else:
print(f"{self.youtube_id}: failed to download subtitle") print(f"{self.youtube_id}: failed to download subtitle")