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

1

8

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?

Hillier answered 18/6, 2020 at 10:27 Comment(0)
H
10

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' \
Hillier answered 24/6, 2020 at 11:29 Comment(3)
How can you add these headers in windows?Canadian
It should work, likely if you have issues is related to the character required to escape other special characters and issue multi-line commands, in windows if you are using cmd it is the caret instead of the backslash. HTHHillier
Just to avoid possibile bother, we could add --no-check-certificateStormystorting

© 2022 - 2024 — McMap. All rights reserved.