Exemplo n.º 1
0
        public void RunDownload(string url)
        {
            // url = @"http://www.ted.com/talks/drew_curtis_how_i_beat_a_patent_troll.html";
            tedProgressForm = new f.TED.FormDowloadedInfo();
            tedProgressForm.Show();
            try
            {
                m_TEDProvider = new TEDProvider();
                m_TEDProvider.GetContent(url, "", "");
                // get info
                if (string.IsNullOrEmpty(m_TEDProvider.SubtitleId))
                {
                }
                else
                {
                    tedProgressForm.EnSubtProgress = 50;
                }

                string folder = GetFolder(m_TEDProvider.VideoTitle, rootFolderName);

                DoDownloadFile(m_TEDProvider.ImgSrc, folder);

                m_FileSubtEn = m_TEDProvider.GetSubtitles("en", folder);
                if (!string.IsNullOrEmpty(m_FileSubtEn))
                {
                    tedProgressForm.EnSubtProgress = 100;
                }
                else
                {
                    tedProgressForm.IsEnSubtWorng = true;
                }

                // native
                if (rbTranslation.Checked && cmbNativeLanguage.SelectedItem is LangName)
                {
                    string nativeCode = ((LangName)cmbNativeLanguage.SelectedItem).Code;
                    if (!nativeCode.Equals("en"))
                    {
                        m_fileSubtNative = m_TEDProvider.GetSubtitles(nativeCode, folder);
                        if (!string.IsNullOrEmpty(m_fileSubtNative))
                        {
                            tedProgressForm.NativeSubtProgress = 100;
                        }
                        else
                        {
                            tedProgressForm.IsNativeSubtWorng = true;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(m_TEDProvider.VideoURL))
                {
                    WebDownloader.DownloadProgressDelegate dowloadProgress = new WebDownloader.DownloadProgressDelegate(ShowProgress);
                    m_fileVideo = WebDownloader.Download(m_TEDProvider.VideoURLFull, folder + "\\", dowloadProgress, "en.mp4");
                    CallCompleteEvent();
                }
                else
                {
                    // перейти на страницу чтобы самостоятельно скачать видео
                    MessageBox.Show(this, "Video not found. Try download it self.", Application.ProductName,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Runner.OpenURL(url);
                }
            }
            catch
            {
                MessageBox.Show(this, "Please, try to select another episode.", Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                tedProgressForm.IsVideoWorng = true;
            }
            tedProgressForm.Close();
        }
Exemplo n.º 2
0
        void DownloadNews(News news, string folder, string nativeSuffix, News sourceNews)
        {
            bool isTargetLanguage = nativeSuffix.Equals("en.");

            try
            {
                if (!string.IsNullOrEmpty(news.VideoSrc))
                {
                    WebDownloader.DownloadProgressDelegate dowloadProgress = new WebDownloader.DownloadProgressDelegate(progressDownloadForm.AssignProgress);
                    m_fileVideo = WebDownloader.Download(news.VideoSrc, folder, dowloadProgress, nativeSuffix + "mp4");
                    if (!string.IsNullOrEmpty(m_fileVideo))
                    {
                        //  news.AllLength = mp4info.FindLength_mciSend(m_fileVideo);
                        //AxWMPLib.AxWindowsMediaPlayer Player = new AxWMPLib.AxWindowsMediaPlayer();
                        VideoControl vc = new VideoControl();
                        vc.Player.URL = m_fileVideo;
                        // не помогает vc.Player.Ctlcontrols.pause(); // т.к. сразу играет
                        while ((int)vc.Player.playState == 9) // connecting
                        {
                            Application.DoEvents();
                        }
                        news.AllLength = (long)(vc.Player.currentMedia.duration * 1000);
                        vc.Player.URL  = "";
                        vc.Dispose();
                    }
                }
                else if (isTargetLanguage)
                {
                    // перейти на страницу чтобы самостоятельно скачать видео
                    MessageBox.Show(this, "Video not found. Try download it self.", Application.ProductName,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    // открывать только если в диалоге выбрали Yes ???
                    //   Runner.OpenURL(url);
                }

                string fileExt     = "txt";
                string fileContent = news.HTMLContent;
                if (news.AllLength != -1) // т.е. известна длина видео
                {
                    fileExt     = "srt";
                    fileContent = SentenceParser.CreateSubtitles(news);
                }
                else // чтобы кол-во предложений былы синхронным добавим еще одно предложение
                {
                    fileContent = string.Format(VideoUnit.FirstSentence, news.URL) + "." + Environment.NewLine + fileContent;
                }

                if (!string.IsNullOrEmpty(news.HTMLContent))
                {
                    string fileName = folder + nativeSuffix + fileExt;
                    fileName = FileManager.CreateFile(fileName, fileContent);
                    if (isTargetLanguage)
                    {
                        this.m_FileSubtEn = fileName;
                        progressDownloadForm.EnSubtProgress = 100;
                    }
                    else
                    {
                        this.m_fileSubtNative = fileName;
                        progressDownloadForm.NativeSubtProgress = 100;
                    }
                }
            }
            catch
            {
                MessageBox.Show(this, "Please, try to select another news.", Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                progressDownloadForm.IsVideoWorng = true;
            }
        }