Exemple #1
0
        private void webVideoList1_DownClick(TPlayerList.WebVideoListItem Item)
        {
            Video video = Item.Tag as Video;

            if (video.playInformation != null)
            {
                int selplayType = -1;
                if (video.playInformation.Count > 1)
                {
                    List <string> seldata = new List <string>();
                    foreach (PlayAddress item in video.playInformation)
                    {
                        seldata.Add(item.playType);
                    }
                    UIListSel frm = new UIListSel(seldata);
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        selplayType = frm.SelIndex;
                    }
                }
                else
                {
                    selplayType = 0;
                }
                if (selplayType > -1)
                {
                    string            _colltag      = "webvideo[okzy]_" + selplayType + "_" + video.id;
                    List <PlayerItem> PlayList_Temp = new List <PlayerItem>();
                    if (video.playInformation[selplayType].videoUrl.Find(ab => ab.playURL.EndsWith(".mp4")) != null || video.playInformation[selplayType].videoUrl.Find(ab => ab.playURL.EndsWith(".m3u8")) != null)
                    {
                        foreach (VideoUrl item in video.playInformation[selplayType].videoUrl)
                        {
                            PlayList_Temp.Add(new PlayerItem("web", item.playURL, video.videoName + " - " + item.playName, _colltag));
                        }
                    }
                    else
                    {
                        foreach (VideoUrl item in video.playInformation[selplayType].videoUrl)
                        {
                            PlayList_Temp.Add(new PlayerItem("web_net1", item.playURL, video.videoName + " - " + item.playName, _colltag));
                        }
                    }
                    player.isTvModel = false;
                    int coll = 0;
                    if (SystemSettings.RememberLocation && File.Exists(Program.CachePath + "coll\\" + PlayList_Temp[0].colltag))
                    {
                        int.TryParse(File.ReadAllText(Program.CachePath + "coll\\" + PlayList_Temp[0].colltag), out coll);
                    }
                    player.OpenFileWeb(PlayList_Temp, coll);
                }
            }
            else if (video.isRun)
            {
                Api.OpenMessage(this, MessageType.Info, "请稍后,正在获取地址");
            }
        }
