stream.hls: remove Sequence named tuple wrapper #5526
Merged
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
SegmentandPlaylistinto dataclasses, so they can be subclassedTwitchSegmentinherit fromSegmentTwitchM3U8Parseraccordinglyltv_lsm_lvplugin (previously cloned theSegmentnamed tuple, now simply updates theuriattribute)Remove
Sequencenamed tuple wrapper, soHLSStream{Writer,Worker}operate on theSegmentdirectlynumattribute toSegmentand initialize with-1HLSStreamWorkertoM3U8ParserSequencereferences inHLSStream{Writer,Worker}HLSStream{Writer,Worker,Reader}I was thinking about adding a
segmentcompatibility property with a deprecation warning toSegment, so third-party plugin implementations which subclassHLSStream{Writer,Worker}don't break when they still implement logic for theSequencewrapper (where the actual segment was accessed via thesegmentattribute), 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 ofSequencesequencesarg 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.loadtostream.hls_playlist.parse_m3u8HLSStreamWorker._reload_playlist()andHLSStream._get_variant_playlist()with directparse_m3u8()calls, using dependency injection and theHLSStream.__parser__referenceM3U8into a generic class and add covariant type-vars for theSegmentandPlaylistdataclassesM3U8Parserinto a generic class and add covariant type-vars for theM3U8class, as well asSegmentandPlaylistThere 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
TypeVars), 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
streampackage. This would even make more sense with my plans for theBaseSegmentstuff, so the HLS and DASH parsers don't have to import the segmented stream implementations, as theBaseSegmentdefinition 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.