-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPlaylist_downloader.py
28 lines (22 loc) · 1007 Bytes
/
Playlist_downloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
from pytube import Playlist
from pytube.exceptions import PytubeError
# Replace with your playlist URL
playlist_url = input("Playlist URL: ")
# Create a directory to save the downloaded videos if it doesn't exist
if not os.path.exists('downloads'):
os.makedirs('downloads')
# Create a Playlist object
playlist = Playlist(playlist_url)
# Function to download a video
def download_video(video, index):
try:
# Download the video
video.streams.get_highest_resolution().download(output_path='downloads', filename=f'video_{index}.mp4')
print(f"✅✅✅ Downloaded video {index}")
except PytubeError as e:
print(f"❌❌❌ Error downloading video {index}: {str(e)}")
# Loop through the videos in the playlist and download them
for index, video in enumerate(playlist.videos, start=1):
download_video(video, index)
print("✅✅✅ Downloaded all available videos in the playlist to 'downloads' directory in .mp4 format")