GithubHelp home page GithubHelp logo

asabino2 / streamproxy Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 1.0 2.7 MB

Stream Proxy - A proxy for the livestreams (streamlink and ffmpeg)

License: GNU General Public License v3.0

JavaScript 100.00%
ffmpeg livestream proxy streamlink

streamproxy's Introduction

███████╗████████╗██████╗ ███████╗ █████╗ ███╗   ███╗    ██████╗ ██████╗  ██████╗ ██╗  ██╗██╗   ██╗
██╔════╝╚══██╔══╝██╔══██╗██╔════╝██╔══██╗████╗ ████║    ██╔══██╗██╔══██╗██╔═══██╗╚██╗██╔╝╚██╗ ██╔╝
███████╗   ██║   ██████╔╝█████╗  ███████║██╔████╔██║    ██████╔╝██████╔╝██║   ██║ ╚███╔╝  ╚████╔╝ 
╚════██║   ██║   ██╔══██╗██╔══╝  ██╔══██║██║╚██╔╝██║    ██╔═══╝ ██╔══██╗██║   ██║ ██╔██╗   ╚██╔╝  
███████║   ██║   ██║  ██║███████╗██║  ██║██║ ╚═╝ ██║    ██║     ██║  ██║╚██████╔╝██╔╝ ██╗   ██║   
╚══════╝   ╚═╝   ╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚═╝     ╚═╝    ╚═╝     ╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═╝   ╚═╝   

Streamproxy is a proxy for livestreams

 

with it you can watch livestreams from youtube, twitch (and any other that can be accessed through the streamlink app) by other iptv apps, such as SSIPTV, tvheadend, ProgTV, etc..

To start the server, run from the command prompt
streamproxy

