/* private readonly static String[] colors = { "{\\c&HC0C0C0&}", // black /gray "{\\c&H4040FF&}", // red "{\\c&H00FF00&}", // green "{\\c&H00FFFF&}", // yellow "{\\c&HFF409B&}", // blue //DM15032004 081.6 int18 changed "{\\c&HFF00FF&}", // magenta "{\\c&HFFFF00&}", // cyan "{\\c&HFFFFFF&}", // white }; public static byte ByteReverse(byte n) { n = (byte)(((n >> 1) & 0x55) | ((n << 1) & 0xaa)); n = (byte)(((n >> 2) & 0x33) | ((n << 2) & 0xcc)); n = (byte)(((n >> 4) & 0x0f) | ((n << 4) & 0xf0)); return n; } private static string GetTeletext(byte[] _buffer, int offset) { string text = string.Empty; bool ascii = false; const int color = 0; bool toggle = false; for (int c = offset, i = 0; c < _buffer.Length; c++, i++) { //var char_value = _buffer[c]; var char_value = 0x7F & ByteReverse(_buffer[c]); if (char_value >> 3 == 0) //0x0..7 { ascii = true; text += ((color == 1) ? colors[char_value] : string.Empty); // + (char)active_set[32]; } else if (char_value >> 4 == 0) //0x8..F { text += " "; //(char)active_set[32]; } else if (char_value >> 7 == 1) //0x80..FF { text += " "; //(char)active_set[32]; } else if (char_value < 27) //0x10..1A { ascii = false; text += " "; //(char)active_set[32]; } else if (char_value < 32) //0x1B..1F { if (char_value == 0x1B) //ESC { if (toggle) { // active_set = CharSet.getActive_G0_Set(primary_set_mapping, primary_national_set_mapping, row); // active_national_set = CharSet.getActiveNationalSubset(primary_set_mapping, primary_national_set_mapping, row); } else { //active_set = CharSet.getActive_G0_Set(secondary_set_mapping, secondary_national_set_mapping, row); //active_national_set = CharSet.getActiveNationalSubset(secondary_set_mapping, secondary_national_set_mapping, row); } toggle = !toggle; } text += " "; //(char)active_set[32]; continue; } else if (char_value == 0x7F) //0x7F { text += " "; // (char)active_set[32]; continue; } if (!ascii) { text += " "; // (char)active_set[32]; continue; } //if (active_national_set != null) //{ // // all chars 0x20..7F // switch (char_value) // special national characters // { // case 0x23: // text += (char)active_national_set[0]; // continue loopi; // case 0x24: // text += (char)active_national_set[1]; // continue loopi; // case 0x40: // text += (char)active_national_set[2]; // continue loopi; // case 0x5b: // text += (char)active_national_set[3]; // continue loopi; // case 0x5c: // text += (char)active_national_set[4]; // continue loopi; // case 0x5d: // text += (char)active_national_set[5]; // continue loopi; // case 0x5e: // text += (char)active_national_set[6]; // continue loopi; // case 0x5f: // text += (char)active_national_set[7]; // continue loopi; // case 0x60: // text += (char)active_national_set[8]; // continue loopi; // case 0x7b: // text += (char)active_national_set[9]; // continue loopi; // case 0x7c: // text += (char)active_national_set[10]; // continue loopi; // case 0x7d: // text += (char)active_national_set[11]; // continue loopi; // case 0x7e: // text += (char)active_national_set[12]; // continue loopi; // } //} text += Encoding.Default.GetString(new byte[] { (byte)char_value }); //(char)active_set[char_value]; //continue loopi; } if (color == 1) return colors[7] + text.Trim(); else return text; } */ #endregion Teletext private bool ImportSubtitleFromMp4(string fileName) { var mp4Parser = new MP4Parser(fileName); var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks(); if (mp4SubtitleTracks.Count == 0) { MessageBox.Show(_language.NoSubtitlesFound); return false; } else if (mp4SubtitleTracks.Count == 1) { LoadMp4Subtitle(fileName, mp4SubtitleTracks[0]); return true; } else { using (var subtitleChooser = new MatroskaSubtitleChooser()) { subtitleChooser.Initialize(mp4SubtitleTracks); if (subtitleChooser.ShowDialog(this) == DialogResult.OK) { LoadMp4Subtitle(fileName, mp4SubtitleTracks[subtitleChooser.SelectedIndex]); return true; } } return false; } }
private void DoSubtitleListview1Drop(object sender, EventArgs e) { _dragAndDropTimer.Stop(); if (ContinueNewOrExit()) { string fileName = _dragAndDropFiles[0]; var file = new FileInfo(fileName); // Do not allow directory drop if (FileUtil.IsDirectory(fileName)) { MessageBox.Show(_language.ErrorDirectoryDropNotAllowed, file.Name, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var dirName = Path.GetDirectoryName(fileName); saveFileDialog1.InitialDirectory = dirName; openFileDialog1.InitialDirectory = dirName; var ext = file.Extension.ToLowerInvariant(); if (ext == ".mkv") { using (var matroska = new MatroskaFile(fileName)) { if (matroska.IsValid) { var subtitleList = matroska.GetTracks(true); if (subtitleList.Count == 0) { MessageBox.Show(_language.NoSubtitlesFound); } else if (subtitleList.Count > 1) { using (var subtitleChooser = new MatroskaSubtitleChooser()) { subtitleChooser.Initialize(subtitleList); if (subtitleChooser.ShowDialog(this) == DialogResult.OK) { LoadMatroskaSubtitle(subtitleList[subtitleChooser.SelectedIndex], matroska, false); } } } else { LoadMatroskaSubtitle(subtitleList[0], matroska, false); } } } return; } if (file.Length < 1024 * 1024 * 2) // max 2 mb { OpenSubtitle(fileName, null); } else if (file.Length < 150000000 && ext == ".sub" && IsVobSubFile(fileName, true)) // max 150 mb { OpenSubtitle(fileName, null); } else if (file.Length < 250000000 && ext == ".sup" && FileUtil.IsBluRaySup(fileName)) // max 250 mb { OpenSubtitle(fileName, null); } else if ((ext == ".ts" || ext == ".rec" || ext == ".mpg" || ext == ".mpeg") && FileUtil.IsTransportStream(fileName)) { OpenSubtitle(fileName, null); } else if (ext == ".m2ts" && FileUtil.IsM2TransportStream(fileName)) { OpenSubtitle(fileName, null); } else { MessageBox.Show(string.Format(_language.DropFileXNotAccepted, fileName)); } } }
private void ImportSubtitleFromMatroskaFile(string fileName) { using (var matroska = new MatroskaFile(fileName)) { if (matroska.IsValid) { var subtitleList = matroska.GetTracks(true); if (subtitleList.Count == 0) { MessageBox.Show(_language.NoSubtitlesFound); } else if (ContinueNewOrExit()) { if (subtitleList.Count > 1) { using (var subtitleChooser = new MatroskaSubtitleChooser()) { subtitleChooser.Initialize(subtitleList); if (_loading) { subtitleChooser.Icon = (Icon)this.Icon.Clone(); subtitleChooser.ShowInTaskbar = true; subtitleChooser.ShowIcon = true; } if (subtitleChooser.ShowDialog(this) == DialogResult.OK) { if (LoadMatroskaSubtitle(subtitleList[subtitleChooser.SelectedIndex], matroska, false) && Path.GetExtension(matroska.Path).Equals(".mkv", StringComparison.OrdinalIgnoreCase)) { OpenVideo(matroska.Path); } } } } else { if (LoadMatroskaSubtitle(subtitleList[0], matroska, false) && Path.GetExtension(matroska.Path).Equals(".mkv", StringComparison.OrdinalIgnoreCase)) { OpenVideo(matroska.Path); } } } } else { MessageBox.Show(string.Format(_language.NotAValidMatroskaFileX, fileName)); } } }
private void pointSyncViaOtherSubtitleToolStripMenuItem_Click(object sender, EventArgs e) { using (var pointSync = new SyncPointsSync()) { openFileDialog1.Title = _language.OpenOtherSubtitle; openFileDialog1.FileName = string.Empty; openFileDialog1.Filter = Utilities.GetOpenDialogFilter(); if (openFileDialog1.ShowDialog() == DialogResult.OK && File.Exists(openFileDialog1.FileName)) { var sub = new Subtitle(); var file = new FileInfo(openFileDialog1.FileName); var fileName = file.FullName; var extension = file.Extension.ToLowerInvariant(); // TODO: Check for mkv etc if (extension == ".sub") { if (IsVobSubFile(fileName, false)) { MessageBox.Show(_language.NoSupportHereVobSub); return; } } if (extension == ".sup") { if (FileUtil.IsBluRaySup(fileName)) { MessageBox.Show(_language.NoSupportHereBluRaySup); return; } else if (FileUtil.IsSpDvdSup(fileName)) { MessageBox.Show(_language.NoSupportHereDvdSup); return; } } if (extension == ".mkv" || extension == ".mks") { using (var matroska = new MatroskaFile(fileName)) { if (matroska.IsValid) { var subtitleList = matroska.GetTracks(true); if (subtitleList.Count > 1) { using (var subtitleChooser = new MatroskaSubtitleChooser()) { subtitleChooser.Initialize(subtitleList); if (_loading) { subtitleChooser.Icon = (Icon)this.Icon.Clone(); subtitleChooser.ShowInTaskbar = true; subtitleChooser.ShowIcon = true; } if (subtitleChooser.ShowDialog(this) == DialogResult.OK) { sub = LoadMatroskaSubtitleForSync(subtitleList[subtitleChooser.SelectedIndex], matroska); } } } else if (subtitleList.Count > 0) { sub = LoadMatroskaSubtitleForSync(subtitleList[0], matroska); } else { MessageBox.Show(_language.NoSubtitlesFound); return; } } } } if (extension == ".divx" || extension == ".avi") { MessageBox.Show(_language.NoSupportHereDivx); return; } if ((extension == ".mp4" || extension == ".m4v" || extension == ".3gp") && file.Length > 10000) { var mp4Parser = new MP4Parser(fileName); var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks(); if (mp4SubtitleTracks.Count == 0) { MessageBox.Show(_language.NoSubtitlesFound); return; } else if (mp4SubtitleTracks.Count == 1) { sub = LoadMp4SubtitleForSync(mp4SubtitleTracks[0]); } else { using (var subtitleChooser = new MatroskaSubtitleChooser()) { subtitleChooser.Initialize(mp4SubtitleTracks); if (subtitleChooser.ShowDialog(this) == DialogResult.OK) { sub = LoadMp4SubtitleForSync(mp4SubtitleTracks[0]); } } } } if (file.Length > 1024 * 1024 * 10 && sub.Paragraphs.Count == 0) // max 10 mb { var text = string.Format(_language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + _language.ContinueAnyway, fileName); if (MessageBox.Show(this, text, Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes) return; } sub.Renumber(); if (sub.Paragraphs.Count == 0) { Encoding enc; SubtitleFormat f = sub.LoadSubtitle(fileName, out enc, null); if (f == null) { ShowUnknownSubtitle(); return; } } pointSync.Initialize(_subtitle, _fileName, _videoFileName, _videoAudioTrackNumber, fileName, sub); mediaPlayer.Pause(); if (pointSync.ShowDialog(this) == DialogResult.OK) { _subtitleListViewIndex = -1; MakeHistoryForUndo(_language.BeforePointSynchronization); _subtitle.Paragraphs.Clear(); foreach (var p in pointSync.FixedSubtitle.Paragraphs) _subtitle.Paragraphs.Add(p); _subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate); ShowStatus(_language.PointSynchronizationDone); ShowSource(); SubtitleListview1.Fill(_subtitle, _subtitleAlternate); } _videoFileName = pointSync.VideoFileName; } } }
private void SubtitleListview1_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Length == 1) { if (ContinueNewOrExit()) { string fileName = files[0]; saveFileDialog1.InitialDirectory = System.IO.Path.GetDirectoryName(fileName); openFileDialog1.InitialDirectory = System.IO.Path.GetDirectoryName(fileName); var fi = new FileInfo(fileName); string ext = Path.GetExtension(fileName).ToLower(); if (ext == ".mkv") { bool isValid; var matroska = new Matroska(); var subtitleList = matroska.GetMatroskaSubtitleTracks(fileName, out isValid); if (isValid) { if (subtitleList.Count == 0) { MessageBox.Show(_language.NoSubtitlesFound); } else if (subtitleList.Count > 1) { MatroskaSubtitleChooser subtitleChooser = new MatroskaSubtitleChooser(); subtitleChooser.Initialize(subtitleList); if (subtitleChooser.ShowDialog(this) == DialogResult.OK) { LoadMatroskaSubtitle(subtitleList[subtitleChooser.SelectedIndex], fileName, false); } } else { LoadMatroskaSubtitle(subtitleList[0], fileName, false); } } return; } if (fi.Length < 1024 * 1024 * 2) // max 2 mb { OpenSubtitle(fileName, null); } else if (fi.Length < 150000000 && ext == ".sub" && IsVobSubFile(fileName, true)) // max 150 mb { OpenSubtitle(fileName, null); } else if (fi.Length < 250000000 && ext == ".sup" && IsBluRaySupFile(fileName)) // max 250 mb { OpenSubtitle(fileName, null); } else if ((ext == ".ts" || ext == ".rec" || ext == ".mpg" || ext == ".mpeg") && IsTransportStream(fileName)) { OpenSubtitle(fileName, null); } else if (ext == ".m2ts" && IsM2TransportStream(fileName)) { OpenSubtitle(fileName, null); } else { MessageBox.Show(string.Format(_language.DropFileXNotAccepted, fileName)); } } } else { MessageBox.Show(_language.DropOnlyOneFile); } }
private void ImportSubtitleFromMatroskaFile(string fileName) { bool isValid; var matroska = new Matroska(); var subtitleList = matroska.GetMatroskaSubtitleTracks(fileName, out isValid); if (isValid) { if (subtitleList.Count == 0) { MessageBox.Show(_language.NoSubtitlesFound); } else { if (ContinueNewOrExit()) { if (subtitleList.Count > 1) { MatroskaSubtitleChooser subtitleChooser = new MatroskaSubtitleChooser(); subtitleChooser.Initialize(subtitleList); if (_loading) { subtitleChooser.Icon = (Icon)this.Icon.Clone(); subtitleChooser.ShowInTaskbar = true; subtitleChooser.ShowIcon = true; } if (subtitleChooser.ShowDialog(this) == DialogResult.OK) { LoadMatroskaSubtitle(subtitleList[subtitleChooser.SelectedIndex], fileName, false); if (Path.GetExtension(fileName).ToLower() == ".mkv") OpenVideo(fileName); } } else { LoadMatroskaSubtitle(subtitleList[0], fileName, false); if (Path.GetExtension(fileName).ToLower() == ".mkv") OpenVideo(fileName); } } } } else { MessageBox.Show(string.Format(_language.NotAValidMatroskaFileX, fileName)); } }
private void pointSyncViaOtherSubtitleToolStripMenuItem_Click(object sender, EventArgs e) { SyncPointsSync pointSync = new SyncPointsSync(); openFileDialog1.Title = _language.OpenOtherSubtitle; openFileDialog1.FileName = string.Empty; openFileDialog1.Filter = Utilities.GetOpenDialogFilter(); if (openFileDialog1.ShowDialog() == DialogResult.OK && File.Exists(openFileDialog1.FileName)) { Subtitle sub = new Subtitle(); Encoding enc; string fileName = openFileDialog1.FileName; //TODO: Check for mkv etc if (Path.GetExtension(fileName).ToLower() == ".sub" && IsVobSubFile(fileName, false)) { MessageBox.Show("VobSub files not supported here"); return; } if (Path.GetExtension(fileName).ToLower() == ".sup") { if (IsBluRaySupFile(fileName)) { MessageBox.Show("Bluray sup files not supported here"); return; } else if (IsSpDvdSupFile(fileName)) { MessageBox.Show("Dvd sup files not supported here"); return; } } if (Path.GetExtension(fileName).ToLower() == ".mkv" || Path.GetExtension(fileName).ToLower() == ".mks") { Matroska mkv = new Matroska(); bool isValid = false; bool hasConstantFrameRate = false; double frameRate = 0; int width = 0; int height = 0; double milliseconds = 0; string videoCodec = string.Empty; mkv.GetMatroskaInfo(fileName, ref isValid, ref hasConstantFrameRate, ref frameRate, ref width, ref height, ref milliseconds, ref videoCodec); if (isValid) { var subtitleList = mkv.GetMatroskaSubtitleTracks(fileName, out isValid); if (isValid) { if (subtitleList.Count == 0) { MessageBox.Show(_language.NoSubtitlesFound); return; } else { if (subtitleList.Count > 1) { MatroskaSubtitleChooser subtitleChooser = new MatroskaSubtitleChooser(); subtitleChooser.Initialize(subtitleList); if (_loading) { subtitleChooser.Icon = (Icon)this.Icon.Clone(); subtitleChooser.ShowInTaskbar = true; subtitleChooser.ShowIcon = true; } if (subtitleChooser.ShowDialog(this) == DialogResult.OK) { sub = LoadMatroskaSubtitleForSync(subtitleList[subtitleChooser.SelectedIndex], fileName); } } else { sub = LoadMatroskaSubtitleForSync(subtitleList[0], fileName); } } } } } if (Path.GetExtension(fileName).ToLower() == ".divx" || Path.GetExtension(fileName).ToLower() == ".avi") { MessageBox.Show("Divx files not supported here"); return; } var fi = new FileInfo(fileName); if ((Path.GetExtension(fileName).ToLower() == ".mp4" || Path.GetExtension(fileName).ToLower() == ".m4v" || Path.GetExtension(fileName).ToLower() == ".3gp") && fi.Length > 10000) { var mp4Parser = new Logic.Mp4.Mp4Parser(fileName); var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks(); if (mp4SubtitleTracks.Count == 0) { MessageBox.Show(_language.NoSubtitlesFound); return; } else if (mp4SubtitleTracks.Count == 1) { sub = LoadMp4SubtitleForSync(fileName, mp4SubtitleTracks[0]); } else { var subtitleChooser = new MatroskaSubtitleChooser(); subtitleChooser.Initialize(mp4SubtitleTracks); if (subtitleChooser.ShowDialog(this) == DialogResult.OK) { sub = LoadMp4SubtitleForSync(fileName, mp4SubtitleTracks[0]); } } } if (fi.Length > 1024 * 1024 * 10 && sub.Paragraphs.Count == 0) // max 10 mb { if (MessageBox.Show(this, string.Format(_language.FileXIsLargerThan10Mb + Environment.NewLine + Environment.NewLine + _language.ContinueAnyway, fileName), Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes) return; } sub.Renumber(1); if (sub.Paragraphs.Count == 0) { SubtitleFormat f = sub.LoadSubtitle(fileName, out enc, null); if (f == null) { ShowUnknownSubtitle(); return; } } pointSync.Initialize(_subtitle, _fileName, _videoFileName, _videoAudioTrackNumber, fileName, sub); mediaPlayer.Pause(); if (pointSync.ShowDialog(this) == DialogResult.OK) { _subtitleListViewIndex = -1; MakeHistoryForUndo(_language.BeforePointSynchronization); _subtitle.Paragraphs.Clear(); foreach (Paragraph p in pointSync.FixedSubtitle.Paragraphs) _subtitle.Paragraphs.Add(p); _subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate); ShowStatus(_language.PointSynchronizationDone); ShowSource(); SubtitleListview1.Fill(_subtitle, _subtitleAlternate); } _videoFileName = pointSync.VideoFileName; } }