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
256 stars 80 forks source link

Using the proxy #8

Open akillar opened 4 years ago

akillar commented 4 years ago

How do you use this proxy to stream a m3u8 url. i've installed the proxy globally and started the proxy using the command + allowed ports in the firewall. but how do i use my m3u8 url to use this proxy ?

warren-bank commented 4 years ago

using the 24/7 CBS News live stream as a sample m3u8 URL

to obtain a proxied URL in bash:

proxy='127.0.0.1:8080'
URL='https://www.cbsnews.com/common/video/cbsn_header_prod.m3u8'
URL=$(echo "$URL" | base64 --wrap=0)
URL="http://${proxy}/${URL}.m3u8"
echo $URL

to obtain a proxied URL in javascript:

{
  const proxy = '127.0.0.1:8080'
  let URL
  URL = 'https://www.cbsnews.com/common/video/cbsn_header_prod.m3u8'
  URL = window.btoa(URL)
  URL = `http://${proxy}/${URL}.m3u8`
  console.log(URL)
}

tool that can be used to simplify this task:

a cheat to use the SPAs without the Chrome extension:

warren-bank commented 4 years ago

PS: since you mentioned opening ports in your server's firewall, I'll mention that you'll want to replace 127.0.0.1 in all of the examples above with an IP that's reachable from your client. For example, on your LAN the IP might look something like 192.168.0.100.

akillar commented 4 years ago

thank you @warren-bank.

akillar commented 4 years ago

@warren-bank is it possible to use a domain name instead of a ip address for the const proxy = '127.0.0.1:8080'

warren-bank commented 4 years ago

yes.. so long as the client that you're using to download the stream through the proxy can use DNS to resolve your domain name to an IP address, then you certainly can.

{
  const proxy = 'https://my-hls-proxy.com:443'
  let URL
  URL = 'https://www.cbsnews.com/common/video/cbsn_header_prod.m3u8'
  URL = window.btoa(URL)
  URL = `${proxy}/${URL}.m3u8`
  console.log(URL)
}

you can play around with this by editing the hosts file on your computer.. to override DNS resolution locally for testing

127.0.0.1  my-hls-proxy.com