Youtube-dl is my favorite and preferred command line download manager. I often use it to download audios, videos and movies from Internet. Today, I tried to download a video from YouTube using youdtube-dl from my Linux desktop and got this error message - Unable to download video data: HTTP Error 403: Forbidden. Usually, most youtube-dl errors will be fixed after updating youtube-dl. So I updated youtube-dl using command:
$ sudo youtube-dl -U
It is already updated! I have the most recent version.
And then I tried again to download the video with command:
$ youtube-dl https://www.youtube.com/watch?v=4jTy5jnMkYc
But I get the same error:
[youtube] 4jTy5jnMkYc: Downloading webpage
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
ERROR: unable to download video data: HTTP Error 403: Forbidden
If you ever encountered with this error, follow the steps given below to fix it.
Fix "Unable to download video data: HTTP Error 403: Forbidden" Error When Downloading Media Files With Youtube-dl In Linux
This error will probably happen because of Youtube-dl cache. To fix it, simply remove the cache for youtube-dl using command:
$ youtube-dl --rm-cache-dir
This command command will remove the local caching directory for youtube-dl. In my case, it removed the following directory:
Removing cache dir /home/sk/.cache/youtube-dl ...
If you use Youtube-dl in Python code, the following will help to fix this error.
# 'cachedir': False -> don't use a local caching dir (~/.cache/youtube-dl) ydl_opts = {..., 'cachedir': False } with youtube_dl.YoutubeDL(ydl_opts) as ydl: result = ydl.extract_info(url)
Now, I can be able to download the youtube videos without any issues.
$ youtube-dl https://www.youtube.com/watch?v=4jTy5jnMkYc
[youtube] 4jTy5jnMkYc: Downloading webpage [youtube] 4jTy5jnMkYc: Downloading js player vflset [youtube] 4jTy5jnMkYc: Downloading js player vflset WARNING: Requested formats are incompatible for merge and will be merged into mkv. [download] Destination: Takkar _ Nira Song Lyric Video _ Siddharth _ Sid Sriram _ Gautham Menon _ Nivas K Prasanna-4jTy5jnMkYc.f137.mp4 [download] 100% of 29.87MiB in 00:24 [download] Destination: Takkar _ Nira Song Lyric Video _ Siddharth _ Sid Sriram _ Gautham Menon _ Nivas K Prasanna-4jTy5jnMkYc.f251.webm [download] 100% of 5.10MiB in 00:04 [ffmpeg] Merging formats into "Takkar _ Nira Song Lyric Video _ Siddharth _ Sid Sriram _ Gautham Menon _ Nivas K Prasanna-4jTy5jnMkYc.mkv" Deleting original file Takkar _ Nira Song Lyric Video _ Siddharth _ Sid Sriram _ Gautham Menon _ Nivas K Prasanna-4jTy5jnMkYc.f137.mp4 (pass -k to keep) Deleting original file Takkar _ Nira Song Lyric Video _ Siddharth _ Sid Sriram _ Gautham Menon _ Nivas K Prasanna-4jTy5jnMkYc.f251.webm (pass -k to keep)
As you may probably noticed, there is a warning message in the above command:
[...] WARNING: Requested formats are incompatible for merge and will be merged into mkv. [...]
This is not actually a problem but an expected behavior for youtube-dl command. By default, youtube-dl will download the highest quality audio and the highest quality video streams available and then join them into a compatible container like mkv, mp4 etc. If these audio and video streams doesn't fit well in an mp4 container, youtube-dl will then pack them in mkv container and display the above warning message. In such cases, you can ignore the mkv warning and download the best quality video and the best quality audio but only in an mp4 container by explicitly mentioning the desired best quality audio and video formats like below:
$ youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]' https://www.youtube.com/watch?v=4jTy5jnMkYc
For more Youtube-dl command examples, refer the following guide.
Hope this helps.
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!
10 comments
That’ll be real useful if you included where to make this change.
Have a look at this -> https://github.com/ytdl-org/youtube-dl/blob/master/README.md#embedding-youtube-dl
Well done. Thank you.
YES! Thanks!
Brilliant! Thx! =)
thank you! that helped me, after a PC crash the cache got corrupted i guess
The tutorial worked for me to sort out the error.
Thanks a lot for correlating error and fix and the step by step explanation. This worked for me on android.
Happy to help. How do you use youtube-dl on Android? Is there a youtube-dl client for Android?
Didn’t work for me, requesting the webm format worked though. Turns out the problem is fetching the mp4 format.
-f “webm[height=720]” instead of -f “best[height<=720]"