-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEyeTube_you.py
More file actions
24 lines (20 loc) · 775 Bytes
/
EyeTube_you.py
File metadata and controls
24 lines (20 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import yt_dlp
import logging
# Function that fetches and downloads the Video from YouTube
def download_youtube_video(url):
ydl_opts = {
'format': 'best',
'noplaylist': True,
'outtmpl': '%(title).100B [%(id)s].%(ext)s', # Limit title length and add video ID
'quiet': True,
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(url, download=False)
if 'entries' in info_dict:
video_format = info_dict['entries'][0] # For playlists, select the first video
else:
video_format = info_dict
download_url = video_format.get('url')
if not download_url:
raise ValueError("Could not extract video URL.")
return download_url