In your favorite iptv app, you will put in the url one of the following options

  • http://<serverip>:<port>/videostream/streamlink?url=<livestreamurl>
    • Livestream will be routed from a live stream url to any url that is streamlink compatible, video and audio codecs will be passthruded
    • query parameters:
    • Ex: http://localhost:3000//videostream/streamlink?url=https://www.youtube.com/c/SkyNews/live
      To display the skynews live stream on your iptv app

 

  • http://<serverip>:<port>/videostream/ffmpeg?url=<livestreamurl>
    • The livestream will be routed and transcoded to MPEG-2 TS format from a live stream url of any url that ffmpeg supports.
    • Query parameters:
      • url => the url of livestream
      • streamserver (optional)=> create a streamserver (&streamserver=<name>), you can use the url http://<serverip>:<port>/streamserver/create to create using wizard
      • videoformat (optional) => the format for output livestream, if ommited, use in config, if doesn't have in config file, use default mpegts
      • videocodec (optional) => the videocodec for output livestream, if ommited use in config, if doesn't have in config file, use default mpeg2
      • framesize (optional) => the framesize for output livestream, if ommited use of input livestream
      • framerate (optional) => the framerate of output livestream, if ommited use of input livestream
      • serviceprovider (optional) => the service provider of output livestream, if ommited use in config, if doesn't have in config file, use default streamproxy
      • streamdescription (optional) => the stream description (use for service name), if ommited use default streamproxyservice
    • Ex: http://localhost:3000/videostream/ffmpeg?url=https://rbmn-live.akamaized.net/hls/live/590964/BoRB-AT/master.m3u8
      To display the live stream of Redbull TV in MPEG2 TS format on your iptv app

 

 

  • http://<serverip>:<port>/audiostream/play?url=<livestreamurl>
    • convert video livestream to audiolivestream (mp3 format), now you can listen youtube channels
    • Query parameters:
      • url => the url of livestream
      • streamserver (optional)=> create a streamserver (&streamserver=<name>), you can use the url http://<serverip>:<port>/streamserver/create to create using wizard
      • runner (optional) => what runner will be used: streamlink or ffmpeg, if ommited the streamproxy choose the best runner
      • title (optional) => the title of audio livestream, if ommited, use default '

        streamproxy audio'

    • Ex: http://localhost:3000/videostream/info?url=https://rbmn-live.akamaized.net/hls/live/590964/BoRB-AT/master.m3u8
      convert the TV RED BULL to a streaming radio station. NOTE: In windows platforms is only possible to convert videostrem to audiostream from ffmpeg (streamlink is not possible)
  • http://<serverip>:<port>/youtubetopodcast/<channelid>?apikey=<youtubeapikey>
    • Convert a youtube channel in a podcast
    • parameters:
      • <channelid> => youtube channel id to convert to podcast
      • <youtubeapikey> =>  you need a youtube api key to use this feature, check google developer docs for more info. In addition to the query string, you can also set the youtube api key in the following ways:
        • Environment variable => set the environment variable YOUTUBE_API_KEY using command export in linux, this is useful in docker version of streamproxy
        • In streamproxy.config.json at tag youtubeapikey (see more information in streamproxy.config.json doc below)
    • OBS1: This endpoint is in alpha, and have known issues (no showing the total lenght of episode and the server crash if you fast forward or rewind the episode)
    • OBS2: This endpoint is only avaiable if streamproxy server is installed in linux platform
  • http://<serverip>:<port>/videostream/play?url=<livestreamurl>
    • Convert a streamlink's stream to MPEG-2 TS
    • Query parameters:
      • url => the url of livestream
      • streamserver (optional)=> create a streamserver (&streamserver=<name>), you can use the url http://<serverip>:<port>/streamserver/create to create using wizard
      • videoformat (optional) => the format for output livestream, if ommited, use in config, if doesn't have in config file, use default mpegts
      • videocodec (optional) => the videocodec for output livestream, if ommited use in config, if doesn't have in config file, use default mpeg2
      • framesize (optional) => the framesize for output livestream, if ommited use of input livestream
      • framerate (optional) => the framerate of output livestream, if ommited use of input livestream
      • serviceprovider (optional) => the service provider of output livestream, if ommited use in config, if doesn't have in config file, use default streamproxy
      • streamdescription (optional) => the stream description (use for service name), if ommited use default streamproxyservice
    • Ex: http://localhost:3000//videostream/streamlink?url=https://www.youtube.com/c/SkyNews/live
      To display the skynews live stream on your iptv app (in MPEG-2 TS format)
    • Note: due to compatibility issues, this endpoint cannot run if the server is installed on windows

 

  • http://<serverip>:<port>/streamserver/create
    • streamserver is a livestream server that allows with just one thread created and using the same streamproxy port you can provide the livestream to several clients, just access http://<serverip>:<port>/play/<servername>, where < servername> is the server name given at creation time. To close this server session, just kill the corresponding process in the status page (/status). Now compatible with streamlink, ffmpeg and convert videostream to audiolivestream
    • use the url http://<serverip>:<port>/streamserver/list instead of this one, because there you will have the option to create a new streamserver. Direct access to http://<serverip>:<port>/streamserver/create and http://<serverip>:<port>/streamserver/edit will be removed in a future release

 

  • http://<serverip>:<port>/streamserver/list
    • manage your streamservers created. in this url you can see the list of created streamservers, stop, start, edit, delete and create new

 

  • http://<serverip>:<port>/streamserver/playlist.m3u
    • Download all streamservers mounted in m3u playlist format
  •  http://<serverip>:<port>/videostream/restream?url=<livestream>&output=<outputaddress>&format=<format>&vcode=<videocoded>&acodec=<audiocodec>
    • Restream a livestream to another address (rtmp for exemple)
    • url parameters
      • <livestream>: the source livestream url (in linux can be streamlink or ffmpeg compatible, in windows only ffmpeg compatible stream is acceptable)
      • <outputaddress>: the destination livestream address (can be a youtube rtmp address, nginx rtmp address, http livestream server address, etc...)
      • <format>: the format of livestream (mpeg2-ts, hls, mp3, etc...)
      • <videocodec>: the video codec (mp4, mpeg2, h264, etc...), this parameter is optional, if ommited the video codec is copied from source
      • <audiocodec>: the audio codec (mp3, aac,  etc...), this parameter is optional, if ommited the audio codec is copied from source
      • This endpoint is in beta version (will be removed in a future version)
      • Ex: http://localhost:3000/videostream/restream?url=https://www.youtube.com/c/SkyNews/live&output=rtmp://localhost:4113/live&format=mpeg2ts&vcode=mpeg2&acodec=mp3 -> restream the skynews youtube channel to rtmp://localhost:4113/live
      • This endpoint must be called from browser
      • To kill session, kill correspondent process from /status
  • http://<serverip>:<port>/user/list
    • User list and management (create, edit and delete)
  • http://<serverip>:<port>/user/create
    • Create a new user
  • http://<serverip>:<port>/changepassword
    • Change your own password
    • OBS: For now, is only possible to change your own password, if you forgot your password and want to recorver and change, go to users file (see above in this document), remove your user and assign the role administrator to anonymous user, go to user manager page (/user/list) again and recreate your user.
  •  http://<serverip>:<port>/status
    • see status of opened process
  • http://<serverip>:<port>/login
    • use to login in server (if basicAuthentication is present in config file)
  • http://<serverip>:<port>/logout
    • use to logout from server (if basicAuthentication is present in config file)
  • http://<serverip>:<port>/log
    • display log (see the parameter logWeb in streamproxy.config.json below)
  • http://<serverip>:<port>/stopserver
    • shutdown the streamproxy server

 

