{"library":"streamlink","title":"Streamlink","type":"library","description":"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.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install streamlink"],"cli":{"name":"streamlink","version":"streamlink 8.4.0"}},"imports":["from streamlink import Streamlink","from streamlink.exceptions import PluginError","from streamlink.exceptions import NoPluginError","from streamlink.plugin import Plugin","session = Streamlink()\nhttp_session = session.http"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://streamlink.github.io","github":"https://github.com/streamlink/streamlink","docs":"https://streamlink.github.io/","changelog":null,"pypi":"https://pypi.org/project/streamlink/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import streamlink\nimport os\n\n# Initialize a Streamlink session\nsession = streamlink.Streamlink()\n\n# Example: Set a session option, e.g., for logging level\nsession.set_option(\"log-level\", \"info\")\n\n# Define the URL and desired stream quality\nstream_url = \"https://www.twitch.tv/twitchdev\"\ndesired_quality = \"best\"\n\ntry:\n    # Attempt to find streams for the URL\n    streams = session.streams(stream_url)\n    if not streams:\n        print(f\"No streams found for {stream_url}\")\n    else:\n        # Get the desired stream\n        stream = streams.get(desired_quality)\n        if stream:\n            print(f\"Opening {desired_quality} stream from {stream_url}\")\n            # Open the stream and read a chunk (or pipe to a player)\n            with stream.open() as fd:\n                # This example just reads a small chunk. For actual playback,\n                # you'd typically pipe this to an external player.\n                # For example, to play with VLC (requires VLC to be installed and in PATH):\n                # import subprocess\n                # player_cmd = [\"vlc\", \"-\"]\n                # p = subprocess.Popen(player_cmd, stdin=subprocess.PIPE)\n                # for chunk in iter(lambda: fd.read(8192), b''):\n                #     p.stdin.write(chunk)\n                # p.stdin.close()\n                # p.wait()\n                print(f\"Successfully accessed {desired_quality} stream.\")\n                # For a real application, you'd stream the data to a player or file\n        else:\n            print(f\"Stream quality '{desired_quality}' not available. Available: {', '.join(streams.keys())}\")\nexcept streamlink.exceptions.NoPluginError:\n    print(f\"No plugin found for URL: {stream_url}\")\nexcept streamlink.exceptions.PluginError as e:\n    print(f\"Plugin error: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to use Streamlink programmatically to find and access streams from a given URL. It initializes a Streamlink session, sets an option, resolves streams for a Twitch URL, and attempts to open the 'best' quality stream. For actual media playback, the stream's file-like object would typically be piped to an external video player process.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}