Ejemplo n.º 1
0
        private async Task UpdateQueue()
        {
            if (client is null)
            {
                return;
            }

            var stream = await client.GetStreamAsync(Url);

            if (stream is null)
            {
                return;
            }

            var lastSegment = ParseSegmentFile(stream)?.Last();

            if (!lastSegment.Equals(recentSegment))
            {
                //Debug.WriteLine($"New segment!");

                recentSegment = lastSegment;

                hlsQueue.Enqueue(lastSegment);
            }
        }
Ejemplo n.º 2
0
        private static IEnumerable <HLSSegment> ParseSegmentFile(Stream stream)
        {
            using (var reader = new StreamReader(stream))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();

                    if (line is null)
                    {
                        continue;
                    }

                    // read normal segment data
                    if (line.StartsWith("#EXTINF"))
                    {
                        var segment = new HLSSegment();

                        segment.Duration = GetDuration(line);

                        // read next line with url
                        line = reader.ReadLine();

                        // skip if this line isn't link
                        if (line == null || !line.StartsWith("https"))
                        {
                            continue;
                        }

                        segment.Url = line;

                        yield return(segment);
                    }

                    // read prefetch
                    if (line.StartsWith("#EXT-X-TWITCH-PREFETCH"))
                    {
                        var segment = new HLSSegment();

                        segment.Prefetch = true;

                        var match = Regex.Match(line, ext_twitch_prefetch_re);

                        if (match.Success)
                        {
                            segment.Url = match.Groups[1].Value;
                        }

                        yield return(segment);
                    }
                }
            }
        }