Skip to content

Commit

Permalink
cli: implement --player-external-http-continuous
Browse files Browse the repository at this point in the history
  • Loading branch information
bastimeyer authored and back-to committed Aug 21, 2022
1 parent 556d112 commit 8c1430e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/streamlink_cli/argparser.py
Expand Up @@ -482,14 +482,33 @@ def build_parser():
useful to allow external devices like smartphones or streaming boxes to
watch streams they wouldn't be able to otherwise.
Behavior will be similar to the continuous HTTP option, but no player
program will be started, and the server will listen on all available
The default behavior is similar to the --player-continuous-http option,
but no player program will be started, and the server will listen on all available
connections instead of just in the local (loopback) interface.
Optionally, the --player-external-http-continuous option allows for disabling
the continuous run-mode, so that Streamlink will stop when the stream ends.
The URLs that can be used to access the stream will be printed to the
console, and the server can be interrupted using CTRL-C.
"""
)
player.add_argument(
"--player-external-http-continuous",
type=boolean,
metavar="{yes,true,1,on,no,false,0,off}",
default=True,
help="""
Set the run-mode of --player-external-http to continuous or non-continuous.
In the continuous run-mode, Streamlink will keep running after the stream has ended
and will wait for the next HTTP request being made unless it gets shut down via CTRL-C.
If set to non-continuous, Streamlink will stop once the stream has ended.
Default is true.
"""
)
player.add_argument(
"--player-external-http-port",
metavar="PORT",
Expand Down
14 changes: 12 additions & 2 deletions src/streamlink_cli/main.py
Expand Up @@ -197,6 +197,7 @@ def output_stream_http(
initial_streams: Dict[str, Stream],
formatter: Formatter,
external: bool = False,
continuous: bool = True,
port: int = 0,
):
"""Continuously output the stream over HTTP."""
Expand Down Expand Up @@ -267,6 +268,9 @@ def output_stream_http(
log.debug("Writing stream to player")
read_stream(stream_fd, server, prebuffer, formatter)

if not continuous:
break

server.close(True)

if player:
Expand Down Expand Up @@ -474,8 +478,14 @@ def handle_stream(plugin: Plugin, streams: Dict[str, Stream], stream_name: str)
log.info(f"Opening stream: {stream_name} ({stream_type})")
success = output_stream_passthrough(stream, formatter)
elif args.player_external_http:
return output_stream_http(plugin, streams, formatter, external=True,
port=args.player_external_http_port)
return output_stream_http(
plugin,
streams,
formatter,
external=True,
continuous=args.player_external_http_continuous,
port=args.player_external_http_port,
)
elif args.player_continuous_http and not file_output:
return output_stream_http(plugin, streams, formatter)
else:
Expand Down

0 comments on commit 8c1430e

Please sign in to comment.