-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_utils.py
32 lines (27 loc) · 1.01 KB
/
video_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import yt_dlp
from typing import Tuple
def extract_video_details(video_url: str) -> Tuple[str, str]:
"""
Extract the title and description of a YouTube video.
:param video_url: URL of the YouTube video.
:return: A tuple containing the video title and description.
"""
ydl_opts = {
"quiet": True,
"no_warnings": True,
# Do not download the video
"simulate": True,
# Skip downloading the video
"skip_download": True,
# Try to use the generic extractor for speed
"force_generic_extractor": True,
# Do not extract additional information about formats
"extract_flat": True,
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(video_url, download=False)
title = info.get("title") if info else None
description = info.get("description") if info else None
title = title or "Title not available"
description = description or "Description not available"
return title, description