human
What is a the Python program you requested given the following:
I am working on the file "IntroductionStreamingAdaptatif/Introduction au streaming adaptatif.ipynb".
The first task is:
Playlist
Chaque playlist pointe les segments de la séquence
/high/LlamaDrama.m3u8
```#EXTM3U
EXT-X-VERSION:3
EXT-X-TARGETDURATION:4
EXT-X-MEDIA-SEQUENCE:0
EXTINF:4.000000,
http://localhost:8000/high/LlamaDrama0.ts
EXTINF:4.000000,
http://localhost:8000/high/LlamaDrama1.ts
EXTINF:4.000000,
http://localhost:8000/high/LlamaDrama2.ts
EXTINF:4.000000,
http://localhost:8000/high/LlamaDrama3.ts
...
EXTINF:4.000000,
http://localhost:8000/high/LlamaDrama21.ts
EXTINF:1.875000,
http://localhost:8000/high/LlamaDrama22.ts
EXT-X-ENDLIST```
Client HLS
La classe HLS permet d'itérer a traver les segments.
Le temps est mesuré, lors du téléchargment du segment.
En combinant le temps et la taille du fichier, on obtient la vitesse.
Le StreamEngine choisit le stream approprié en fonction de la vitesse.

@startuml
skinparam style strictuml
skinparam dpi 300
class HLS << iterable >> {
    ByteIO next()
}
class StreamEngine {
    Stream selectStream(speed)
}
HLS -right-> StreamEngine
@enduml
Classe HLS
Le patron Iterator est utilisé pour itérer à travers l'ensemble des segments de la séquence.
Can you write Python program for it?
assistant
#Here is the Python program you requested.

class HLS:
    
    speed = 0 # Bits / second
    i = 0
    
    def __init__(self, uri):
        self.selector = StreamEngine(uri)
    
    def __iter__(self):
        return self
    
    def __next__(self):
        stream = self.selector.selectStream(self.speed)
        
        if self.i < len(stream.segments):
            startTime = time()
            buf = getSegment(stream.segments[self.i])
            self.speed = round((buf.getbuffer().nbytes*8) / (time() - startTime))
            print('%d bits/s' %self.speed)
            self.i += 1
            return buf
        else:
            raise StopIteration