/// <summary>
        /// Initializes a new instance of the <see cref="HandBrakeWPF.ViewModels.SubtitlesViewModel"/> class.
        /// </summary>
        public SubtitlesViewModel()
        {
            this.Task = new EncodeTask();

            this.Langauges = LanguageUtilities.MapLanguages().Keys;
            this.CharacterCodes = CharCodesUtilities.GetCharacterCodes();

            this.ForeignAudioSearchTrack = new Subtitle { SubtitleType = SubtitleType.ForeignAudioSearch, Language = "Foreign Audio Search (Bitmap)" };
            this.SourceTracks = new List<Subtitle> { this.ForeignAudioSearchTrack };
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubtitleTrack"/> class.
 /// Copy Constructor
 /// </summary>
 /// <param name="subtitle">
 /// The subtitle.
 /// </param>
 public SubtitleTrack(SubtitleTrack subtitle)
 {
     this.Burned = subtitle.Burned;
     this.Default = subtitle.Default;
     this.Forced = subtitle.Forced;
     this.sourceTrack = subtitle.SourceTrack;
     this.SrtCharCode = subtitle.SrtCharCode;
     this.SrtFileName = subtitle.SrtFileName;
     this.SrtLang = subtitle.SrtLang;
     this.SrtOffset = subtitle.SrtOffset;
     this.SrtPath = subtitle.SrtPath;
     this.SubtitleType = subtitle.SubtitleType;
     this.SourceTrack = subtitle.SourceTrack;
 }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HandBrakeWPF.ViewModels.SubtitlesViewModel"/> class.
        /// </summary>
        public SubtitlesViewModel()
        {
            this.Task = new EncodeTask();

            this.Langauges = LanguageUtilities.MapLanguages().Keys;
            this.CharacterCodes = CharCodesUtilities.GetCharacterCodes();

            this.ForeignAudioSearchTrack = new Subtitle { SubtitleType = SubtitleType.ForeignAudioSearch, Language = "Foreign Audio Search (Bitmap)" };
            this.SourceTracks = new List<Subtitle> { this.ForeignAudioSearchTrack };

            this.SubtitleBehaviours = new SubtitleBehaviours();
            this.SelectedAvailableToMove = new BindingList<string>();
            this.SelectedLangaugesToMove = new BindingList<string>();
            this.availableLanguages = new BindingList<string>();
            this.SetupLanguages(null);
        }
        /// <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)
        {
            string preferred =
                this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles);

            Subtitle source = subtitle ??
                              ((this.SourceTracks != null)
                                   ? (this.SourceTracks.FirstOrDefault(l => l.Language == preferred) ??
                                      this.SourceTracks.FirstOrDefault(s => s.SubtitleType != SubtitleType.ForeignAudioSearch))
                                   : null);

            if (source == null)
            {
                source = ForeignAudioSearchTrack;
            }

            SubtitleTrack track = new SubtitleTrack
                    {
                        SubtitleType = SubtitleType.VobSub,
                        SourceTrack = source,
                    };

            if ((source.SubtitleType == SubtitleType.PGS || source.SubtitleType == SubtitleType.VobSub) &&
                this.Task != null &&
                (this.Task.OutputFormat == OutputFormat.Mp4 || this.Task.OutputFormat == OutputFormat.M4V))
            {
                this.SelectBurnedInTrack(track);
            }

            this.Task.SubtitleTracks.Add(track);
        }
示例#5
0
        /// <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)
        {
            string preferred =
                this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles);

            Subtitle source = subtitle ??
                              ((this.SourceTracks != null)
                                   ? (this.SourceTracks.FirstOrDefault(l => l.Language == preferred) ??
                                      this.SourceTracks.FirstOrDefault(s => s.SubtitleType != SubtitleType.ForeignAudioSearch))
                                   : null);

            if (source == null)
            {
                source = ForeignAudioSearchTrack;
            }

            SubtitleTrack track = new SubtitleTrack
                    {
                        SubtitleType = SubtitleType.VobSub,
                        SourceTrack = source,
                    };

            this.Task.SubtitleTracks.Add(track);
        }
示例#6
0
 /// <summary>
 /// The equals.
 /// </summary>
 /// <param name="other">
 /// The other.
 /// </param>
 /// <returns>
 /// The System.Boolean.
 /// </returns>
 public bool Equals(Subtitle other)
 {
     if (ReferenceEquals(null, other))
     {
         return false;
     }
     if (ReferenceEquals(this, other))
     {
         return true;
     }
     return other.TrackNumber == this.TrackNumber && object.Equals(other.Language, this.Language) && object.Equals(other.LanguageCode, this.LanguageCode) && object.Equals(other.SubtitleType, this.SubtitleType);
 }
