Skip to content

Commit c702c12

Browse files
committed
Initial YouTube Video Downloader project with yt-dlp integration
1 parent d49deeb commit c702c12

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Youtube Video Downloader/main.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yt-dlp
2+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-3.10.12

0 commit comments

Comments
 (0)