to see the list of APIs available in streamproxy check the url: http://<serverip>:<port>/docs/api

or in address: https://asabino.stoplight.io/docs/streamproxy/34dd32710e316-streamproxy


streamproxy.config.json

you can modify some parameters of the program, changing the config.json file located in the same folder as the executable

{
 "port": "3000",
 "logconsole": true,
 "logWeb": false,
 "streamlinkpath": "",
 "ffmpegpath": "",
 "youtubeapikey": "",
 "ffmpeg": {
   "codec": "mpeg2video",
   "format": "mpegts",
   "serviceprovider": "streamproxy"
 }, "token": "yourtoken", (optional)
"streamserver": { 
  "startOnInvoke": false,
  "hideStoppedStreamServerInPlaylist": true,
  "stopOnNoConnection": true
}
 "basicAuthentication": { "active": true, "users": [{ "username": "teste", "password": "teste2" }] } (optional, if exist, server will be require login in all endpoints)

 
}
  • Port: The listening port of server
  • logConsole (true|false): choose if log will be outputed to console
  • logWeb (true|false): choose if log will be outputed to http://<serverip>:<port>/log
  • Streamlinkpath: the path of streamlink app
  • ffmpegpath: the path of ffmpeg app
  • youtubeapikey: set your youtube api key, will be used if not seted in environment variable, for now only used in youtube to podcast feature
  • codec: the video codec of transcoded ffmpeg's stream
  • format: the video container of transcoded ffmpeg's stream
  • serviceprovider: the service provider of transcoded ffmpeg's stream
  • startOnInvoke: if seted to true, if a streamserver is stopped, will be started when called, if false, will raise a HTTP 500 error
  • hideStoppedStreamServerInPlaylist: if seted to true, will hide the stopped streamservers in /streamserver/playlist.m3u, else will be show in playlist all the streamservers created, even the stoppeds
  • stopOnNoConnection: stop the streamserver if no more clients are connected
  • Now, in addition to using token, you can create logins to allow access to all endpoints. The server will use Basic Authentication, so to use the videostream url in your IPTV app you should use: http://<username>:<password>@<IP>:<port>/videostream/streamlink?url=<url address from the live stream >
    The token is now obsolete and may be retired from future versions

OBS: Now you can set the directory of streamproxy.config.json, streamproxy.authroles.json, streamproxy.users.json, streamproxy.streamservers.json using the environment variable STREAMPROXY_DATA_DIR 


