Exemplo n.º 1
0
Arquivo: Form1.cs Projeto: famisy/DDTV
        public void GetYoutube(string roomId)
        {
            int 标号 = int.Parse(RInfo[CurrentlyStream].Name);
            //VLC[CurrentlyStream].Play(@".\img\630529.ts", PBOX[CurrentlyStream].Handle);
            string ASDASD = MMPU.get返回网页内容("https://www.youtube.com/channel/" + roomId + "/live");

            try
            {
                ASDASD = ASDASD.Replace("\\\"},\\\"playbackTracking\\\"", "㈨").Split('㈨')[0].Replace("\\\"hlsManifestUrl\\\":\\\"", "㈨").Split('㈨')[1].Replace("\",\\\"probeUrl\\\"", "㈨").Split('㈨')[0].Replace("\\", "");
            }
            catch (Exception)
            {
                ClForm(标号);
                MessageBox.Show("该直播已停止");
                return;
            }
            ASDASD = MMPU.get返回网页内容(ASDASD);

            /*
             * 3  256x144
             * 5  426x240
             * 7  640x360
             * 9  854x480
             * 11 1280x720
             * 13 1920x1080
             */

            string[] ASD  = ASDASD.Split('\n');
            bool     播放开始 = false;

            Thread T1 = new Thread(new ThreadStart(delegate
            {
                List <string> LS1 = new List <string>();
                int S             = 0;
                while (true)
                {
                    if (!RInfo[标号].status)
                    {
                        return;
                    }
                    if (FM[标号].Visible == false)
                    {
                        return;
                    }
                    ASDASD = MMPU.get返回网页内容(ASD[CurrentResolution()]);

                    /*
                     * 6   1
                     * 8   2
                     * 10  3
                     */
                    string[] LS3        = ASDASD.Split('\n');
                    List <string[]> LS2 = new List <string[]>();

                    for (int i = 0; i < LS3.Length; i++)
                    {
                        if (LS3[i].Length != LS3[i].Replace("http", "").Length)
                        {
                            string[] A = new string[2];

                            Regex reg    = new Regex("index.m3u8/sq/(.+)/goap");
                            Match match  = reg.Match(LS3[i]);
                            string value = match.Groups[1].Value;
                            A[0]         = LS3[i];
                            A[1]         = value;
                            LS2.Add(A);
                        }
                    }


                    MMPU.IsExistDirectory("./tmp/" + roomId + "/");
                    for (int i = 0; i < LS2.Count; i++)
                    {
                        if (LS1.Count == 0)
                        {
                            LS1.Add(LS2[i][1]);
                            MMPU.HttpDownloadFile(LS2[i][0], "./tmp/" + roomId + "/" + LS2[i][1] + ".ts");
                            S++;
                            //break;
                        }
                        else if (!LS1.Contains(LS2[i][1]))
                        {
                            LS1.Add(LS2[i][1]);
                            MMPU.HttpDownloadFile(LS2[i][0], "./tmp/" + roomId + "/" + LS2[i][1] + ".ts");
                            S++;
                        }
                    }
                    RInfo[标号].status = true;
                    if (S > 5 && !播放开始)
                    {
                        播放开始      = true;
                        Thread T2 = new Thread(new ThreadStart(delegate
                        {
                            int S1 = int.Parse(LS1[0]);

                            FileStream fs   = new FileStream("./tmp/" + roomId + "/" + S1 + ".ts", FileMode.Append); //以Append方式打开文件
                            BinaryWriter bw = new BinaryWriter(fs);                                                  //二进制写入流
                            RInfo[标号].steam = "./tmp/" + roomId + "/" + S1 + ".ts";
                            //VLC[CurrentlyStream].Play("./tmp/" + roomId + "/" + S1 + ".ts", PBOX[CurrentlyStream].Handle);
                            S1++;
                            int k = 0;
                            while (true)
                            {
                                if (!RInfo[标号].status)
                                {
                                    fs.Close();
                                    bw.Close();
                                    return;
                                }
                                if (FM[标号].Visible == false)
                                {
                                    fs.Close();
                                    bw.Close();
                                    return;
                                }
                                try
                                {
                                    if (MMPU.IsExistFile("./tmp/" + roomId + "/" + (S1 + 1) + ".ts"))
                                    {
                                        FileStream fs1   = new FileStream("./tmp/" + roomId + "/" + S1 + ".ts", FileMode.Open);//以Append方式打开文件
                                        BinaryReader br1 = new BinaryReader(fs1);
                                        int line         = 0;
                                        byte[] Q2        = br1.ReadBytes((int)br1.BaseStream.Length);
                                        bw.Write(Q2, 0, Q2.Length); //写文件

                                        fs1.Close();
                                        br1.Close();
                                        MMPU.DelFile("./tmp/" + roomId + "/" + S1 + ".ts");
                                        S1++;
                                    }
                                    else
                                    {
                                        if (MMPU.IsExistFile("./tmp/" + roomId + "/" + (S1 + 2) + ".ts"))
                                        {
                                            S1++;
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                    // Console.WriteLine(S1);
                                    Thread.Sleep(10);
                                }
                                if (k == 0)
                                {
                                    for (int i = 0; i < 5; i++)
                                    {
                                        if (FM[CurrentlyStream].Visible == true)
                                        {
                                            VLC[CurrentlyStream].PlayFile("./tmp/" + roomId + "/" + S1 + ".ts", PBOX[CurrentlyStream].Handle);
                                            Thread.Sleep(1000);
                                        }
                                    }
                                    k++;
                                }
                            }
                        }));
                        T2.IsBackground = true;
                        T2.Start();
                    }
                }
            }));

            T1.IsBackground = true;
            T1.Start();
        }
Exemplo n.º 2
0
Arquivo: Form1.cs Projeto: famisy/DDTV
 private void DloFile(string RoomId, string path)
 {
     MMPU.HttpDownloadFile(getUriSteam.GetTrueUrl(RoomId), path);
 }