CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-streamlink

Command-line utility and Python library for extracting video streams from various streaming services

Overview
Eval results
Files

stream-access.mddocs/

Stream Access

Streamlink provides multiple stream types for different protocols and use cases. All streams inherit from the base Stream class and provide methods for opening connections and accessing stream data.

Capabilities

Base Stream Class

The abstract base class that all stream types inherit from.

class Stream:
    def __init__(self, session):
        """
        Initialize stream with Streamlink session.
        
        Parameters:
        - session: Streamlink session instance
        """

    def open(self) -> StreamIO:
        """
        Open stream connection for reading.
        
        Returns:
        StreamIO object for data access
        
        Raises:
        StreamError: If stream cannot be opened
        """

    def to_url(self) -> str:
        """
        Convert stream to direct URL if supported.
        
        Returns:
        Direct stream URL
        
        Raises:
        TypeError: If stream type doesn't support URL conversion
        """

    def to_manifest_url(self) -> str:
        """
        Convert stream to manifest URL if supported.
        
        Returns:
        Manifest URL (e.g., M3U8 or MPD)
        
        Raises:
        TypeError: If stream type doesn't support manifest URLs
        """

    @classmethod
    def shortname(cls) -> str:
        """
        Get stream type identifier.
        
        Returns:
        Short name identifying the stream type
        """

    @property
    def json(self) -> str:
        """JSON representation of stream metadata"""

Stream I/O Base Class

Base class for stream data access with file-like interface.

class StreamIO:
    """Base class for stream I/O operations with file-like interface"""

HTTP Streams

Direct HTTP streams for simple video/audio files served over HTTP.

class HTTPStream(Stream):
    def __init__(self, session, url, buffered=True, **kwargs):
        """
        Initialize HTTP stream.
        
        Parameters:
        - session: Streamlink session
        - url: HTTP URL to stream
        - buffered: Whether to use buffered I/O (default: True)
        - **kwargs: Additional request arguments (headers, params, etc.)
        """

    @property
    def url(self) -> str:
        """Prepared request URL"""

    @property  
    def args(self) -> dict:
        """Request arguments dictionary"""

HLS Streams

HTTP Live Streaming (HLS) support for adaptive bitrate streaming.

class HLSStream(Stream):
    """
    HTTP Live Streaming implementation supporting:
    - M3U8 playlist parsing
    - Adaptive bitrate streaming  
    - AES encryption
    - Subtitle tracks
    """

class MuxedHLSStream(Stream):
    """
    HLS stream combining multiple tracks (video, audio, subtitles).
    
    Automatically muxes separate video and audio streams into
    a single output stream using FFmpeg.
    """

DASH Streams

Dynamic Adaptive Streaming over HTTP for modern adaptive streaming.

class DASHStream(Stream):
    """
    DASH (Dynamic Adaptive Streaming over HTTP) implementation supporting:
    - MPD manifest parsing
    - Multi-period content
    - Multiple representations
    - Audio/video track selection
    """

Muxed Streams

Generic muxed streams combining multiple input streams using FFmpeg.

class MuxedStream(Stream):
    def __init__(self, session, *substreams, **options):
        """
        Combine multiple streams into a single output.
        
        Parameters:
        - session: Streamlink session
        - *substreams: Input streams to mux together
        - **options: FFmpeg options and stream mapping
        """

Stream Wrappers

Utility classes for adapting different data sources to the StreamIO interface.

class StreamIOWrapper:
    """Wraps non-IOBase file-like objects to provide consistent interface"""

class StreamIOIterWrapper:
    """Wraps iterators as file-like objects for streaming data"""

class StreamIOThreadWrapper:
    """Adds threading support to stream I/O operations"""

Usage Examples

Basic Stream Access

import streamlink

# Get streams for a URL
streams = streamlink.streams("https://www.twitch.tv/example")

if streams:
    # Access best quality stream
    best_stream = streams['best']
    print(f"Stream type: {best_stream.shortname()}")
    
    # Open stream for reading
    with best_stream.open() as stream_fd:
        # Read first 1KB
        data = stream_fd.read(1024)
        print(f"Read {len(data)} bytes")

Stream Quality Selection

streams = streamlink.streams("https://example.com/stream")

# Check available qualities
print("Available streams:")
for quality, stream in streams.items():
    print(f"  {quality}: {stream}")

# Select specific quality
if '720p' in streams:
    selected_stream = streams['720p']
elif 'best' in streams:
    selected_stream = streams['best']
else:
    print("No suitable stream found")

HTTP Stream Usage

from streamlink.stream import HTTPStream

session = streamlink.Streamlink()

# Create HTTP stream with custom headers
http_stream = HTTPStream(
    session, 
    "https://example.com/video.mp4",
    headers={'Referer': 'https://example.com'}
)

# Get direct URL
try:
    direct_url = http_stream.to_url()
    print(f"Direct URL: {direct_url}")
except TypeError:
    print("Stream doesn't support direct URL access")

# Read stream data
with http_stream.open() as fd:
    chunk = fd.read(8192)
    while chunk:
        # Process chunk
        process_data(chunk)
        chunk = fd.read(8192)

HLS Stream Features

streams = streamlink.streams("https://example.com/hls_stream")

for quality, stream in streams.items():
    if hasattr(stream, 'to_manifest_url'):
        try:
            manifest_url = stream.to_manifest_url()
            print(f"{quality}: {manifest_url}")
        except TypeError:
            pass

Muxed Stream Creation

from streamlink.stream import MuxedStream

# Assuming we have separate video and audio streams
video_stream = streams.get('720p_video')
audio_stream = streams.get('audio_en')

if video_stream and audio_stream:
    # Create muxed stream
    muxed = MuxedStream(
        session,
        video_stream,
        audio_stream,
        format='mp4',
        acodec='aac',
        vcodec='h264'
    )
    
    with muxed.open() as fd:
        # Process combined stream
        data = fd.read(1024)

Stream Type Detection

streams = streamlink.streams("https://example.com")

for quality, stream in streams.items():
    stream_type = stream.shortname()
    
    if stream_type == 'hls':
        print(f"{quality}: HLS stream")
    elif stream_type == 'dash':  
        print(f"{quality}: DASH stream")
    elif stream_type == 'http':
        print(f"{quality}: HTTP stream")
    elif stream_type == 'muxed':
        print(f"{quality}: Muxed stream")

Install with Tessl CLI

npx tessl i tessl/pypi-streamlink

docs

data-validation.md

index.md

options-configuration.md

plugin-system.md

session-management.md

stream-access.md

utilities.md

tile.json