streamproxy.authroles.json

Authorizations roles file, you can modify or create new authorization roles changing this file

 

[
    {
      "name": "basic",
      "description": "Basic Authorization",
      "authorizations": [
        {
          "endpoint": "/",
          "methods": [
            "GET"
          ]
        },
        {
          "endpoint": "/about",
          "methods": [
            "GET"
          ]
        }
      ]
    },
    {
      "name": "basicWatchers",
      "description": "Basic Watches",
      "authorizations": [
        {
          "endpoint": "/videostream/*",
          "methods": [
            "GET"
          ]
        },
        {
          "endpoint": "/audiostream/play",
          "methods": [
            "GET"
          ]
        }
      ]
    },
    {
      "name": "streamserverWatchersbasic",
      "description": "Stream Server Watchers Basic (without playlist Download)",
      "authorizations": [
        {
          "endpoint": "/play/*",
          "methods": [
            "GET"
          ]
        }
      ]
    },
    {
      "name": "playlistdownloader",
      "description": "Playlist Downloader",
      "authorizations": [
        {
          "endpoint": "/streamserver/playlist.m3u",
          "methods": [
            "GET"
          ]
        }
      ]
    },
    {
      "name": "streamserverWatchersfull",
      "description": "Stream Server Watchers Full (with playlist Download)",
      "authorizations": [
        {
          "endpoint": "/play/*",
          "methods": [
            "GET"
          ]
        },
        {
          "endpoint": "/streamserver/playlist.m3u",
          "methods": [
            "GET"
          ]
        }
      ]
    },
    {
      "name": "administrator",
      "description": "Administrator",
      "authorizations": [
        {
          "endpoint": "*",
          "methods": [
            "GET",
            "POST",
            "PUT",
            "DELETE",
            "PATCH"
          ]
        }
      ]
    }
  ]
  • name: name of authorization role
  • description: Description of authorization role
  • authorizations: endpoints and methods authorizeds for this role (wildcard is allowed)

OBS: Now you can set the directory of streamproxy.config.json, streamproxy.authroles.json, streamproxy.users.json, streamproxy.streamservers.json using the environment variable STREAMPROXY_DATA_DIR 


streamproxy.users.json

File to store all users created in streamproxy. When not exists will be created with 2 users: anonymous, with only basic role and no password, and admin (with password admin) with administrator role

 

[
   {
      "username":"anonymous",
      "password":"",
      "fullname":"Anonymous",
      "authorizations":{
         "basic":true,
         "basicWatchers":true,
         "streamserverWatchersbasic":false,
         "playlistdownloader":false,
         "streamserverWatchersfull":false,
         "administrator":false
      }
   },
   {
      "username":"admin",
      "password":"d033e22ae348aeb5660fc2140aec35850c4da997",
      "fullname":"Administrator",
      "authorizations":{
         "administrator":true
      }
   }
]

prefer to use the user manager (/user/list) instead of directly editing this file

if you enabled basic authetication in config file then all users created there will be automatically migrated to streamproxy.users.json file

 

OBS: Now you can set the directory of streamproxy.config.json, streamproxy.authroles.json, streamproxy.users.json, streamproxy.streamservers.json using the environment variable STREAMPROXY_DATA_DIR 


CLI Parameters: run streamproxy -h to see the cli parameters help

Streamproxy is already for ChatGPT Plugin (Alpha)

now you can use your streamproxy server as chatgpt plugin. unfortunately I can't perform tests, because I don't have chatgpt plus. Use at your own risk

For more information, see the chatgpt plugins documentation on openAI


there are a docker version of streamproxy at https://hub.docker.com/repository/docker/asabino2/streamproxy


If you think this app is useful to you, please consider donating to support with the development.

 

Paypal: https://www.paypal.com/donate/?hosted_button_id=BGLA2H7WPBX9L

Bitcoin wallet: 1ABDdCp7rrkDa2tAtLwW6diNU2XqAxw7fB

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.