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
1 changed files with 7 additions and 1 deletions

View File

@ -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")