warren-bank / HLS-Proxy

Node.js server to proxy HLS video streams
http://webcast-reloaded.surge.sh/proxy.html
GNU General Public License v2.0
238 stars 68 forks source link

ip restrictions #24

Open ChronoBrake opened 1 year ago

ChronoBrake commented 1 year ago

Hello, Your project be awesome! Will this repo handle IP restrictions? i have an m3u8 channel but it limits the use to 2 devices per ip address. Can you get around this? Can you somehow add support for SOCKS proxy or something like that?

example link: http://r.faola.li/6428/video.m3u8?token=K8C3Dt1DXA

Best Regards

warren-bank commented 1 year ago

regarding the use of this hls proxy to bypass access restrictions imposed by the video host: only 2 registered IP addresses are allowed to make requests to download video..

yes, using a hls proxy is very good workaround. you register the IP address where the hls proxy runs.. to allow it access to the video host. you connect any number of clients (at any IP) to the hls proxy.. and voila.. you can access the video streams.

in this use case, if these are all live video streams (ie: not video on demand).. then it would also make sense to --prefetch --max-segments <some fairly large number>.. to retain a large in-memory cache of video so each stream is only requested from the server once; where the actual number depends on how much RAM you're willing to allocate; to prevent running out of RAM, you'd need to estimate.. the max number of streams you expect to be used concurrently.. and the max size of each video segment.

warren-bank commented 1 year ago

regarding adding an option to configure the use of a socks proxy, between the hls proxy and the video host.. I've considered it, and I'm not convinced that it's a good idea.

  1. it would add a fairly large dependency to the project, and I like that it's currently ridiculously lean
  2. it would reduce the speed of the hls proxy, which defeats its intended purpose
    • in my personal life, I have a few tools that I use socks proxies to route requests through.. and I can see that they are slow.. but for their particular use cases, it happens not to matter

a good tool to use to help determine how much of a delay a socks proxy would impose is my command-line http client.. you can use an hls manifest as an --input-file and configure the --max-concurrency.. to download all video segment URLs contained in the manifest.. and run two tests..

  1. without any socks proxy
  2. with the --proxy option

wrap each test in a timer.. and compare the relative difference

ChronoBrake commented 1 year ago

Hm, you have right. socks or any proxies between it will add delay. In this case last option is set like you said prefetch and big fragments to saving in memory.

d3vr commented 1 year ago

In my case I have a stream that's restricted to a specific country only. My server doesn't run in that country however I have an http proxy I can use. Is there a way I can do this with HLS Proxy ? If not, any suggested workarounds ?

warren-bank commented 1 year ago

I think there's room for compromise..

I didn't want to include support for non-http protocol proxies (ex: socks4, socks5, etc).. because then I would need to start adding dependencies, and the app becomes bloated by features that most people would never use.

However, adding support for an http/https proxy doesn't require any new libraries.. only some minimal code to modify outbound requests. There's no good reason to not offer that as an option:

--http-proxy "http://username:password@hostname:port"

I'll write that up and test it within the next day or two.. and will let you know when it's pushed to npm.

d3vr commented 1 year ago

I understand your concern about keeping the codebase light with minimal dependencies. Thank you for the consideration and quick response, much appreciated.

I tried looking into the code and trying to figure out to do what I wanted to do, but I wasn't sure which options to pass to node-request to make the requests go through the proxy. Not even sure if it's supported there.

Thanks again.

warren-bank commented 1 year ago

node-request doesn't include support for that, for the same reason.. wanted to keep the library super light-weight.

node-request-cli adds support for many different types of proxies.. specifically, this support was added in v4.0.12.. so the difference in installed size from v4.0.11 is attributable to the added dependencies.

warren-bank commented 1 year ago

ok.. v3.3.0 is ready to use.

I used a proxy server at GetFlix to test.. turned out that this proxy (and probably all real ones) uses the HTTP Connect method to tunnel.. which is entirely different from the web proxy server methodology described by Fiddler.. so after some testing, I decided to replace my implementation and offload the logic to a library.. and ended up using hpagent.. which is great, because it's tiny and has no dependencies.. and it worked when tested.

d3vr commented 1 year ago

Thank you so much for the quick implementation 🙏 !