-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
stream.hls: remove Sequence named tuple wrapper #5526
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
bastimeyer
merged 4 commits into
streamlink:master
from
bastimeyer:stream/hls/refactor-segment
Oct 7, 2023
Merged
stream.hls: remove Sequence named tuple wrapper #5526
bastimeyer
merged 4 commits into
streamlink:master
from
bastimeyer:stream/hls/refactor-segment
Oct 7, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8e23005
to
f2b4b9c
Compare
14 tasks
6f17f38
to
4bb8cc1
Compare
4bb8cc1
to
134dc65
Compare
- Turn `Segment` and `Playlist` into dataclasses, so they can be subclassed - Update `TwitchSegment` and inherit from the default HLS `Segment` - Update `TwitchM3U8Parser` accordingly - Fix segment URL updates in `LTVHLSStreamWorker`
- Add `num` attribute to `Segment` and initialize with `-1` - Move sequence number logic from `HLSStreamWorker` to `M3U8Parser`: Update the `num` attribute of each playlist `Segment` after parsing instead of wrapping it in a new `Sequence` named tuple - Remove `Sequence` named tuple wrapper - Update various `Sequence` references in `HLSStream{Writer,Worker}` - Update generic typevar of `HLSStream{Writer,Worker,Reader}` - Update HLS subclasses accordingly in various plugins - Update tests
- Update method and attribute names after the removal of `Sequence` - Update method signatures - Change argument/keyword names from sequence(s) to segment(s) - Remove `sequences` arg from `HLSStreamWorker.process_segments()` as it's not needed anymore after the sequence number logic was moved to the parser - Keep "Sequence" names and log messages for everything that's about the order of segments in the playlist or the position in the stream - Update HLS subclasses accordingly in various plugins - Update tests
- Rename `stream.hls_playlist.load` to `stream.hls_playlist.parse_m3u8` - Replace `HLSStreamWorker._reload_playlist()` and `HLSStream._get_variant_playlist()` with direct `parse_m3u8()` calls, using dependency injection and the `HLSStream.__parser__` reference - Turn `M3U8` into a generic class and add covariant type-vars for the `Segment` and `Playlist` dataclasses - Turn `M3U8Parser` into a generic class and add covariant type-vars for the `M3U8` class, as well as for `Segment` and `Playlist` - Update `M3U8Parser.get_{segment,playlist}()` and add `M3U8Parser.__{segment,playlist}__` references, to avoid having to copy data when subclassing `Segment`/`Playlist` dataclasses - Update `TwitchHLSStream` and related classes: - Set concrete types for `TwitchM3U8` - Set concrete types for `TwitchM3U8Parser` - Set `TwitchM3U8Parser.__m3u8__` to `TwitchM3U8` - Set `TwitchM3U8Parser.__segment__` to `TwitchSegment` - Set `TwitchHLSStream.__parser__` to `TwitchM3U8Parser` Note: Some typing issues are still unresolved due to shortcomings of current PEP revisions and typing implementations.
134dc65
to
640b668
Compare
Rebased to As explained, some HLS internals got renamed. Here's a quick summary of the relevant stuff which could potentially be accessed by 3rd party plugins:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ref #5498
Turn
Segment
andPlaylist
into dataclasses, so they can be subclassedTwitchSegment
inherit fromSegment
TwitchM3U8Parser
accordinglyltv_lsm_lv
plugin (previously cloned theSegment
named tuple, now simply updates theuri
attribute)Remove
Sequence
named tuple wrapper, soHLSStream{Writer,Worker}
operate on theSegment
directlynum
attribute toSegment
and initialize with-1
HLSStreamWorker
toM3U8Parser
Sequence
references inHLSStream{Writer,Worker}
HLSStream{Writer,Worker,Reader}
I was thinking about adding a
segment
compatibility property with a deprecation warning toSegment
, so third-party plugin implementations which subclassHLSStream{Writer,Worker}
don't break when they still implement logic for theSequence
wrapper (where the actual segment was accessed via thesegment
attribute), but I decided against it, because (3) changes the names and signatures of some methods anyway. As said in Refactor segmented streams and use a common BaseSegment #5498, these are not public interfaces, so I don't care.Update class attributes and method names/signatures of
HLSStream{Writer,Worker}
after the removal ofSequence
sequences
arg fromHLSStreamWorker.process_segments()
as it's not needed anymore after the sequence number logic was moved to the parserRefactor M3U8 playlist loading and update/fix typing
stream.hls_playlist.load
tostream.hls_playlist.parse_m3u8
HLSStreamWorker._reload_playlist()
andHLSStream._get_variant_playlist()
with directparse_m3u8()
calls, using dependency injection and theHLSStream.__parser__
referenceM3U8
into a generic class and add covariant type-vars for theSegment
andPlaylist
dataclassesM3U8Parser
into a generic class and add covariant type-vars for theM3U8
class, as well asSegment
andPlaylist
There are still some typing issues left, but I didn't manage to fix it (yet). I believe there are currently some restrictions (PEP 696 - default values for
TypeVar
s), so unless the whole design of the parser and stuff gets rewritten, this can't be improved further. But I'm not 100% sure. Should be good enough though.I was also thinking about finally moving the HLS and DASH stuff into their own sub-packages, so we don't have multiple modules lying around in the
stream
package. This would even make more sense with my plans for theBaseSegment
stuff, so the HLS and DASH parsers don't have to import the segmented stream implementations, as theBaseSegment
definition would have to go there otherwise. Those changes don't belong in this PR though.Btw, I'm not expecting any reviews here, because it requires knowledge of the details of the HLS classes. I will merge this when I feel ready.