Do not except any raised error
This commit is contained in:
parent
4df67bd475
commit
d6bc9e6728
1 changed files with 15 additions and 19 deletions
34
summarize.py
34
summarize.py
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue