Streamlink
Streamlink is a command-line utility and Python library that extracts streams from various online services (like Twitch, YouTube, etc.) and pipes them into a video player of choice, such as VLC or mpv. It aims to provide a lightweight alternative to resource-heavy and unoptimized websites. The library is actively maintained, with frequent minor and patch releases, and the current stable version is 8.3.0.
Common errors
-
No playable streams found on this URL: <URL>
cause The Streamlink plugin for the given URL could not find any streams, often due to changes on the streaming service's side, an invalid URL, or the stream being offline.fixFirst, verify the URL is correct and the stream is live. Try updating Streamlink (`pip install --upgrade streamlink`) to get the latest plugin definitions. You can also run with `--json` to see raw output or `--loglevel debug` for more details. -
Error: Couldn't launch the Stream Unexpected Version check output. / urllib3 (X.Y) or chardet (X.Y.Z) doesn't match a supported version!
cause A common cause is an incompatibility between Streamlink's `urllib3` dependency (or `requests`' dependency on `urllib3`) and Streamlink's expected version.fixUpgrade Streamlink and its dependencies: `pip install --upgrade streamlink`. This typically resolves `urllib3` version mismatches. -
[stream.hls][warning] Encountered a stream discontinuity. This is unsupported and will result in incoherent output data.
cause This usually indicates an issue with the HLS stream itself, where segments are not continuous or metadata changes unexpectedly, leading to corrupted output or incomplete recordings.fixThis often points to a problem with the source stream. Try different stream qualities (`best`, `worst`, or specific resolutions). If recording, try adjusting `--hls-segment-threads` or `--hls-live-restart`. Sometimes, the issue resolves itself or is temporary. -
streamlink: error: unrecognized arguments: <some-argument>
cause This error occurs when Streamlink's CLI parser encounters an argument it doesn't recognize. This often happens after major version updates where CLI arguments are changed or deprecated, or when an outdated configuration file passes invalid options.fixReview your Streamlink command-line arguments and any custom configuration files. Pay close attention to changes in how `--player` and `--player-args` work since version 6.0.0. Remove or update old config files. Run `streamlink --help` for current argument options.
Warnings
- breaking Streamlink 8.0.0 dropped support for Python 3.9. Projects must use Python 3.10 or newer.
- breaking The `url_master` argument and attribute in `HLSStream` and `MuxedHLSStream` were removed in Streamlink 8.0.0.
- breaking Streamlink 8.0.0 updated its `urllib3` dependency, requiring `>=2.0.0`.
- deprecated Imports of re-exported attributes from `streamlink.stream` and `streamlink.utils` are deprecated.
- gotcha The `--player` CLI argument changed in Streamlink 6.0.0 to be path-only. It no longer accepts additional player arguments.
- gotcha Old and deprecated config file paths (including plugin-specific ones) are no longer supported since Streamlink 7.0.0.
Install
-
pip install streamlink
Imports
- Streamlink
from streamlink import Streamlink
- PluginError
from streamlink.plugins import PluginError
from streamlink.exceptions import PluginError
- NoPluginError
from streamlink.plugins import NoPluginError
from streamlink.exceptions import NoPluginError
- Plugin
from streamlink.plugins import Plugin
from streamlink.plugin import Plugin
- HTTPSession
from streamlink.plugin.api.http_session import HTTPSession
session = Streamlink() http_session = session.http
Quickstart
import streamlink
import os
# Initialize a Streamlink session
session = streamlink.Streamlink()
# Example: Set a session option, e.g., for logging level
session.set_option("log-level", "info")
# Define the URL and desired stream quality
stream_url = "https://www.twitch.tv/twitchdev"
desired_quality = "best"
try:
# Attempt to find streams for the URL
streams = session.streams(stream_url)
if not streams:
print(f"No streams found for {stream_url}")
else:
# Get the desired stream
stream = streams.get(desired_quality)
if stream:
print(f"Opening {desired_quality} stream from {stream_url}")
# Open the stream and read a chunk (or pipe to a player)
with stream.open() as fd:
# This example just reads a small chunk. For actual playback,
# you'd typically pipe this to an external player.
# For example, to play with VLC (requires VLC to be installed and in PATH):
# import subprocess
# player_cmd = ["vlc", "-"]
# p = subprocess.Popen(player_cmd, stdin=subprocess.PIPE)
# for chunk in iter(lambda: fd.read(8192), b''):
# p.stdin.write(chunk)
# p.stdin.close()
# p.wait()
print(f"Successfully accessed {desired_quality} stream.")
# For a real application, you'd stream the data to a player or file
else:
print(f"Stream quality '{desired_quality}' not available. Available: {', '.join(streams.keys())}")
except streamlink.exceptions.NoPluginError:
print(f"No plugin found for URL: {stream_url}")
except streamlink.exceptions.PluginError as e:
print(f"Plugin error: {e}")