Skip to content

Instantly share code, notes, and snippets.

@RajeshKrSahoo
Last active August 16, 2020 03:56
Show Gist options
  • Save RajeshKrSahoo/1e42b895b6dc4a3b9ca50dcadbf55b70 to your computer and use it in GitHub Desktop.
Save RajeshKrSahoo/1e42b895b6dc4a3b9ca50dcadbf55b70 to your computer and use it in GitHub Desktop.
'''
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)
@RajeshKrSahoo
Copy link
Author

downloading all the videos from the youtube playlists

@RajeshKrSahoo
Copy link
Author

Updated with latest fixes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment