private void AddExternalSubtitles(string directoryName, string fileName) { foreach (string subtitleFile in GetExternalSubtitlesBasedOnFileName(directoryName, fileName)) { var languageCode = GetLanguageCodeFromExternalSubtitleFile(subtitleFile); var languageNames = LanguageUtilities.GetLanguageNames(new List <string>() { languageCode }); if (!languageNames.Any()) { languageNames = LanguageUtilities.GetLanguageNames(new List <string>() { "eng" }); } SubtitleTrack track = new SubtitleTrack { SrtFileName = Path.GetFileNameWithoutExtension(subtitleFile), SrtOffset = 0, SrtCharCode = "UTF-8", SrtLang = languageNames.FirstOrDefault(), SubtitleType = SubtitleType.IMPORTSRT, SrtPath = subtitleFile, }; this.Task.SubtitleTracks.Add(track); } }
/// <summary> /// Import an SRT File. /// </summary> public void Import() { OpenFileDialog dialog = new OpenFileDialog { Filter = "SRT files (*.srt)|*.srt", CheckFileExists = true, Multiselect = true }; dialog.ShowDialog(); foreach (var srtFile in dialog.FileNames) { SubtitleTrack track = new SubtitleTrack { SrtFileName = Path.GetFileNameWithoutExtension(srtFile), SrtOffset = 0, SrtCharCode = "UTF-8", SrtLang = "English", SubtitleType = SubtitleType.SRT, SrtPath = srtFile }; this.Task.SubtitleTracks.Add(track); } }
/// <summary> /// Add a subtitle track. /// The Source track is set based on the following order. If null, it will skip to the next option. /// 1. Passed in Subitle param /// 2. First preferred Subtitle from source /// 3. First subtitle from source. /// Will not add a subtitle if the source has none. /// </summary> /// <param name="subtitle"> /// The subtitle. Use null to add preferred, or first from source (based on user preference) /// </param> private void Add(Subtitle subtitle) { Subtitle source = subtitle ?? ((this.SourceTracks != null) ? (this.SourceTracks.FirstOrDefault(l => l.Language == this.GetPreferredSubtitleTrackLanguage()) ?? this.SourceTracks.FirstOrDefault( s => s.SubtitleType != SubtitleType.ForeignAudioSearch)) : null); if (source == null) { source = foreignAudioSearchTrack; } SubtitleTrack track = new SubtitleTrack { SubtitleType = source.SubtitleType, SourceTrack = source, }; // Burn-in Behaviours if (this.SubtitleBehaviours.SelectedBurnInBehaviour == SubtitleBurnInBehaviourModes.ForeignAudio || this.SubtitleBehaviours.SelectedBurnInBehaviour == SubtitleBurnInBehaviourModes.ForeignAudioPreferred) { if (subtitle != null && subtitle.SubtitleType == SubtitleType.ForeignAudioSearch) { track.Burned = true; this.SetBurnedToFalseForAllExcept(track); } } // For MP4, PGS Subtitles must be burned in. if (!track.Burned && (source.SubtitleType == SubtitleType.PGS) && this.Task != null && this.Task.OutputFormat == OutputFormat.Mp4) { if (this.Task.SubtitleTracks.Any(a => a.Burned)) { return; // We can't add any more burned in tracks. } if (track.CanBeBurned) { track.Burned = true; this.SetBurnedToFalseForAllExcept(track); } } var encodeTask = this.Task; if (encodeTask != null) { encodeTask.SubtitleTracks.Add(track); } }
/// <summary> /// Select the burned in track. /// </summary> /// <param name="subtitle"> /// The subtitle. /// </param> public void SetBurnedToFalseForAllExcept(SubtitleTrack subtitle) { foreach (SubtitleTrack track in this.Task.SubtitleTracks) { if (track == subtitle) { continue; // Skip the track the user selected. } track.Burned = false; } this.NotifyOfPropertyChange(() => this.Task); }
/// <summary> /// Select the default subtitle track. /// </summary> /// <param name="subtitle"> /// The subtitle. /// </param> public void SelectDefaultTrack(SubtitleTrack subtitle) { foreach (SubtitleTrack track in this.Task.SubtitleTracks) { if (track == subtitle) { continue; // Skip the track the user selected. } track.Default = false; } this.NotifyOfPropertyChange(() => this.Task); }
private void AddInputSubtitles(string[] filenames) { foreach (var srtFile in filenames) { if (!File.Exists(srtFile)) { continue; } SubtitleTrack track = new SubtitleTrack { SrtFileName = Path.GetFileNameWithoutExtension(srtFile), SrtOffset = 0, SrtCharCode = "UTF-8", SrtLang = "English", SubtitleType = SubtitleType.SRT, SrtPath = srtFile }; this.Task.SubtitleTracks.Add(track); } }
/// <summary> /// Remove a Track /// </summary> /// <param name="track"> /// The track. /// </param> public void Remove(SubtitleTrack track) { this.Task.SubtitleTracks.Remove(track); }
/// <summary> /// Add a subtitle track. /// The Source track is set based on the following order. If null, it will skip to the next option. /// 1. Passed in Subitle param /// 2. First preferred Subtitle from source /// 3. First subtitle from source. /// Will not add a subtitle if the source has none. /// </summary> /// <param name="subtitle"> /// The subtitle. Use null to add preferred, or first from source (based on user preference) /// </param> private void Add(Subtitle subtitle) { Subtitle source = subtitle ?? ((this.SourceTracks != null) ? (this.SourceTracks.FirstOrDefault(l => l.Language == this.GetPreferredSubtitleTrackLanguage()) ?? this.SourceTracks.FirstOrDefault( s => s.SubtitleType != SubtitleType.ForeignAudioSearch)) : null); if (source == null) { source = ForeignAudioSearchTrack; } SubtitleTrack track = new SubtitleTrack { SubtitleType = SubtitleType.VobSub, SourceTrack = source, }; // Burn-in Behaviours if (this.SubtitleBehaviours.SelectedBurnInBehaviour == SubtitleBurnInBehaviourModes.ForeignAudio || this.SubtitleBehaviours.SelectedBurnInBehaviour == SubtitleBurnInBehaviourModes.ForeignAudioPreferred) { track.Burned = true; this.SetBurnedToFalseForAllExcept(track); } // For MP4, PGS Subtitles must be burned in. if (!track.Burned && (source.SubtitleType == SubtitleType.PGS) && this.Task != null && this.Task.OutputFormat == OutputFormat.Mp4) { if (track.CanBeBurned) { track.Burned = true; this.SetBurnedToFalseForAllExcept(track); } } var encodeTask = this.Task; if (encodeTask != null) { encodeTask.SubtitleTracks.Add(track); } }