-
Notifications
You must be signed in to change notification settings - Fork 481
Add Segment.media_Sequence #310
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
Add Segment.media_Sequence #310
Conversation
@@ -174,6 +174,9 @@ def _initialize_attributes(self): | |||
for attr, param in self.simple_attributes: | |||
setattr(self, attr, self.data.get(param)) | |||
|
|||
for i, segment in enumerate(self.segments, self.media_sequence or 0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I learned something new here :) I didn't know enumerate
would work with two sources :)
Just out of curiosity, why does it return first the number iterator and secondly the list iterator? (since they were passed in other order)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two tricks here.
First, enumerate has a two argument form: iterable
, start_number
. For us, self.segments
is the iterable, since the SegmentList
type can be iterated. We want to start counting from the media sequence number, so we use it as the second argument.
Second, the self.media_sequence or 0
trick. I want to handle the case where media_sequence
is None
and treat that ias 0
, as per the HLS spec. The or
operator takes the left argument if it's truthy (None
isn't) and the right operator if it's not.
None or 0 # Picks 0
0 or 0 # Picks the second 0
1 or 0 # Picks 1
2 or 0 # Picks 2
# etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool ty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another amazing piece of work! ty man
Thank you @bbayles amazing work! |
18df216
to
4d8a3f5
Compare
OK, this is rebased. Thanks! |
Thank you, @bbayles merged. |
Re: Issue 308, this PR adds a
media_sequence
attribute toSegment
objects.From RFC 8216:
It's useful to have access to the Media Sequence number on the
Segment
object because this value can be used for the initialization vector (section 5.2). It's also useful for tracking changes between requests of live playlists.