def segment_numbers(self): """ yield the segment number and when it will be available There are two cases for segment number generation, static and dynamic. In the case of static stream, the segment number starts at the startNumber and counts up to the number of segments that are represented by the periods duration. In the case of dynamic streams, the segments should appear at the specified time in the simplest case the segment number is based on the time since the availabilityStartTime :return: """ log.debug( "Generating segment numbers for {0} playlist (id={1})".format( self.root.type, self.parent.id)) if self.root.type == u"static": available_iter = repeat(epoch_start) duration = self.period.duration.seconds or self.root.mediaPresentationDuration.seconds if duration: number_iter = range(self.startNumber, int(duration / self.duration_seconds) + 1) else: number_iter = count(self.startNumber) else: now = datetime.datetime.now(utc) if self.presentationTimeOffset: since_start = (now - self.presentationTimeOffset ) - self.root.availabilityStartTime available_start_date = self.root.availabilityStartTime + self.presentationTimeOffset + since_start available_start = available_start_date else: since_start = now - self.root.availabilityStartTime available_start = now # if there is no delay, use a delay of 3 seconds suggested_delay = datetime.timedelta( seconds=(self.root.suggestedPresentationDelay.total_seconds( ) if self.root.suggestedPresentationDelay else 3)) # the number of the segment that is available at NOW - SUGGESTED_DELAY - BUFFER_TIME number_iter = count(self.startNumber + int((since_start - suggested_delay - self.root.minBufferTime).total_seconds() / self.duration_seconds)) # the time the segment number is available at NOW available_iter = count_dt( available_start, step=datetime.timedelta(seconds=self.duration_seconds)) for number, available_at in izip(number_iter, available_iter): yield number, available_at
def segment_numbers(self): """ yield the segment number and when it will be available There are two cases for segment number generation, static and dynamic. In the case of static stream, the segment number starts at the startNumber and counts up to the number of segments that are represented by the periods duration. In the case of dynamic streams, the segments should appear at the specified time in the simplest case the segment number is based on the time since the availabilityStartTime :return: """ log.debug("Generating segment numbers for {0} playlist (id={1})".format(self.root.type, self.parent.id)) if self.root.type == u"static": available_iter = repeat(epoch_start) duration = self.period.duration.seconds or self.root.mediaPresentationDuration.seconds if duration: number_iter = range(self.startNumber, int(duration / self.duration_seconds) + 1) else: number_iter = count(self.startNumber) else: now = datetime.datetime.now(utc) if self.presentationTimeOffset: since_start = (now - self.presentationTimeOffset) - self.root.availabilityStartTime available_start_date = self.root.availabilityStartTime + self.presentationTimeOffset + since_start available_start = available_start_date else: since_start = now - self.root.availabilityStartTime available_start = now # if there is no delay, use a delay of 3 seconds suggested_delay = datetime.timedelta(seconds=(self.root.suggestedPresentationDelay.total_seconds() if self.root.suggestedPresentationDelay else 3)) # the number of the segment that is available at NOW - SUGGESTED_DELAY - BUFFER_TIME number_iter = count(self.startNumber + int((since_start - suggested_delay - self.root.minBufferTime).total_seconds() / self.duration_seconds)) # the time the segment number is available at NOW available_iter = count_dt(available_start, step=datetime.timedelta(seconds=self.duration_seconds)) for number, available_at in izip(number_iter, available_iter): yield number, available_at