Reputation: 395
I am trying to download songs from youtube using python 3.8 and youtube_dl 2020.3.24. But the weird thing is that most songs I try to download don't get downloaded. I'm talking 99% of them. The ones that do get downloaded get the following Error from youtube_dl:
ERROR: unable to download video data: HTTP Error 403: Forbidden
It is worth saying that this happened overnight and I did not change any code. before this everything worked fine. I have friends who ran the same code and they did not get this Error
Upvotes: 25
Views: 26422
Reputation: 21
If it doesn't help, you can try this:
Open https://colab.research.google.com/
Add a cell (shift+ins) and execute the code:
!pip install yt-dlp
!yt-dlp Your_URL
After uploading, the file can be downloaded (left column).
Upvotes: 2
Reputation: 395
It seems like i have figured it out on my own. The Error went away after i cleared the cache.
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
try:
ydl.cache.remove()
ydl.download([youtube_link])
except youtube_dl.DownloadError as error:
pass
Upvotes: 5
Reputation: 539
Same problem many times ..
solution: youtube-dl --rm-cache-dir
Cause of the problem: Sometimes I download playlists of large videos and I force it to stop downloading, the next time I run the command to resume the download, the 403 problem arises
At the moment, the cache directory is used only to store youtube players for obfuscated signatures. Since all videos in playlist use simple signatures
Playlist caching is an obvious way to detect changed titles or changed playlists in general
Upvotes: 40