Skip to content
Back to top
View this page
Edit this page

# Stream

All streams inherit from the `Stream` base class.

class streamlink.stream.Stream(session)

  Bases: `object`

  This is a base class that should be inherited when implementing different stream types. Should only be created by plugins.

  Parameters:

    session (Streamlink) -- Streamlink session instance

  open()

    Attempts to open a connection to the stream. Returns a file-like object that can be used to read the stream data.

    Raises:

      StreamError -- on failure

    Return type:

      StreamIO

class streamlink.stream.MuxedStream(session, *substreams, **options)

  Bases: `Stream`, `Generic`[`TSubstreams_co`]

  Muxes multiple streams into one output stream.

  Parameters:

    - session (streamlink.Streamlink) -- Streamlink session instance

    - substreams (TSubstreams_co) -- Video and/or audio streams

    - options -- Additional keyword arguments passed to `ffmpegmux.FFMPEGMuxer`. Subtitle streams need to be set via the `subtitles` keyword.

class streamlink.stream.HTTPStream(session, url, buffered=True, **kwargs)

  Bases: `Stream`

  An HTTP stream using the `requests` library.

  Parameters:

    - session (Streamlink) -- Streamlink session instance

    - url (str) -- The URL of the HTTP stream

    - buffered (bool) -- Wrap stream output in an additional reader-thread

    - kwargs -- Additional keyword arguments passed to `requests.Session.request()`

  args: dict

    A dict of keyword arguments passed to `requests.Session.request()`, such as method, headers, cookies, etc.

  property url: str

    The URL to the stream, prepared by `requests` with parameters read from `args`.

class streamlink.stream.HLSStream(session, url, multivariant=None, name=None, force_restart=False, start_offset=0, duration=None, **kwargs)

  Bases: `HTTPStream`

  Implementation of the Apple HTTP Live Streaming protocol.

  Parameters:

    - session (Streamlink) -- Streamlink session instance

    - url (str) -- The URL of the HLS playlist

    - multivariant (M3U8 | None) -- The parsed multivariant playlist

    - name (str | None) -- Optional name suffix for the stream's worker and writer threads

    - force_restart (bool) -- Start from the beginning after reaching the playlist's end

    - start_offset (float) -- Number of seconds to be skipped from the beginning

    - duration (float | None) -- Number of seconds until ending the stream

    - kwargs -- Additional keyword arguments passed to `requests.Session.request()`

  classmethod parse_variant_playlist(session, url, name_key='name', name_prefix='', check_streams=False, force_restart=False, name_fmt=None, start_offset=0, duration=None, **kwargs)

    Parse a variant playlist and return its streams.

    Parameters:

      - session (Streamlink) -- Streamlink session instance

      - url (str) -- The URL of the variant playlist

      - name_key (str) -- Prefer to use this key as stream name, valid keys are: name, pixels, bitrate

      - name_prefix (str) -- Add this prefix to the stream names

      - check_streams (bool) -- Only allow streams that are accessible

      - force_restart (bool) -- Start at the first segment even for a live stream

      - name_fmt (str | None) -- A format string for the name, allowed format keys are: name, pixels, bitrate

      - start_offset (float) -- Number of seconds to be skipped from the beginning

      - duration (float | None) -- Number of second until ending the stream

      - kwargs -- Additional keyword arguments passed to `HLSStream`, `MuxedHLSStream`, or `requests.Session.request()`

    Return type:

      dict[str, Self | MuxedHLSStream[Self]]

class streamlink.stream.MuxedHLSStream(session, video, audio, hlsstream=None, multivariant=None, force_restart=False, ffmpeg_options=None, **kwargs)

  Bases: `MuxedStream`[`TMuxedHLSStream_co`]

  Muxes multiple HLS video and audio streams into one output stream.

  Parameters:

    - session (Streamlink) -- Streamlink session instance

    - video (str) -- Video stream URL

    - audio (str | list[str]) -- Audio stream URL or list of URLs

    - hlsstream (type[TMuxedHLSStream_co] | None) -- The `HLSStream` class of each sub-stream

    - multivariant (M3U8 | None) -- The parsed multivariant playlist

    - force_restart (bool) -- Start from the beginning after reaching the playlist's end

    - ffmpeg_options (Mapping[str, Any] | None) -- Additional keyword arguments passed to `ffmpegmux.FFMPEGMuxer`

    - kwargs -- Additional keyword arguments passed to `HLSStream`

class streamlink.stream.DASHStream(session, mpd, video_representation=None, audio_representation=None, duration=None, **kwargs)

  Bases: `Stream`

  Implementation of the "Dynamic Adaptive Streaming over HTTP" protocol (MPEG-DASH)

  Parameters:

    - session (Streamlink) -- Streamlink session instance

    - mpd (MPD) -- Parsed MPD manifest

    - video_representation (Representation | None) -- Video representation

    - audio_representation (Representation | None) -- Audio representation

    - duration (float | None) -- Number of seconds until ending the stream

    - kwargs -- Additional keyword arguments passed to `requests.Session.request()`

  classmethod parse_manifest(session, url_or_manifest, period=0, with_video_only=False, with_audio_only=False, **kwargs)

    Parse a DASH manifest file and return its streams.

    Parameters:

      - session (Streamlink) -- Streamlink session instance

      - url_or_manifest (str) -- URL of the manifest file or an XML manifest string

      - period (int | str) -- Which MPD period to use (index number (int) or `id` attribute (str)) for finding representations

      - with_video_only (bool) -- Also return video-only streams, otherwise only return muxed streams

      - with_audio_only (bool) -- Also return audio-only streams, otherwise only return muxed streams

      - kwargs -- Additional keyword arguments passed to `DASHStream` or `requests.Session.request()`

    Return type:

      dict[str, DASHStream]