예제 #1
0
        void ParseAndCreateFile(string[] lines)
        {
            string        retText   = "Subtitles was not loaded";
            StringBuilder subOutput = new StringBuilder();
            string        prevTime  = SentenceParser.GetTimeFromSeconds(shiftStart);

            subOutput.AppendLine("0");
            subOutput.AppendLine(string.Format("{0} --> {1}", "00:00:00,000", prevTime));
            subOutput.AppendLine(m_firstSentence);
            subOutput.AppendLine();

            int  counter = 1;
            long time    = 0;

            foreach (string line in lines)
            {
                string[] res = line.Split(new string[] { dlm }, StringSplitOptions.RemoveEmptyEntries);

                if (long.TryParse(res[0], out time))
                {
                    subOutput.AppendLine((counter++).ToString());
                    string start = prevTime;
                    string end   = prevTime = SentenceParser.GetTimeFromSeconds(time + shiftStart);
                    subOutput.AppendLine(string.Format("{0} --> {1}", start, end));
                    subOutput.AppendLine(res[1]);
                    subOutput.AppendLine();
                }
            }
            // all ok
            retText = subOutput.ToString();

            retText = retText.Replace("\\", "");
            FileManager.CreateFile(m_fileName, retText); // надо в UTF-8 для китайцев и прочего
            //  FileManager.CreateFile(fileName, retText, Encoding.Default);
        }
예제 #2
0
        public static void RewriteSubtitles(string fileName, List <Sentence> list)
        {
            int           counter = 0;
            StringBuilder sb      = new StringBuilder();

            foreach (SentenceVideo sn in list)
            {
                sb.AppendLine((counter++).ToString());
                long st = (long)(sn.Start * 1000);
                sb.AppendLine(GetTimeFromSeconds(st) + " --> " + GetTimeFromSeconds(st + (long)(sn.Length * 1000)));
                sb.AppendLine(sn.TextValue);
                sb.AppendLine();
            }
            FileManager.CreateFile(fileName, sb.ToString()); // надо в UTF-8 для китайцев и прочего
        }
예제 #3
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;
            }
        }
예제 #4
0
파일: Gator.cs 프로젝트: easably/easy2learn
        public String GetContents(string word, string codeForm, string codeTo)
        {
            List <IDictionaryProvider> dictionaries = new List <IDictionaryProvider>();

            foreach (Type type in GlobalOptions.WorkedDictionaries)
            {
                IDictionaryProvider provider = (IDictionaryProvider)Activator.CreateInstance(type);
                //TODO: здесь бы вставить и проверку поддержки языка
                if (!provider.OnlyAsUrlProvider)
                {
                    dictionaries.Add(provider);
                }
            }

            if (string.IsNullOrEmpty(word))
            {
                return("");
            }
            string fileName = GetFileName(word, codeForm, codeTo);

            // if (File.Exists(fileName)) return fileName;
//            if (!WWW.IsOnline()) return "";

            threads.Clear();
            string body = "";

            foreach (DictionaryProvider provider in dictionaries)
            {
                ProviderInfoForThread ex = new ProviderInfoForThread(word, codeForm, codeTo, provider);
                Thread th = new Thread(ex.Execute)
                {
                };
                th.Name = string.Format("{0} provider for word '{1}'", provider.Title, word);
                threads.Add(th);
                th.Start();
            }
            WaitUntilFinished();
            foreach (DictionaryProvider provider in dictionaries)
            {
                string content = provider.GetContent(word, codeForm, codeTo);
                if (string.IsNullOrEmpty(content))
                {
                    continue;
                }
                DictionaryProvider.ResultFromResponse res = provider.LastResultFromResponse;
                if (res != null)
                {
                    body += string.Format(ArticleReferenceTemplate,
                                          res.LastURL, provider.Title, res.Content, res.AcceptedLanguageCode);
                }
            }
            if (string.IsNullOrEmpty(body))
            {
                if (File.Exists(fileName))
                {
                    return(fileName);
                }
                return("");
            }
            string s = HtmlFileTemplate.Replace("{0}", word);

            s = s.Replace("{1}", body);
            FileManager.CreateFile(fileName, s);
            return(fileName);
        }