예제 #1
0
        public static M3U FromString(string s)
        {
            // TODO : string.split is inefficient
            string[]     lines   = s.Split('\n');
            M3U          Out     = new M3U();
            List <Chunk> _chunks = new List <Chunk>();

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

                if (line.Contains("TARGETDURATION"))
                {
                    Out.TargetDuration = line.Split(':')[1];
                }

                if (line.Contains("ALLOW-CACHE"))
                {
                    Out.AllowCache = line.Split(':')[1] == "YES";
                }

                if (line.Contains("PLAYLIST-TYPE"))
                {
                    Out.PlaylistType = line.Split(':')[1];
                }

                if (line.Contains("KEY"))
                {
                    // TODO : Possible - key isn't in this file nor the url
                    Out.Key = new EncryptionKey(line.Split(':')[1] + (line.Split(':').Count() > 1 ? (":" + line.Split(':')[2]) : ""));
                }

                if (line.Contains("VERSION"))
                {
                    Out.Version = line.Split(':')[1];
                }

                if (line.Contains("MEDIA-SEQUENCE"))
                {
                    Out.MediaSequence = line.Split(':')[1];
                }

                if (line.Contains("EXTINF"))
                {
                    // TODO : Possible URL without http:// part or domain
                    _chunks.Add(new Chunk(line, lines[i + 1]));
                    i = i + 1;
                }
            }
            Out.Chunks = _chunks.ToArray();
            return(Out);
        }
예제 #2
0
        public void PromptParameters()
        {
            UI.Log("");
            UI.Log(" . . . . . . . . . . . ");
            UI.Log("    M3U8 Parser        ");
            UI.Log(" . . . . . . . . . . . ");
            UI.Log("");



Choosesrc:
            string src = UI.Prompt("Enter your M3U8 file URL or Enter ~filename.m3u8 to read from file. \n (You can also input the file to this CLI by replacing new lines with \\n)");

            if (src.StartsWith('~'))
            {
                try
                {
                    m3U = M3U.FromFile(src.TrimStart('~'));
                }
                catch (Exception ex)
                {
                    UI.LogError(ex);
                    goto Choosesrc;
                }
            }
            else if (src.StartsWith("#EXTM3U"))
            {
                try
                {
                    m3U = M3U.FromString(src.Replace("\\n", Environment.NewLine));
                    UI.Log("Parsed M3U from string");
                }
                catch (System.Exception ex)
                {
                    UI.LogError(ex);
                    goto Choosesrc;
                }
            }
            else
            {
                try
                {
                    m3U = M3U.FromURL(src);
                }
                catch (System.Exception ex)
                {
                    UI.LogError(ex);
                    goto Choosesrc;
                }
            }


            var p = m3U.GetCSA(UI);

            if (p.Item1)
            {
                Pp = p.Item2;
            }
            else
            {
                goto Choosesrc;
            }
        }