Example #1
0
        public static void WriteToConsole(string text, bool lineBreaks = false, bool refresh = false, bool bypassThreadLock = false)
        {
            if (!bypassThreadLock)
            {
                if (_pause)
                {
                    lock (locker)
                    {
                        Monitor.Wait(locker);
                    }
                }
            }

            int running = 0;

            for (int idx = 0; idx < concurrentTasks.Length; idx++)
            {
                if (tasksRunning[idx] == true)
                {
                    Console.SetCursorPosition(0, topBuffer + idx);
                    running++;
                    int d = Console.BufferWidth - concurrentTasks[idx].Length;
                    Console.Write($"{concurrentTasks[idx]}{new string(' ', d < 0 ? 0 : d)}");
                }
            }
            if (text == null && refresh == false)
            {
                return;
            }
            buffer.ModifySize((bufferw - ((topBuffer - 1) * 2)) - concurrentTasks.Length);
            if (lineBreaks)
            {
                foreach (string str in text.Split('\n').Reverse())
                {
                    buffer.push_back(str);
                }
            }
            else
            {
                buffer.push_back(text);
            }

            string x = buffer.ToString();

            Console.SetCursorPosition(0, running > 0 ? topBuffer + running : topBuffer);
            Console.Write(x);
            WriteTop();
            Console.SetCursorPosition(0, 0);
        }
Example #2
0
        private void ParseM3U()
        {
            bool flg = false;

            for (int idx = 0; idx < m3u8Info.Length; idx++)
            {
                if (!flg)
                {
                    if (m3u8Info[idx][0] == '#' && m3u8Info[idx + 1][0] == '#')
                    {
                        headers.Add(m3u8Info[idx]);
                        continue;
                    }
                    else
                    {
                        parts = new ExList <m3Object>((m3u8Info.Length / 2) - (headers.Count - 3), false);
                        flg   = true;
                        idx--;
                        continue;
                    }
                }

                if (idx == m3u8Info.Length - 1)
                {
                    break;
                }

                parts.push_back(new m3Object(m3u8Info[idx], m3u8Info[idx + 1].IsValidUri() ? m3u8Info[idx + 1] : $"{bPath}/{m3u8Info[idx + 1]}"));
                idx++;
            }

            for (int idx = 0; idx < headers.Count; idx++)
            {
                string[] a = headers[idx].Replace("\"", string.Empty).Split(':');
                switch (a[0])
                {
                case "#EXT-X-KEY":
                {
                    encrypted = true;
                    string[] mkpair = a[1].Split(',');
                    mkpair[0] = mkpair[0].SkipCharSequence("METHOD=".ToCharArray());
                    switch (mkpair[0])
                    {
                    case "AES-128":
                        encType = encrpytionType.AES128;
                        break;

                    default:
                        throw new Exception("There's no decryption support for this encryption method at the moment.");
                    }
                    webClient.Headers = collection;
                    encKey            = webClient.DownloadString(mkpair[1].SkipCharSequence("URI=".ToCharArray()) + $":{a[2]}");
                    break;
                }

                case "#EXT-X-TARGETDURATION":
                    duration = int.Parse(a[1]);
                    break;
                }
            }
            Size = parts.Size;
        }