Skip to content

cli.main: use *_args, **_kwargs for create_http_server #3450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 26, 2020

Conversation

back-to
Copy link
Collaborator

@back-to back-to commented Dec 26, 2020

closes #2622

use 127.0.0.1 for local create_http_server()
use 0.0.0.0 for external create_http_server()

--player-http = 127.0.0.1
https://streamlink.github.io/cli.html#cmdoption-player-http

--player-continuous-http = 127.0.0.1
https://streamlink.github.io/cli.html#cmdoption-player-continuous-http

--player-external-http = None / 0.0.0.0
https://streamlink.github.io/cli.html#cmdoption-player-external-http


we use AF_INET which is IPv4

https://github.com/streamlink/streamlink/blob/2.0.0/src/streamlink_cli/utils/http_server.py#L24

we don't use AF_INET6 which is IPv6, so IPv6 support is unimportant.

Ref #2622 (comment)


$ streamlink https://www.youtube.com/channel/UCSrZ3UV4jOidv8ppoVuvW9Q/live --player-http -l debug
...
[cli][info] Starting player: /usr/bin/mpv
[cli.output][debug] Opening subprocess: /usr/bin/mpv "--force-media-title=Euronews English Live" http://127.0.0.1:35085/
$ streamlink https://www.youtube.com/channel/UCSrZ3UV4jOidv8ppoVuvW9Q/live --player-continuous-http -l debug
...
[cli][info] Starting player: /usr/bin/mpv
[cli.output][debug] Opening subprocess: /usr/bin/mpv "--force-media-title=Euronews English Live" http://127.0.0.1:39099/
[cli][info] Got HTTP request from libmpv
$ streamlink https://www.youtube.com/channel/UCSrZ3UV4jOidv8ppoVuvW9Q/live --player-external-http --player-external-http-port 33333
[cli][info] Starting server, access with one of:
[cli][info]  http://127.0.0.1:33333/
[cli][info]  http://127.0.0.53:33333/
[cli][info]  http://127.0.1.1:33333/
[cli][info] Got HTTP request from Mozilla/5.0 ...
[cli][info] Opening stream: 720p (hls)

closes streamlink#2622

use `127.0.0.1` for local `create_http_server()`
use `0.0.0.0` for external `create_http_server()`

`--player-http` = ***127.0.0.1***
https://streamlink.github.io/cli.html#cmdoption-player-http

`--player-continuous-http` = ***127.0.0.1***
https://streamlink.github.io/cli.html#cmdoption-player-continuous-http

`--player-external-http` = ***None*** / ***0.0.0.0***
https://streamlink.github.io/cli.html#cmdoption-player-external-http

---

we use `AF_INET` which is IPv4

https://github.com/streamlink/streamlink/blob/2.0.0/src/streamlink_cli/utils/http_server.py#L24

we don't use `AF_INET6` which is IPv6, so IPv6 support is unimportant.

Ref streamlink#2622 (comment)

---

```
$ streamlink https://www.youtube.com/channel/UCSrZ3UV4jOidv8ppoVuvW9Q/live --player-http -l debug
...
[cli][info] Starting player: /usr/bin/mpv
[cli.output][debug] Opening subprocess: /usr/bin/mpv "--force-media-title=Euronews English Live" http://127.0.0.1:35085/
```

```
$ streamlink https://www.youtube.com/channel/UCSrZ3UV4jOidv8ppoVuvW9Q/live --player-continuous-http -l debug
...
[cli][info] Starting player: /usr/bin/mpv
[cli.output][debug] Opening subprocess: /usr/bin/mpv "--force-media-title=Euronews English Live" http://127.0.0.1:39099/
[cli][info] Got HTTP request from libmpv
```

```
$ streamlink https://www.youtube.com/channel/UCSrZ3UV4jOidv8ppoVuvW9Q/live --player-external-http --player-external-http-port 33333
[cli][info] Starting server, access with one of:
[cli][info]  http://127.0.0.1:33333/
[cli][info]  http://127.0.0.53:33333/
[cli][info]  http://127.0.1.1:33333/
[cli][info] Got HTTP request from Mozilla/5.0 ...
[cli][info] Opening stream: 720p (hls)
```
@bastimeyer
Copy link
Member

host="127.0.0.1" is already the default parameter value on HTTPServer.bind():

def bind(self, host="127.0.0.1", port=0):

Just remove the default parameter values in streamlink_cli.main.create_http_server():

def create_http_server(host=None, port=0):
"""Creates a HTTP server listening on a given host and port.
If host is empty, listen on all available interfaces, and if port is 0,
listen on a random high port.
"""
try:
http = HTTPServer()
http.bind(host=host, port=port)

When --player-external-http is True, host=None is already set:

def output_stream_http(plugin, initial_streams, external=False, port=0):
"""Continuously output the stream over HTTP."""
global output
if not external:
if not args.player:
console.exit("The default player (VLC) does not seem to be "
"installed. You must specify the path to a player "
"executable with --player.")
title = create_title(plugin)
server = create_http_server()
player = output = PlayerOutput(args.player, args=args.player_args,
filename=server.url,
quiet=not args.verbose_player,
title=title)
try:
log.info("Starting player: {0}".format(args.player))
if player:
player.open()
except OSError as err:
console.exit("Failed to start player: {0} ({1})",
args.player, err)
else:
server = create_http_server(host=None, port=port)
player = None
log.info("Starting server, access with one of:")
for url in server.urls:
log.info(" " + url)

@back-to
Copy link
Collaborator Author

back-to commented Dec 26, 2020

host="127.0.0.1" is already the default parameter value on HTTPServer.bind():

well it is never called, that is basically the issue because None will overwrite it.

Just remove the default parameter values in streamlink_cli.main.create_http_server():

I could, but we would need to use always host and port
which should be acceptable

def create_http_server(host, port):

TypeError: create_http_server() missing 2 required positional arguments: 'host' and 'port'

@bastimeyer
Copy link
Member

Just pass the *args and **kwargs to HTTPServer.bind. create_http_server doesn't need to define its own parameter signature.

@back-to back-to changed the title cli.main: use '127.0.0.1' for --player-http / --player-continuous-http cli.main: use *_args, **_kwargs for create_http_server Dec 26, 2020
@back-to back-to added enhancement PR: squash commits Commits need to be squashed as a single commit - eg. multiple commits for a single component labels Dec 26, 2020
@back-to back-to merged commit 474325f into streamlink:master Dec 26, 2020
@back-to back-to deleted the 2622 branch December 26, 2020 16:03
Billy2011 pushed a commit to Billy2011/streamlink-27 that referenced this pull request Dec 28, 2020
…mlink#3450)

use `127.0.0.1` for local `create_http_server()`
use `0.0.0.0` for external `create_http_server()`

`--player-http` = ***127.0.0.1***
https://streamlink.github.io/cli.html#cmdoption-player-http

`--player-continuous-http` = ***127.0.0.1***
https://streamlink.github.io/cli.html#cmdoption-player-continuous-http

`--player-external-http` = ***None*** / ***0.0.0.0***
https://streamlink.github.io/cli.html#cmdoption-player-external-http
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement PR: squash commits Commits need to be squashed as a single commit - eg. multiple commits for a single component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http server binds to all hosts rather than localhost
2 participants