diff options
| author | pants <niklasjo2004@gmail.com> | 2026-09-21 14:17:03 -0700 |
|---|---|---|
| committer | pants <niklasjo2004@gmail.com> | 2026-09-21 14:17:03 -0700 |
| commit | 7b21727285e50b0b050c4ddd70d07542229c5366 (patch) | |
| tree | 5d369153c5df5b41f3750d25479a68f20169c8ff /python/ytdl/download_video.py | |
init
Diffstat (limited to 'python/ytdl/download_video.py')
| -rw-r--r-- | python/ytdl/download_video.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/python/ytdl/download_video.py b/python/ytdl/download_video.py new file mode 100644 index 0000000..dbd8bff --- /dev/null +++ b/python/ytdl/download_video.py @@ -0,0 +1,19 @@ +import yt_dlp + +def download_video(url, path='.'): + # Options for downloading the best quality video and audio + ydl_opts = { + 'format': 'bestvideo+bestaudio/best', # Selects the best quality of video and audio available + 'outtmpl': f'{path}/%(title)s.%(ext)s', # Template for output file name + } + + with yt_dlp.YoutubeDL(ydl_opts) as ydl: + try: + ydl.download([url]) + print("Video downloaded successfully.") + except Exception as e: + print(f"An error occurred while downloading the video: {e}") + +# Example usage +video_url = input("Video URL: ") +download_video(video_url) |
