Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download MPEG Dash (mpd file) using youtube-dl when headers are requested and getting HTTP Error 403

I've used Chrome developer tools to inspect network activity and filter the mpd file. I've get the URL of the mpd with the context menu copy link address. But when I've assembled the youtube-dl command line it get HTTP Error 403: Forbidden.

So I've tried to add the --verbose option to get more information and found a warning "Could not send HEAD request" so I've assumed I needed to send also the headers. I can get the headers with the context menu copy as cURL in the mpd file listed in network activity inspector.

Downloading with curl works for the manifest, but how can I provide headers to youtube-dl to send them properly?

like image 452
Telesforo X Avatar asked Jun 18 '20 10:06

Telesforo X


People also ask

How do I play a MPD link?

Simply enter the URL of your mpeg-dash stream (. mpd file) into Castr's Dash player and press play. If everything goes well, the video will playback smoothly. Make sure your URL are HTTPS- compatible, otherwise your stream may not play.


1 Answers

The cURL copy from Chrome developer tools filtered entry in the inspect network activity will provide this kind of string:

curl 'https://source-of-video.net/folder/manifest.mpd' \
  -H 'authority: source-of-video.net' \
  -H 'pragma: no-cache' \
  -H 'cache-control: no-cache' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' \
  -H 'dnt: 1' \
  -H 'accept: */*' \
  -H 'origin: https://origin-website-of-video' \
  -H 'sec-fetch-site: cross-site' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-dest: empty' \
  -H 'referer: https://origin-website-of-video/origin.html' \
  -H 'accept-language: en-US,en;q=0.9,es;q=0.8,it;q=0.7,pt;q=0.6' \
  --compressed

Just replacing -H with --add-header and curl with youtube-dl and deleting --compressed will do the trick, ending up like this (headers are only examples):

youtube-dl 'https://source-of-video.net/folder/manifest.mpd' \
  --add-header 'authority: source-of-video.net' \
  --add-header 'pragma: no-cache' \
  --add-header 'cache-control: no-cache' \
  --add-header 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' \
  --add-header 'dnt: 1' \
  --add-header 'accept: */*' \
  --add-header 'origin: https://origin-website-of-video' \
  --add-header 'sec-fetch-site: cross-site' \
  --add-header 'sec-fetch-mode: cors' \
  --add-header 'sec-fetch-dest: empty' \
  --add-header 'referer: https://origin-website-of-video/origin.html' \
  --add-header 'accept-language: en-US,en;q=0.9,es;q=0.8,it;q=0.7,pt;q=0.6' \
like image 113
Telesforo X Avatar answered Nov 15 '22 14:11

Telesforo X