Skip to content

stream.dash: various SegmentList/SegmentTemplate fixes #5247

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

Merged
merged 4 commits into from
Mar 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
stream.dash: fix SegmentList child nodes
- Turn `SegmentList` into an only-child in `Period`, `AdaptationSet`
  and `Representation`
- Set `parent` type in `SegmentList`
- Turn `SegmentList.segments` from a property into a regular method,
  similar to `SegmentTemplate.segments()`
  • Loading branch information
bastimeyer committed Mar 14, 2023
commit 1d99b964de123ca341dea3b8ef66c25eb47bbf66
14 changes: 8 additions & 6 deletions src/streamlink/stream/dash_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ def __init__(self, *args, **kwargs) -> None:
class SegmentList(MPDNode):
__tag__ = "SegmentList"

parent: Union["Period", "AdaptationSet", "Representation"]

def __init__(self, *args, period: "Period", **kwargs) -> None:
super().__init__(*args, **kwargs)

Expand All @@ -548,7 +550,6 @@ def __init__(self, *args, period: "Period", **kwargs) -> None:
self.initialization = self.only_child(Initialization)
self.segment_urls = self.children(SegmentURL, minimum=1)

@property
def segments(self) -> Iterator[Segment]:
if self.initialization: # pragma: no branch
yield Segment(
Expand Down Expand Up @@ -636,6 +637,8 @@ def __init__(self, *args, **kwargs) -> None:
)

self.baseURLs = self.children(BaseURL)
self.segmentBase = self.only_child(SegmentBase, period=self.parent)
self.segmentList = self.only_child(SegmentList, period=self.parent)
self.segmentTemplate = self.only_child(SegmentTemplate, period=self.parent)
self.representations = self.children(Representation, minimum=1, period=self.parent)
self.contentProtection = self.children(ContentProtection)
Expand Down Expand Up @@ -894,7 +897,7 @@ def __init__(self, *args, period: "Period", **kwargs) -> None:
self.baseURLs = self.children(BaseURL)
self.subRepresentation = self.children(SubRepresentation)
self.segmentBase = self.only_child(SegmentBase, period=self.period)
self.segmentList = self.children(SegmentList, period=self.period)
self.segmentList = self.only_child(SegmentList, period=self.period)
self.segmentTemplate = self.only_child(SegmentTemplate, period=self.period)
self.contentProtection = self.children(ContentProtection)

Expand All @@ -914,7 +917,7 @@ def segments(self, **kwargs) -> Iterator[Segment]:
"""

# segmentBase = self.segmentBase or self.walk_back_get_attr("segmentBase")
segmentLists = self.segmentList or self.walk_back_get_attr("segmentList")
segmentList = self.segmentList or self.walk_back_get_attr("segmentList")
segmentTemplate = self.segmentTemplate or self.walk_back_get_attr("segmentTemplate")

if segmentTemplate:
Expand All @@ -925,9 +928,8 @@ def segments(self, **kwargs) -> Iterator[Segment]:
Bandwidth=int(self.bandwidth * 1000),
**kwargs,
)
elif segmentLists:
for segmentList in segmentLists:
yield from segmentList.segments
elif segmentList:
yield from segmentList.segments()
else:
yield Segment(
url=self.base_url,
Expand Down