Using the method mentioned here: Using Pytube to download playlist from YouTube using replit I keep encountering the following error:
import re from pytube import Playlist
YOUTUBE_STREAM_AUDIO = '140' # modify the value to download a different stream DOWNLOAD_DIR = 'D:\\Users\\Jean-Pierre\\Downloads'
playlist = Playlist('https://www.youtube.com/playlist?list=PLzwWSJNcZTMSW-v1x6MhHFKkwrGaEgQ-L')
# this fixes the empty playlist.videos list playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)")
print(len(playlist.video_urls))
for url in playlist.video_urls:
print(url)
# physically downloading the audio track for video in playlist.videos:
audioStream = video.streams.get_by_itag(YOUTUBE_STREAM_AUDIO)
audioStream.download(output_path=DOWNLOAD_DIR)
I keep getting the following error:
Traceback (most recent call last):
File "main.py", line 18, in <module>
for video in playlist.videos:
File "/home/runner/FlippantFrankHashmaps/venv/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 144, in videos
yield from (YouTube(url) for url in self.video_urls)
File "/home/runner/FlippantFrankHashmaps/venv/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 144, in <genexpr>
yield from (YouTube(url) for url in self.video_urls)
File "/home/runner/FlippantFrankHashmaps/venv/lib/python3.10/site-packages/pytube/__main__.py", line 91, in __init__
self.prefetch()
...
line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 410: Gone