Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream.hls: fix byterange parser #4301

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/streamlink/stream/hls_playlist.py
Expand Up @@ -27,7 +27,7 @@ class ExtInf(NamedTuple):
# EXT-X-BYTERANGE
class ByteRange(NamedTuple): # version >= 4
range: int
offset: int
offset: Optional[int]


# EXT-X-DATERANGE
Expand Down Expand Up @@ -152,7 +152,7 @@ def is_date_in_daterange(cls, date: Segment.date, daterange: DateRange):
class M3U8Parser:
_extinf_re = re.compile(r"(?P<duration>\d+(\.\d+)?)(,(?P<title>.+))?")
_attr_re = re.compile(r"([A-Z\-]+)=(\d+\.\d+|0x[0-9A-z]+|\d+x\d+|\d+|\"(.+?)\"|[0-9A-z\-]+)")
_range_re = re.compile(r"(?P<range>\d+)(@(?P<offset>.+))?")
_range_re = re.compile(r"(?P<range>\d+)(?:@(?P<offset>\d+))?")
_tag_re = re.compile(r"#(?P<tag>[\w-]+)(:(?P<value>.+))?")
_res_re = re.compile(r"(\d+)x(\d+)")

Expand Down Expand Up @@ -214,7 +214,10 @@ def parse_bool(value: str) -> bool:

def parse_byterange(self, value: str) -> Optional[ByteRange]:
match = self._range_re.match(value)
return None if match is None else ByteRange(int(match.group("range")), int(match.group("offset") or 0))
if match is None:
return None
_range, offset = match.groups()
return ByteRange(int(_range), int(offset) if offset is not None else None)

def parse_extinf(self, value: str) -> Tuple[float, Optional[str]]:
match = self._extinf_re.match(value)
Expand Down