Last active
August 16, 2020 03:56
-
-
Save RajeshKrSahoo/1e42b895b6dc4a3b9ca50dcadbf55b70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Below code downlaod all the videos in the playlists present | |
''' | |
import re,os | |
from pytube import Playlist,YouTube | |
# YOUTUBE_STREAM_AUDIO = '480' # modify the value to download a different stream | |
DOWNLOAD_DIR = os.getcwd()+'newDownload' | |
print("DOWNLOAD_DIR") | |
playlist = Playlist('https://www.youtube.com/playlist?list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH') | |
# this fixes the empty playlist.videos list | |
playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)") | |
print(len(playlist.video_urls)) | |
try: | |
for url in playlist.video_urls: | |
print("Trying download:---> ",url) | |
try: | |
YouTube(url).streams.first().download(DOWNLOAD_DIR) | |
print("Downlaoded succesfully: ",url) | |
except urllib.error.URLError as e: | |
print("********ERROR downloading the link*****: {0} {}".format(e.reason, url)) | |
pass | |
except urllib.error.URLError as e: | |
print(e.reason)streams.first().download() | |
# physically downloading the audio track | |
# for video in playlist.videos: | |
# print('downloading for') | |
# audioStream = video.streams.get_by_itag(YOUTUBE_STREAM_AUDIO) | |
# audioStream.download(output_path=DOWNLOAD_DIR) |
Updated with latest fixes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
downloading all the videos from the youtube playlists