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); }
protected virtual void LoadFile() { this.ReadOnly = true; string ext = Path.GetExtension(this.FileName).ToLower(); if (ext == ".txt" && this is SentenceListWithIndent) { LoadFileAsText(); } else if (Array.IndexOf(GlobalOptions.SubtitlesFileExtensions, ext) != -1) { try { List <Sentence> result = SentenceParser.GetSentencesFromSubtitles(this.FileName); if (result.Count == 1 && string.IsNullOrEmpty(result[0].TextValue) && string.Equals(".txt", ext)) // is empty { this.FullText = SentenceParser.GetFileByRichTextBox(this.FileName); this.ReadOnly = false; } else { this.Sentences = result; this.m_FullText = this.GetAllSentences(); } } catch // если не смогли пропарсить как субтитры попробуем открыть просто как текст { // TODO: дублируется код 3 раза if (string.Equals(".txt", ext)) { LoadFileAsText(); } } } else { this.FullText = SentenceParser.GetFileByRichTextBox(this.FileName); this.ReadOnly = false; } }
public void DoCorrectionForLengths(string lengths, bool doForceReplay) { string[] newLengths = lengths.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries); // TODO: not fine if (newLengths.Length != Host.ListEn.Sentences.Count) { return; } int i = 0; double startTime = 0; foreach (string l in newLengths) { double dl = double.Parse(l); ((SentenceVideo)Host.ListEn.Sentences[i++]).SetLength(startTime, dl); startTime += dl; } if (doForceReplay || // ïðîèãðàåì ñíà÷àëà âñåãäà, íî åñëè äâèãàëè êîíåö ïðåäëîæåíèÿ (doForceReplay == false) è ïëååð åùå èãðàë ñòàðò òåêóùåãî ïðèëîæåíèÿ íå äåëàåì !VideoForm.CurrentVideoContrl.IsPlaying) { Host.Invoke((Action)(() => { try { ((SentenceListWithVideo)Host.ListEn).PlayCurrentSentence(); } finally { } })); } try { // rewrite allFiles SentenceParser.RewriteSubtitles(Host.ListEn.FileName, Host.ListEn.Sentences); } catch { //DebugMonitor. } }
private void LoadFileAsText() { this.FullText = SentenceParser.GetFileByRichTextBox(this.FileName); this.ReadOnly = false; }
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; } }