Skip to content

Commit

Permalink
[PATCH] stream.hls: turn url_master into property(streamlink#4643)
Browse files Browse the repository at this point in the history
with backwards compatibility for the deprecated url_master parameter,
and read the value from the parsed multivariant playlist instead, if it
exists.

See 7cb0ebe
  • Loading branch information
Billy2011 committed Jul 10, 2022
1 parent a3bf8fc commit 0a362db
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 132 deletions.
20 changes: 20 additions & 0 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
Deprecations
============

streamlink 2.27.4.0
-------------------

Deprecation of url_master in HLSStream
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The ``url_master`` parameter and attribute of the :py:class:`streamlink.stream.HLSStream`
and :py:class:`streamlink.stream.MuxedHLSStream` classes have been deprecated in favor of the ``multivariant`` parameter
and attribute. ``multivariant`` is an :py:class:`M3U8` reference of the parsed HLS multivariant playlist.


Removal of streamlink.plugin.api.utils
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The ``streamlink.plugin.api.utils`` module including the ``itertags`` function and export aliases for ``streamlink.utils.parse``
has been removed. Import the parse functions directly and find data in XML/HTML by parsing it via ``parse_{xml,html}`` and
applying XPath queries to the parsed result via the available methods provided by the ``lxml.etree`` API. The
``streamlink.plugin.api.validate`` module also has the necessary validation schema functions for this.


streamlink 2.27.0.0
-------------------

Expand Down
28 changes: 0 additions & 28 deletions src/streamlink/plugin/api/utils.py

This file was deleted.

14 changes: 12 additions & 2 deletions src/streamlink/stream/hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,14 @@ def __init__(
ffmpeg_options = ffmpeg_options or {}

super(MuxedHLSStream, self).__init__(session, *substreams, format="mpegts", maps=maps, **ffmpeg_options)
self.url_master = url_master
self._url_master = url_master
self.multivariant = multivariant if multivariant and multivariant.is_master else None

@property
def url_master(self):
"""Deprecated"""
return self.multivariant.uri if self.multivariant and self.multivariant.uri else self._url_master

def to_manifest_url(self):
url = self.multivariant.uri if self.multivariant and self.multivariant.uri else self.url_master

Expand Down Expand Up @@ -421,7 +426,7 @@ def __init__(
:param args: Additional keyword arguments passed to :meth:`requests.Session.request`
"""
super(HLSStream, self).__init__(session_, url, **args)
self.url_master = url_master
self._url_master = url_master
self.multivariant = multivariant if multivariant and multivariant.is_master else None
self.force_restart = force_restart
self.start_offset = start_offset
Expand All @@ -440,6 +445,11 @@ def __json__(self):

return json

@property
def url_master(self):
"""Deprecated"""
return self.multivariant.uri if self.multivariant and self.multivariant.uri else self._url_master

def to_manifest_url(self):
url = self.multivariant.uri if self.multivariant and self.multivariant.uri else self.url_master

Expand Down
12 changes: 12 additions & 0 deletions tests/stream/test_hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ def test_variant_playlist(self):
stream = next(iter(streams.values()))
assert repr(stream) == "<HLSStream ['hls', '{0}/720p.m3u8', '{0}/master.m3u8']>".format(base)

assert stream.multivariant is not None
assert stream.multivariant.uri == "{0}/master.m3u8".format(base)
assert stream.url_master == "{0}/master.m3u8".format(base)

def test_url_master(self):
session = Streamlink()
stream = HLSStream(session, "http://mocked/foo", url_master="http://mocked/master.m3u8")

assert stream.multivariant is None
assert stream.url == "http://mocked/foo"
assert stream.url_master == "http://mocked/master.m3u8"


class EventedHLSReader(HLSStreamReader):
__writer__ = EventedHLSStreamWriter
Expand Down
102 changes: 0 additions & 102 deletions tests/test_plugin_utils.py

This file was deleted.

0 comments on commit 0a362db

Please sign in to comment.