This repository contains two separate Python programs for downloading YouTube content:
- Download Playlist: Downloads all videos from a YouTube playlist.
- Download Single Video: Downloads a single YouTube video.
Both programs use the yt-dlp
library to handle the downloading process.
Ensure you have Python installed on your system. You also need to install the yt-dlp
library. You can install it using pip:
pip install yt-dlp
This script downloads all videos from a specified YouTube playlist.
import yt_dlp
def download_playlist(playlist_url, download_path):
ydl_opts = {
'format': 'bestvideo+bestaudio/best',
'merge_output_format': 'mp4', # Use 'mkv' if you prefer that format
'outtmpl': f'{download_path}/%(title)s.%(ext)s',
'noplaylist': False, # Set to True if you want to download only a single video
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([playlist_url])
playlist_url = 'https://youtube.com/playlist?list=PLihCJJ6_IteEo46nNNA4ksZw7ITDQ7nkS'
download_path = 'D:/Yt_videos'
download_playlist(playlist_url, download_path)
- Replace
playlist_url
with the URL of the playlist you want to download. - Replace
download_path
with your desired download directory. - Run the script:
python download_playlist.py
This script downloads a single YouTube video.
import yt_dlp
def download_video(video_url, download_path):
ydl_opts = {
'format': 'bestvideo+bestaudio/best',
'merge_output_format': 'mp4', # Use 'mkv' if you prefer that format
'outtmpl': f'{download_path}/%(title)s.%(ext)s',
'noplaylist': True, # Set to True to ensure only a single video is downloaded
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([video_url])
video_url = 'https://www.youtube.com/watch?v=OoHPhLV43gg'
download_path = 'E:/Yt_single_videos'
download_video(video_url, download_path)
- Replace
video_url
with the URL of the video you want to download. - Replace
download_path
with your desired download directory. - Run the script:
python download_video.py
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to adjust any paths or URLs as needed!