Do not except any raised error

This commit is contained in:
Marty Oehme 2025-01-18 14:34:21 +01:00
parent 4df67bd475
commit d6bc9e6728
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -33,28 +33,24 @@ def grab_subtitles(url: str | Path) -> Path:
import yt_dlp
temp_dir = get_temp_dir()
try:
ydl_opts = {
"outtmpl": f"{temp_dir}/subs",
"writeautomaticsub": True,
"subtitlesformat": "json3",
"skip_download": True,
}
ydl_opts = {
"outtmpl": f"{temp_dir}/subs",
"writeautomaticsub": True,
"subtitlesformat": "json3",
"skip_download": True,
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=True)
filename = ydl.prepare_filename(info)
print(f"Subtitle file saved as: {filename}")
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=True)
filename = ydl.prepare_filename(info)
print(f"Subtitle file saved as: {filename}")
for root, _, files in Path(temp_dir).walk():
for file in files:
if file.endswith(".json3"):
return Path(root).joinpath(file)
for root, _, files in Path(temp_dir).walk():
for file in files:
if file.endswith(".json3"):
return Path(root).joinpath(file)
raise ValueError("No correct json3 transcript object found.")
except ValueError as e:
print(e)
raise ValueError("No correct json3 transcript object found.")
def get_temp_dir() -> str: