Spark-NF / hls-downloader

Download HLS streams in NodeJS
Apache License 2.0
73 stars 32 forks source link

Passing cookies? #14

Closed Zebraslive closed 3 years ago

Zebraslive commented 3 years ago

Can someone show me an example? how to pass multiple cookies?

Zebraslive commented 3 years ago

@Spark-NF when not using CLI how do I pass multiple cookies?

Spark-NF commented 3 years ago

Can't you just use the "httpHeaders" option and use the "Cookie" header? And for multiple values, something like "name=value; name2=value2; name3=value3;".

So something like

httpHeaders: {
    Cookie: "name=value; name2=value2; name3=value3;"
} 
Zebraslive commented 3 years ago

Can't you just use the "httpHeaders" option and use the "Cookie" header? And for multiple values, something like "name=value; name2=value2; name3=value3;".

So something like

httpHeaders: {
    Cookie: "name=value; name2=value2; name3=value3;"
} 

Thanks that helps. but now I get an error saying Refused to set unsafe header "Cookie" Do you know a work around for this? I really appreciate the response.

I'm using the downloader with electron app but i think it would still throw the error if i ran on server.

Spark-NF commented 3 years ago

If you're in electron, you're in a browser, so you can't set cookies during requests, as the browser is enforcing its own cookies. Are the cookies already set in your browser? Or are you trying to set them manually?

The first option could be fixed (via withCredentials), but for setting manually you'll need to Electron's API: https://www.electronjs.org/docs/api/cookies