Exemple #2
0
        void DownZimu(string title, Panel panel, ProgressBar progressBar, string url)
        {
            string        basePath = Program.CachePath + "sub\\" + title.Replace(":", "") + "\\";
            List <string> Files    = ScanFile(new DirectoryInfo(basePath));

            if (Files.Count > 0)
            {
                if (Files.Count > 1)
                {
                    UIListSel frm = new UIListSel(Files);
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        player.LoadZimu(frm.SelValue);
                    }
                }
                else
                {
                    player.LoadZimu(Files[0]);
                }
            }
            else
            {
                panel.Enabled       = false;
                progressBar.Visible = true;
                progressBar.Style   = ProgressBarStyle.Marquee;
                bool   isok    = false;
                Action _action = () =>
                {
                    try
                    {
                        List <HttpLib.Val> _header = new List <HttpLib.Val> {
                            new HttpLib.Val("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"),
                            new HttpLib.Val("Accept-Encoding", "gzip, deflate"),
                            new HttpLib.Val("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"),
                            new HttpLib.Val("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 Edg/83.0.478.37"),
                        };

                        string html = HttpLib.Http.Get(url).header(_header).redirect(true).request();
                        if (!string.IsNullOrEmpty(html))
                        {
                            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                            doc.LoadHtml(html);

                            string href     = doc.DocumentNode.SelectSingleNode("//li[@class='li dlsub']/div/a[@id='down1']").GetAttributeValue("href", null);
                            Uri    uri      = new Uri(href);
                            string htmlhref = HttpLib.Http.Get(uri.AbsoluteUri).header(_header).redirect(true).request();
                            if (!string.IsNullOrEmpty(htmlhref))
                            {
                                HtmlAgilityPack.HtmlDocument dochref = new HtmlAgilityPack.HtmlDocument();
                                dochref.LoadHtml(htmlhref);
                                var downs = dochref.DocumentNode.SelectNodes("//div[@class='down clearfix']/ul/li");
                                foreach (var item in downs)
                                {
                                    string downhref = "http://" + uri.Host + item.SelectSingleNode("a").GetAttributeValue("href", null);
                                    try
                                    {
                                        HttpWebRequest Myrq = (HttpWebRequest)HttpWebRequest.Create(downhref);
                                        Myrq.Accept    = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
                                        Myrq.Host      = "zmk.pw";
                                        Myrq.Referer   = url;
                                        Myrq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 Edg/83.0.478.37";
                                        Myrq.Timeout   = 3000;
                                        using (HttpWebResponse response = (HttpWebResponse)Myrq.GetResponse())
                                        {
                                            if (response.ContentType.ToLower().Contains("application/octet-stream"))
                                            {
                                                string fileName    = "字幕库.z";
                                                string Disposition = response.Headers["Content-Disposition"];
                                                if (!string.IsNullOrEmpty(Disposition))
                                                {
                                                    string filename = "";
                                                    filename = Disposition.Substring(Disposition.IndexOf("filename=") + 9);
                                                    if (filename.Contains(";"))
                                                    {
                                                        filename = filename.Substring(0, filename.IndexOf(";"));
                                                        if (filename.EndsWith("\""))
                                                        {
                                                            filename = filename.Substring(1, filename.Length - 2);
                                                        }
                                                    }
                                                    filename = filename.Trim('"');


                                                    byte[] byteArray = Encoding.GetEncoding("ISO-8859-1").GetBytes(filename); // System.Text.Encoding.Default.GetBytes(fileName);
                                                                                                                              // Encoding.GetEncoding("utf-8").GetBytes(fileName);
                                                    string urlFilename = Encoding.GetEncoding("utf-8").GetString(byteArray);
                                                    urlFilename = System.Web.HttpUtility.UrlDecode(urlFilename, Encoding.UTF8);

                                                    fileName = urlFilename;
                                                }
                                                else
                                                {
                                                    fileName = response.ResponseUri.Segments[response.ResponseUri.Segments.Length - 1];
                                                }
                                                if (!File.Exists(Program.CachePath + "sub\\" + fileName))
                                                {
                                                    //application/octet-stream
                                                    //_length = myrp.ContentLength;//总大小
                                                    //tProgressBar1.Invoke(new Action(() =>
                                                    //{
                                                    //    tProgressBar1.Maximum = (int)_length;
                                                    //}));
                                                    progressBar.Invoke(new Action(() =>
                                                    {
                                                        progressBar.Style   = ProgressBarStyle.Blocks;
                                                        progressBar.Maximum = (int)response.ContentLength;
                                                    }));
                                                    using (Stream su = response.GetResponseStream())
                                                    {
                                                        (Program.CachePath + "sub\\").CreateDirectory(true);
                                                        int _downvalue = 0;
                                                        using (FileStream so = new FileStream(Program.CachePath + "sub\\" + fileName, FileMode.Create))
                                                        {
                                                            byte[] by    = new byte[1024];
                                                            int    osize = su.Read(by, 0, (int)by.Length);
                                                            while (osize > 0)
                                                            {
                                                                _downvalue += osize;
                                                                so.Write(by, 0, osize);
                                                                osize = su.Read(by, 0, (int)by.Length);
                                                                progressBar.Invoke(new Action(() =>
                                                                {
                                                                    progressBar.Value = _downvalue;
                                                                }));
                                                            }
                                                        }
                                                    }
                                                }
                                                //Program.CachePath + "sub\\" +
                                                //srt;ass;ssa;smi;psb;idx;sub;sup
                                                string[] filters = new string[0];
                                                string   filter  = player.playerGetConfig(502);
                                                if (!string.IsNullOrEmpty(filter))
                                                {
                                                    filters = filter.Split(';');
                                                }

                                                basePath.CreateDirectory();

                                                if (filters.Contains(Path.GetExtension(fileName).TrimStart('.').ToLower()))
                                                {
                                                    File.Move(Program.CachePath + "sub\\" + fileName, basePath + fileName);
                                                    player.LoadZimu(basePath + fileName);
                                                }
                                                else
                                                {
                                                    string        err;
                                                    List <string> files = Compression.DecompressionList(Program.CachePath + "sub\\" + fileName, basePath, out err);
                                                    if (files != null)
                                                    {
                                                        UIListSel frm = new UIListSel(files);
                                                        if (frm.ShowDialog() == DialogResult.OK)
                                                        {
                                                            string path_ = basePath + frm.SelValue;
                                                            if (File.Exists(path_))
                                                            {
                                                                player.LoadZimu(path_);
                                                            }
                                                        }
                                                        //File.Delete(Program.CachePath + "sub\\" + fileName);
                                                    }
                                                    else
                                                    {
                                                        Api.OpenMessage(this, MessageType.Warn, "解压失败:" + err);
                                                    }
                                                }
                                                return;
                                            }
                                            else
                                            {
                                                Myrq.Abort();
                                            }
                                        }
                                        isok = true;
                                        return;
                                    }
                                    catch (Exception ez)
                                    {
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        Api.OpenMessage(this, MessageType.Warn, "下载字幕失败:1");
                    }
                };
                _task.ContinueWhenAll(new Task[] { _task.StartNew(_action) }, (action =>
                {
                    this.Invoke(new Action(() =>
                    {
                        progressBar.Style = ProgressBarStyle.Blocks;
                        progressBar.Maximum = progressBar.Value = 0;
                        progressBar.Visible = false;
                        panel.Enabled = true;
                    }));
                }));
            }
        }