I need to add custom HTTP header to extracted direct link to file by youtube-dl so it won't open once clicked in browser, but download. I was going to use solution from this answer, but there might be easier solution. There is a option in youtube-dl Workarounds:
--add-header FIELD:VALUE Specify a custom HTTP header and its value, separated by a colon ':'. You can use this option multiple times
My question is what header to write as a FIELD and VALUE in terminal to force direct link to file to download by default.
youtube-dl -g --add-header FIELD:VALUE https://www.youtube.com/watch?v=9Q7Vr3yQYWQ
EDIT: To better explain what I'm trying to accomplish, I execute the following command from application on server:
youtube-dl -g URL
and return output, what is direct link to video file, to client for user to download. Problem is that by default, browser opens the file and not starts download. By changing header of the file, you can force browser to download. My question is that if it applies to direct links too and if so, how to add header in youtube-dl script to force the link to trigger download.
HTML 5 solution that works only in Chrome and Firefox, is not good enough.
<a href="url" download="filename"></a>
Taken from this youtube-dl issue. For non-dash formats (for example if you use -f best
when calling youtube-dl) if you add &title=something
to the url you get with youtube-dl their servers add the following header to the response: Content-Disposition: attachment; filename="something.mp4"
, forcing the browser to download it as something.mp4
.