示例#7
0
        /// <summary>
        /// Parse the input strings related to subtitles
        /// </summary>
        /// <param name="output">
        /// The output.
        /// </param>
        /// <returns>
        /// A Subitle object
        /// </returns>
        public static Subtitle Parse(StringReader output)
        {
            string curLine = output.ReadLine();

            // + 1, English (iso639-2: eng) (Text)(SSA)
            // + 1, English (iso639-2: eng) (Text)(UTF-8)
            Match m = Regex.Match(curLine, @"^    \+ ([0-9]*), ([A-Za-z, ]*) \((.*)\) \(([a-zA-Z]*)\)\(([a-zA-Z0-9\-]*)\)");

            if (m.Success && !curLine.Contains("HandBrake has exited."))
            {
                var thisSubtitle = new Subtitle
                                       {
                                           TrackNumber = int.Parse(m.Groups[1].Value.Trim()),
                                           Language = m.Groups[2].Value,
                                           LanguageCode = m.Groups[3].Value,
                                       };

                switch (m.Groups[5].Value)
                {
                    case "VOBSUB":
                        thisSubtitle.SubtitleType = SubtitleType.VobSub;
                        break;
                    case "SRT":
                        thisSubtitle.SubtitleType = SubtitleType.SRT;
                        break;
                    case "CC":
                        thisSubtitle.SubtitleType = SubtitleType.CC;
                        break;
                    case "UTF-8":
                        thisSubtitle.SubtitleType = SubtitleType.UTF8Sub;
                        break;
                    case "TX3G":
                        thisSubtitle.SubtitleType = SubtitleType.TX3G;
                        break;
                    case "SSA":
                        thisSubtitle.SubtitleType = SubtitleType.SSA;
                        break;
                    case "PGS":
                        thisSubtitle.SubtitleType = SubtitleType.PGS;
                        break;
                    default:
                        thisSubtitle.SubtitleType = SubtitleType.Unknown;
                        break;
                }

                return thisSubtitle;
            }
            return null;
        }
示例#8
0
        /// <summary>
        /// Parse the Title Information
        /// </summary>
        /// <param name="output">A StringReader of output data</param>
        /// <returns>A Title Object</returns>
        public static Title Parse(StringReader output)
        {
            var    thisTitle = new Title();
            string nextLine  = output.ReadLine();

            // Get the Title Number
            Match m = Regex.Match(nextLine, @"^\+ title ([0-9]*):");

            if (m.Success)
            {
                thisTitle.TitleNumber = int.Parse(m.Groups[1].Value.Trim());
            }
            nextLine = output.ReadLine();

            // Detect if this is the main feature
            m = Regex.Match(nextLine, @"  \+ Main Feature");
            if (m.Success)
            {
                thisTitle.MainTitle = true;
                nextLine            = output.ReadLine();
            }

            // Get the stream name for file import
            m = Regex.Match(nextLine, @"^  \+ stream:");
            if (m.Success)
            {
                thisTitle.SourceName = nextLine.Replace("+ stream:", string.Empty).Trim();
                nextLine             = output.ReadLine();
            }

            // Playlist
            m = Regex.Match(nextLine, @"^  \+ playlist:");
            if (m.Success)
            {
                thisTitle.Playlist = nextLine.Replace("+ playlist:", string.Empty).Trim();
                nextLine           = output.ReadLine();
            }

            // Jump over the VTS and blocks line
            m = Regex.Match(nextLine, @"^  \+ vts:");
            if (nextLine.Contains("blocks") || nextLine.Contains("+ vts "))
            {
                nextLine = output.ReadLine();
            }

            // Multi-Angle Support if LibDvdNav is enabled
            if (!userSettingService.GetUserSetting <bool>(ASUserSettingConstants.DisableLibDvdNav))
            {
                m = Regex.Match(nextLine, @"  \+ angle\(s\) ([0-9])");
                if (m.Success)
                {
                    string angleList = m.Value.Replace("+ angle(s) ", string.Empty).Trim();
                    int    angleCount;
                    int.TryParse(angleList, out angleCount);

                    thisTitle.AngleCount = angleCount;
                    nextLine             = output.ReadLine();
                }
            }

            // Get duration for this title
            m = Regex.Match(nextLine, @"^  \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})");
            if (m.Success)
            {
                thisTitle.Duration = TimeSpan.Parse(m.Groups[1].Value);
            }

            // Get resolution, aspect ratio and FPS for this title
            m = Regex.Match(output.ReadLine(), @"^  \+ size: ([0-9]*)x([0-9]*), pixel aspect: ([0-9]*)/([0-9]*), display aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");
            if (m.Success)
            {
                thisTitle.Resolution  = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
                thisTitle.ParVal      = new Size(int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value));
                thisTitle.AspectRatio = float.Parse(m.Groups[5].Value, Culture);
                thisTitle.Fps         = float.Parse(m.Groups[6].Value, Culture);
            }

            // Get autocrop region for this title
            m = Regex.Match(output.ReadLine(), @"^  \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)");
            if (m.Success)
            {
                thisTitle.AutoCropDimensions = new Cropping
                {
                    Top    = int.Parse(m.Groups[1].Value),
                    Bottom = int.Parse(m.Groups[2].Value),
                    Left   = int.Parse(m.Groups[3].Value),
                    Right  = int.Parse(m.Groups[4].Value)
                };
            }

            thisTitle.Chapters.AddRange(Chapter.ParseList(output));

            thisTitle.AudioTracks.AddRange(AudioHelper.ParseList(output));

            thisTitle.Subtitles.AddRange(Subtitle.ParseList(output));

            return(thisTitle);
        }
示例#9
0
        /// <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,
                                      };

            if ((source.SubtitleType == SubtitleType.PGS || source.SubtitleType == SubtitleType.VobSub || source.SubtitleType == SubtitleType.ForeignAudioSearch)
                && this.Task != null
                && (this.Task.OutputFormat == OutputFormat.Mp4 || this.Task.OutputFormat == OutputFormat.M4V))
            {
                if (track.CanBeBurned)
                {
                    track.Burned = true;
                    this.SetBurnedToFalseForAllExcept(track);
                }
            }

            this.Task.SubtitleTracks.Add(track);
        }