Example #1
0
        public static VodPlaylist Parse(string tempDir, string playlistStr, string urlPrefix)
        {
            VodPlaylist playlist = new VodPlaylist();

            List <string> lines = playlistStr.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();

            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i];

                if (line.StartsWith("#EXT-X-VERSION", StringComparison.OrdinalIgnoreCase))
                {
                    int version = int.Parse(line.Substring(line.LastIndexOf(":") + 1).TrimEnd(), NumberStyles.Integer, CultureInfo.InvariantCulture);

                    if (version == 4)
                    {
                        return(ParseV4(tempDir, lines, urlPrefix));
                    }
                    else
                    {
                        return(ParseV3(tempDir, lines, urlPrefix));
                    }
                }
            }

            return(playlist);
        }
Example #2
0
        private static VodPlaylist ParseV4(string tempDir, List <string> lines, string urlPrefix)
        {
            VodPlaylist playlist = new VodPlaylist();

            int    partCounter    = 0;
            double lengthBuffer   = 0;
            string currentPartStr = null;

            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i];

                if (line.StartsWith("#EXTINF", StringComparison.OrdinalIgnoreCase))
                {
                    string partStr = lines[i + 2];

                    if (string.IsNullOrWhiteSpace(currentPartStr))
                    {
                        currentPartStr = partStr;
                    }

                    if (!currentPartStr.Equals(partStr))
                    {
                        playlist.Add(new VodPlaylistPart(lengthBuffer, urlPrefix + currentPartStr, Path.Combine(tempDir, partCounter.ToString("D8") + ".ts")));
                        currentPartStr = partStr;
                        lengthBuffer   = 0;
                        partCounter++;
                    }

                    lengthBuffer += Math.Max(double.Parse(line.Substring(line.LastIndexOf(":") + 1).TrimEnd(','), NumberStyles.Any, CultureInfo.InvariantCulture), 0);

                    i++;
                }
            }

            if (!string.IsNullOrWhiteSpace(currentPartStr) && lengthBuffer > 0)
            {
                playlist.Add(new VodPlaylistPart(lengthBuffer, urlPrefix + currentPartStr, Path.Combine(tempDir, partCounter.ToString("D8") + ".ts")));
            }

            return(playlist);
        }
Example #3
0
        public static VodPlaylist Parse(string tempDir, string playlistStr, string urlPrefix)
        {
            VodPlaylist playlist = new VodPlaylist();

            List <string> lines = playlistStr.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();

            int indexCounter = 0;
            int partCounter  = 0;

            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i];

                if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#EXT-X-TWITCH", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                if (line.StartsWith("#EXTINF", StringComparison.OrdinalIgnoreCase))
                {
                    playlist.Add(new VodPlaylistPartExt(indexCounter, line, lines[i + 1], urlPrefix, Path.Combine(tempDir, partCounter.ToString("D8") + ".ts")));
                    partCounter++;
                    i++;
                }
                else
                {
                    playlist.Add(new VodPlaylistPart(indexCounter, line));
                }

                indexCounter++;
            }

            if (!playlist.Last().GetOutput().Equals("#EXT-X-ENDLIST", StringComparison.OrdinalIgnoreCase))
            {
                playlist.Add(new VodPlaylistPart(indexCounter, "#EXT-X-ENDLIST"));
            }

            return(playlist);
        }
Example #4
0
        private static VodPlaylist ParseV3(string tempDir, List <string> lines, string urlPrefix)
        {
            VodPlaylist playlist = new VodPlaylist();

            int partCounter = 0;

            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i];

                if (line.StartsWith("#EXTINF", StringComparison.OrdinalIgnoreCase))
                {
                    double length = Math.Max(double.Parse(line.Substring(line.LastIndexOf(":") + 1).TrimEnd(','), NumberStyles.Any, CultureInfo.InvariantCulture), 0);

                    playlist.Add(new VodPlaylistPart(length, urlPrefix + lines[i + 1], Path.Combine(tempDir, partCounter.ToString("D8") + ".ts")));
                    partCounter++;
                    i++;
                }
            }

            return(playlist);
        }
Example #5
0
        public static VodPlaylist Parse(String tempDir, String playlistStr, String urlPrefix)
        {
            VodPlaylist playlist = new VodPlaylist();

            List <String> lines = playlistStr.Split(new String[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();

            var partCounter = 0;

            for (var i = 0; i < lines.Count; i++)
            {
                var line = lines[i];

                if (line.StartsWith("#EXTINF", StringComparison.OrdinalIgnoreCase))
                {
                    var length = Math.Max(Double.Parse(line.Substring(line.LastIndexOf(":") + 1).TrimEnd(','), NumberStyles.Any, CultureInfo.InvariantCulture), 0);

                    playlist.Add(new VodPlaylistPart(length, urlPrefix + lines[i + 1], Path.Combine(tempDir, partCounter.ToString("D8") + ".ts")));
                    partCounter++;
                    i++;
                }
            }

            return(playlist);
        }