File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ import yt_dlp
2
+
3
+ def download_video (url , resolution = 'highest' ):
4
+ try :
5
+ # Set yt-dlp options for video download
6
+ ydl_opts = {
7
+ 'format' : f'bestvideo[height<={ resolution } ]+bestaudio/best[height<={ resolution } ]' if resolution != 'highest' else 'best' ,
8
+ 'outtmpl' : '%(title)s.%(ext)s' , # Output file name template
9
+ }
10
+
11
+ # Download video with yt-dlp
12
+ with yt_dlp .YoutubeDL (ydl_opts ) as ydl :
13
+ ydl .download ([url ])
14
+ print ("Download completed!" )
15
+ except Exception as e :
16
+ print (f"Error: { e } " )
17
+
18
+ if __name__ == "__main__" :
19
+ video_url = input ("Enter YouTube URL: " )
20
+ video_resolution = input ("Enter resolution (e.g., 720p or leave blank for highest): " ).strip ()
21
+
22
+ # Download the video with specified resolution
23
+ download_video (video_url , video_resolution or 'highest' )
Original file line number Diff line number Diff line change
1
+ yt-dlp
2
+
Original file line number Diff line number Diff line change
1
+ python-3.10.12
You can’t perform that action at this time.
0 commit comments