Exemplo n.º 1
0
        /*wRequest = (HttpWebRequest)WebRequest.Create(url);
         *  wRequest.Headers = whc;
         *  wRequest.Host = "cdn.twist.moe";
         *  wRequest.Referer = $"https://twist.moe/{info.slug}";
         *  wRequest.AddRange(0, 999999999999);
         *  WebResponse a = wRequest.GetResponse();*/
        private void ParseMp4(M3UMP4_SETTINGS settings)
        {
            downloadRange = new int[2];
            //string parsedTitle = info.title.RemoveSpecialCharacters();
            wRequest = settings.GenerateWebRequest(m3u8Info[0]);
            wRequest.AddRange(0, 999999999999);
            WebResponse a = wRequest.GetResponse();

            downloadRange[1] = int.Parse(a.Headers["Content-Length"]);
            downloadRange[0] = 0;
            Size             = downloadRange[1];
            mp4ByteStream    = new MemoryStream();

            if (settings.location != -1)
            {
                downloadRange[0] = settings.location;
                location         = settings.location;
            }
            // Start thread to download file.
            new Thread(() =>
            {
                Thread.CurrentThread.Name = "downloader";
                System.IO.Stream ab;
                while (downloadRange[0] < downloadRange[1])
                {
                    wRequest = settings.GenerateWebRequest(m3u8Info[0]);
                    wRequest.AddRange(downloadRange[0], downloadRange[0] + downloadAmnt);
                    a  = wRequest.GetResponse();
                    ab = a.GetResponseStream();
                    using (MemoryStream ms = new MemoryStream())
                    {
                        ab.CopyTo(ms);
                        Byte[] arr        = ms.ToArray();
                        downloadRange[0] += arr.Length;
                        location         += arr.Length;
                        ms.Seek(0, SeekOrigin.Begin);
                        reset.WaitOne();
                        ms.CopyTo(mp4ByteStream);
                        onNewBytes?.Invoke(arr);
                    }
                }

                location = -99;
            }).Start();
        }
Exemplo n.º 2
0
        public M3U(string dataToParse, WebHeaderCollection wc = null, string bpath = null, bool mp4 = false, M3UMP4_SETTINGS settings = null)
        {
            collection = wc;
            webClient  = new WebClient();
            m3u8Info   = dataToParse.Split('\n');
            headers    = new List <string>();
            bPath      = bpath;

            if (mp4)
            {
                this.mp4 = true;
                ParseMp4(settings);
            }
            else
            {
                ParseM3U();
            }
        }