Example #1
0
        static public M3UStream Create(string url, string content)
        {
            var result = new M3UStream(url);

            result.Parse(content);
            return(result);
        }
Example #2
0
        protected override void Parse(string content)
        {
            var lines = ParseLines(content);

            for (var i = 1; i < lines.Length; i++)
            {
                var line = lines[i].Trim();
                if (!line.StartsWith("#"))
                {
                    continue;
                }

                var split = line.Substring(1).Split(':');

                var name  = split[0];
                var value = split.Length >= 2 ? split[1] : "";

                switch (name)
                {
                case "EXT-X-TARGETDURATION":
                    this.Duration = Int32.Parse(value);
                    break;

                //oh, how sweet. a header for us to entirely ignore. we'll always use cache.
                case "EXT-X-ALLOW-CACHE":
                    break;

                case "EXT-X-VERSION":
                    break;

                case "EXT-X-MEDIA-SEQUENCE":
                    break;

                case "EXT-X-STREAM-INF":
                    var   resolution = 0;
                    Match match      = Regex.Match(value, @"RESOLUTION=(?<resolution>\d+)");
                    if (match.Success)
                    {
                        resolution = Convert.ToInt32(match.Groups["resolution"].Value);
                    }

                    var stream = new M3UStream(this.Url + lines[i + 1].Trim())
                    {
                        Resolution = resolution
                    };

                    this.Streams.Add(stream);

                    break;
                }
            }
        }
Example #3
0
        static public M3UContent CreateFromUrl(string url)
        {
            using (var http = new HttpClient())
            {
                var content = http.GetStringAsync(url.Trim()).Result;

                var lines = ParseLines(content);

                if (lines.Any(l => l.StartsWith("#EXTINF:")))
                {
                    return(M3UStream.Create(url, content));
                }
                else
                {
                    return(M3UManifest.Create(url, content));
                }
            }
        }