Friday, August 2, 2024

Download Youtube videos

# pip install yt-dlp


import yt_dlp


def download_youtube_video(url, save_path='.'):

  ydl_opts = {'outtmpl': f'{save_path}/%(title)s.%(ext)s', 'format': 'best'

  }

  try:

    with yt_dlp.YoutubeDL(ydl_opts) as ydl:

      ydl.download([url])

    print("Download completed!")

  except Exception as e:

    print(f"An error occurred: {e}")


video_url = "https://www.youtube.com/watch?v=-5ef7epnR60"

download_youtube_video(video_url)


No comments:

Post a Comment