Пример #1
0
 /// <summary>Initializes a new instance of the <see cref="SubtitleTypeInfo" /> class.</summary>
 /// <param name="name">The name of the subtitle type.</param>
 /// <param name="type">The subtitle type.</param>
 /// <param name="mode">The subtitle mode.</param>
 /// <param name="extensions">The extensions the subtitle type uses.</param>
 public SubtitleTypeInfo(string name, SubtitleType type, SubtitleMode mode, string[] extensions)
 {
     this.name       = name;
     this.type       = type;
     this.mode       = mode;
     this.extensions = extensions;
 }
Пример #2
0
        /* Private members */

        private ParseHeaderDelegate GetHeaderParser(SubtitleType subtitleType)
        {
            switch (subtitleType)
            {
            case SubtitleType.SubViewer1:
                return(new ParseHeaderDelegate(ParseHeaderSubViewer1));

            case SubtitleType.SubViewer2:
                return(new ParseHeaderDelegate(ParseHeaderSubViewer2));

            case SubtitleType.KaraokeLyricsLRC:
                return(new ParseHeaderDelegate(ParseHeaderKaraokeLyricsLRC));

            case SubtitleType.KaraokeLyricsVKT:
                return(new ParseHeaderDelegate(ParseHeaderKaraokeLyricsVKT));

            case SubtitleType.MPSub:
                return(new ParseHeaderDelegate(ParseHeaderMPSub));

            case SubtitleType.SubStationAlpha:
                return(new ParseHeaderDelegate(ParseHeaderSubStationAlphaAAS));

            case SubtitleType.AdvancedSubStationAlpha:
                return(new ParseHeaderDelegate(ParseHeaderSubStationAlphaAAS));

            default:
                return(null);
            }
        }
Пример #3
0
        private void OnDefaultsFileSaveFormatChanged(object o, EventArgs args)
        {
            int active = fileSaveFormat.ActiveSelection;
            ConfigFileSaveFormatOption activeOption = (ConfigFileSaveFormatOption)Enum.ToObject(typeof(ConfigFileSaveFormatOption), active);

            if (((int)activeOption) > ((int)ConfigFileSaveFormatOption.Specific))     //Positions higher than specific are always specific too
            {
                activeOption = ConfigFileSaveFormatOption.Specific;
            }

            Base.Config.FileSaveFormatOption = activeOption;
            /* If format is specific, formatOption=Specific and format holds the format name */
            if (activeOption == ConfigFileSaveFormatOption.Specific)
            {
                SubtitleType chosenFormat = fileSaveFormat.ChosenSubtitleType;
                if (!chosenFormat.Equals(SubtitleType.Unknown))
                {
                    Base.Config.FileSaveFormatFixed = chosenFormat;
                }
            }
            else
            {
                /* If format option is keep existing or remember last, use keep existing */
                Base.Config.FileSaveFormat = ConfigFileSaveFormat.KeepExisting;
            }
        }
Пример #4
0
	/// <summary>Creates a new instance of the <see cref="FileProperties" /> class, given its properties.</summary>
	/// <param name="path">The file's path.</param>
	/// <param name="encoding">The file's character coding.</param>
	/// <param name="subtitleType">The file's subtitle type.</param>
	/// <param name="timingMode">The file's timing mode. This is more useful for the subtitle types that support both the time and frame modes.</param>
	/// <param name="newlineType">The file's newline type.</param>
	public FileProperties (string path, Encoding encoding, SubtitleType subtitleType, TimingMode timingMode, NewlineType newlineType) {
		this.path = path;
		this.encoding = encoding;
		this.subtitleType = subtitleType;
		this.timingMode = timingMode;
		this.newlineType = newlineType;
	}
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Subtitle"/> class.
 /// </summary>
 /// <param name="trackNumber">
 /// The track number.
 /// </param>
 /// <param name="language">
 /// The language.
 /// </param>
 /// <param name="languageCode">
 /// The language code.
 /// </param>
 /// <param name="subtitleType">
 /// The subtitle type.
 /// </param>
 public Subtitle(int trackNumber, string language, string languageCode, SubtitleType subtitleType)
 {
     this.TrackNumber = trackNumber;
     this.Language = language;
     this.LanguageCode = languageCode;
     this.SubtitleType = subtitleType;
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Subtitle"/> class.
 /// </summary>
 /// <param name="trackNumber">
 /// The track number.
 /// </param>
 /// <param name="language">
 /// The language.
 /// </param>
 /// <param name="languageCode">
 /// The language code.
 /// </param>
 /// <param name="subtitleType">
 /// The subtitle type.
 /// </param>
 public Subtitle(int trackNumber, string language, string languageCode, SubtitleType subtitleType)
 {
     this.TrackNumber  = trackNumber;
     this.Language     = language;
     this.LanguageCode = languageCode;
     this.SubtitleType = subtitleType;
 }
Пример #7
0
        private void buttonConfirm_Click(object sender, EventArgs e)
        {
            if (checkBoxInternalSubs.Checked)
            {
                SubtitleType type = Program.SubtitleTracks[(int)comboBoxVideoTracks.SelectedValue].Item2;
                string       extension;
                switch (type)
                {
                case SubtitleType.TextSub:
                    extension = Program.SubtitleTracks[(int)comboBoxVideoTracks.SelectedValue].Item3;
                    break;

                case SubtitleType.VobSub:
                    extension = ".idx";
                    break;

                default:
                    throw new NotImplementedException();
                }
                string filename = Path.Combine(Program.AttachmentDirectory, string.Format("sub{0}{1}", (int)comboBoxVideoTracks.SelectedValue, extension));
                GeneratedFilter = new SubtitleFilter(filename, type, (int)comboBoxVideoTracks.SelectedValue);
            }
            else
            {
                string       filename = textBoxSubtitleFile.Text;
                SubtitleType type     = Path.GetExtension(filename) == ".sub" ? SubtitleType.VobSub : SubtitleType.TextSub;
                GeneratedFilter = new SubtitleFilter(filename, type);
            }
        }
Пример #8
0
        // format "hh:mm:ss,fff" or "hh:mm:ss.ff"
        public static long TimeToMilliseconds(string timeString, out SubtitleType type)
        {
            DateTime date;

            type = SubtitleType.None; // default

            try
            {
                // try SubRip format by default
                date = DateTime.ParseExact(timeString, "hh:mm:ss,fff", System.Globalization.CultureInfo.InvariantCulture);
                type = SubtitleType.SubRip;
            }
            catch (Exception /*e*/)
            {
                try
                {
                    // try SubViewer format
                    date = DateTime.ParseExact(timeString, "hh:mm:ss.ff", System.Globalization.CultureInfo.InvariantCulture);
                    type = SubtitleType.SubViewer;
                }
                catch (Exception /*e*/)
                {
                    throw new Exception("Cannot convert time " + timeString);
                }
            }

            long totalMilliseconds = 1000 * (3600 * date.Hour + 60 * date.Minute + date.Second) + date.Millisecond;

            return(totalMilliseconds);
        }
Пример #9
0
        public static string MillisecondsToTime(long totalMilliseconds, SubtitleType type)
        {
            try
            {
                DateTime date = DateTime.Now.Date; // dummy
                date = date.AddMilliseconds((double)totalMilliseconds);

                string timeString = "";
                switch (type)
                {
                case SubtitleType.SubRip:
                    timeString = date.ToString("HH:mm:ss,fff", System.Globalization.CultureInfo.InvariantCulture);
                    break;

                case SubtitleType.SubViewer:
                    timeString = date.ToString("HH:mm:ss.ff", System.Globalization.CultureInfo.InvariantCulture);
                    break;

                default:
                    throw new Exception("Cannot convert milliseconds " + totalMilliseconds.ToString());
                }

                return(timeString);
            }
            catch (Exception /*e*/)
            {
                throw new Exception("Cannot convert milliseconds " + totalMilliseconds.ToString());
            }
        }
Пример #10
0
        private string UpdateFilenameExtension(string filename, SubtitleType type)
        {
            SubtitleTypeInfo typeInfo           = Subtitles.GetAvailableType(type);
            string           newExtensionDotted = "." + typeInfo.PreferredExtension;

            int    index           = -1;
            string extensionDotted = "." + GetFilenameExtension(filename, out index);

            if (extensionDotted == newExtensionDotted)     //filename already has the correct extension
            {
                return(filename);
            }
            else if (index == -1)     //filename doesn't have an extension, appending
            {
                return(filename + newExtensionDotted);
            }
            else if (Subtitles.IsSubtitleExtension(extensionDotted))        //filename's extension is a subtitle extension
            {
                int dotIndex = index - 1;
                return(filename.Substring(0, dotIndex) + newExtensionDotted);
            }
            else     //filename's extension is not a subtitle extension
            {
                return(filename + newExtensionDotted);
            }
        }
Пример #11
0
 /// <summary>Creates a new instance of the <see cref="FileProperties" /> class, given its properties.</summary>
 /// <param name="path">The file's path.</param>
 /// <param name="encoding">The file's character coding.</param>
 /// <param name="subtitleType">The file's subtitle type.</param>
 /// <param name="timingMode">The file's timing mode. This is more useful for the subtitle types that support both the time and frame modes.</param>
 /// <param name="newlineType">The file's newline type.</param>
 public FileProperties(string path, Encoding encoding, SubtitleType subtitleType, TimingMode timingMode, NewlineType newlineType)
 {
     this.path         = path;
     this.encoding     = encoding;
     this.subtitleType = subtitleType;
     this.timingMode   = timingMode;
     this.newlineType  = newlineType;
 }
Пример #12
0
 public void StopTimer(SubtitleType key)
 {
     if (timersDictionary.ContainsKey(key))
     {
         timersDictionary[key].currentTime = 0;
         timersDictionary[key].canCount    = false;
     }
 }
Пример #13
0
 public override string ToString()
 {
     if (TrackDescription != null)
     {
         return(TrackDescription.Name);
     }
     return(FileName == null?SubtitleType.ToString() : FileName);
 }
	private SubtitleType fixedSubtitleType = SubtitleType.Unknown; //A subtitle type that must be selected

	public SubtitleFormatComboBox (ComboBox comboBox, SubtitleType fixedSubtitleType, string[] additionalActions) {
		this.comboBox = comboBox;
		this.fixedSubtitleType = fixedSubtitleType;
		this.additionalActions = additionalActions;

		InitComboBoxModel();
		SetComboBox();
		ConnectHandlers();
	}
Пример #15
0
 public SubtitleFilesModel(SubtitleType SubtitleType, string dir)
 {
     if (dir != null)
     {
         this.Directory = dir;
         this.FileName  = Path.GetFileNameWithoutExtension(dir);
     }
     this.SubtitleType = SubtitleType;
 }
        private SubtitleType fixedSubtitleType = SubtitleType.Unknown; //A subtitle type that must be selected

        public SubtitleFormatComboBox(SubtitleType fixedSubtitleType, string[] additionalActions)
        {
            this.comboBox          = new ComboBoxText();
            this.fixedSubtitleType = fixedSubtitleType;
            this.additionalActions = additionalActions;

            this.subtitleTypes = Subtitles.AvailableTypesSorted;
            FillComboBox();
            ConnectHandlers();
        }
Пример #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Subtitle"/> class.
 /// </summary>
 /// <param name="sourceId">
 /// The source Id.
 /// </param>
 /// <param name="trackNumber">
 /// The track number.
 /// </param>
 /// <param name="language">
 /// The language.
 /// </param>
 /// <param name="languageCode">
 /// The language code.
 /// </param>
 /// <param name="subtitleType">
 /// The subtitle type.
 /// </param>
 /// <param name="canBurn">
 /// The can Burn.
 /// </param>
 /// <param name="canForce">
 /// The can Force.
 /// </param>
 public Subtitle(int sourceId, int trackNumber, string language, string languageCode, SubtitleType subtitleType, bool canBurn, bool canForce)
 {
     this.SourceId = sourceId;
     this.TrackNumber = trackNumber;
     this.Language = language;
     this.LanguageCode = languageCode;
     this.SubtitleType = subtitleType;
     this.CanBurnIn = canBurn;
     this.CanForce = canForce;
 }
Пример #18
0
 public static ISubtitle GetSubtitle(SubtitleType subtitleType)
 {
     switch (subtitleType)
     {
         case SubtitleType.Src:
             return new SrtSubtitle();
         default:
             throw new ArgumentOutOfRangeException("subtitleType");
     }
 }
 internal static SubtitleFormat GetFormat(SubtitleType subtitleType)
 {
     if (subtitleType == SubtitleType.Unknown)
     {
         return(null);
     }
     else
     {
         return(subtitleFormats[(int)subtitleType - 1]);
     }
 }
Пример #20
0
        private string GetSubtitleFormat(SubtitleType type)
        {
            if (type == SubtitleType.Unknown)
            {
                return(null);
            }

            SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);

            return(typeInfo.Name);
        }
Пример #21
0
	private void FillSubtitleFormat (SubtitleType type) {
		string format = String.Empty;
		if (type == SubtitleType.Unknown)
			format = Catalog.GetString("Unknown");
		else {
			SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);
			format = typeInfo.Name;
		}

		subtitleFormatValueLabel.Text = format;
	}
Пример #22
0
        private string AddExtensionIfNeeded(string filename, SubtitleType type)
        {
            int    index     = 0;
            string extension = GetFilenameExtension(filename, out index);

            SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);

            if (typeInfo.HasExtension(extension))
            {
                return(filename);
            }
            else
            {
                return(filename + "." + typeInfo.PreferredExtension);
            }
        }
Пример #23
0
        public static string AdjustTime(string timeString, double speed = 1.0, long delay = 0)
        {
            try
            {
                SubtitleType type                 = SubtitleType.None;
                long         milliseconds         = TimeToMilliseconds(timeString, out type);
                long         adjustedMilliseconds = (long)((1.0 / speed) * milliseconds + delay); // adjust
                adjustedMilliseconds = Math.Max(0, adjustedMilliseconds);                         // ensure positive time
                string adjustedTimeString = MillisecondsToTime(adjustedMilliseconds, type);

                return(adjustedTimeString);
            }
            catch (Exception /*e*/)
            {
                throw new Exception("Cannot convert time " + timeString);
            }
        }
Пример #24
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length >= 1)
            {
                bool         sourceTrackCanBurn = (bool)values[0];
                SubtitleType type = (SubtitleType)values[1];
                EncodeTask   task = values[2] as EncodeTask;

                if (task != null && OutputFormat.Mp4.Equals(task.OutputFormat) && SubtitleType.PGS.Equals(type))
                {
                    return(false);
                }

                return(sourceTrackCanBurn);
            }

            return(true);
        }
Пример #25
0
        /// <summary>Displays a SaveAs dialog and gets the chosen options as <cref="FileProperties" />.</summary>
        /// <param name="dialog">The dialog to display.</param>
        /// <returns>The chosen file properties, or null in case SaveAs was canceled.</returns>
        private FileProperties ShowSaveAsDialog(FileSaveDialog dialog)
        {
            dialog.Show();
            bool toSaveAs = dialog.WaitForResponse();

            if (!toSaveAs)
            {
                return(null);
            }

            string       path         = dialog.Filename;
            Encoding     encoding     = Encodings.GetEncoding(dialog.Encoding.CodePage);
            SubtitleType subtitleType = dialog.SubtitleType;
            NewlineType  newlineType  = dialog.NewlineType;
            TimingMode   timingMode   = Base.TimingMode;

            return(new FileProperties(path, encoding, subtitleType, timingMode, newlineType));
        }
Пример #26
0
        public SubtitleMonitorTask(int videoSeq, Language language, SubtitleType type, TimeSpan period, VSharpService service) : base(videoSeq, period, service)
        {
            Language = language;
            Type     = type;
            Id       = new SubtitleMonitorTaskId(videoSeq, language, type);

            Timer = new Timer(async(s) =>
            {
                if (Checking)
                {
                    return;
                }

                // Set flag to prevent overlapping checks
                Checking = true;

                try
                {
                    VODInfo vodInfo = await Service.GetVODInfoAsync(VideoSeq);

                    // Only continue if the VOD has caption data
                    if (vodInfo.CaptionInfo == null)
                    {
                        return;
                    }

                    foreach (var details in vodInfo.CaptionInfo.Details)
                    {
                        if (details.Locale == Language.Value && details.Type.ToLower() == Type.Value)
                        {
                            SubtitleAvailable.Invoke(null, CreateSubtitleEventArgs(VideoSeq, details));
                        }
                    }
                }
                catch (Exception e)
                {
                    ExceptionThrown.Invoke(null, e);
                }
                finally
                {
                    Checking = false;
                }
            }, null, Timeout.Infinite, Timeout.Infinite);
        }
Пример #27
0
        private void BuildFormatComboBox()
        {
            SubtitleType         fixedSubtitleType = GetFixedSubtitleType();
            ConfigFileSaveFormat formatConfig      = Base.Config.FileSaveFormat;

            if (formatConfig == ConfigFileSaveFormat.Fixed)
            {
                fixedSubtitleType = Base.Config.FileSaveFormatFixed;
            }

            /* Check if fixed subtitle type has been correctly identified */
            if (fixedSubtitleType == SubtitleType.Unknown)
            {
                fixedSubtitleType = SubtitleType.SubRip;
            }

            formatComboBox = new SubtitleFormatComboBox(fixedSubtitleType, null);
            formatComboBox.SelectionChanged += OnFormatChanged;
        }
Пример #28
0
        private SubtitleFormatComboBox BuildFileSaveFormatComboBox()
        {
            string[]     additionalActions = { Catalog.GetString("Keep the format used on file open"), Catalog.GetString("Remember the last used format") };
            SubtitleType fixedFormat       = SubtitleType.Unknown;
            ConfigFileSaveFormatOption fileSaveFormatOption = Base.Config.FileSaveFormatOption;

            if (fileSaveFormatOption == ConfigFileSaveFormatOption.Specific)
            {
                fixedFormat = Base.Config.FileSaveFormatFixed;
            }

            SubtitleFormatComboBox comboBox = new SubtitleFormatComboBox(fixedFormat, additionalActions);

            if (fileSaveFormatOption != ConfigFileSaveFormatOption.Specific)
            {
                comboBox.ActiveSelection = (int)fileSaveFormatOption;
            }
            comboBox.SelectionChanged += OnDefaultsFileSaveFormatChanged;
            return(comboBox);
        }
Пример #29
0
        /* Event members */

        protected override bool ProcessResponse(ResponseType response)
        {
            if (response == ResponseType.Ok)
            {
                /* Check chosen encoding */
                chosenEncoding = encodingComboBox.ChosenEncoding;
                if (Base.Config.FileSaveEncodingOption == ConfigFileSaveEncodingOption.RememberLastUsed)
                {
                    int activeAction = encodingComboBox.ActiveSelection;
                    ConfigFileSaveEncoding activeOption = (ConfigFileSaveEncoding)Enum.ToObject(typeof(ConfigFileSaveEncoding), activeAction);
                    if (((int)activeOption) >= ((int)ConfigFileSaveEncoding.Fixed))
                    {
                        Base.Config.FileSaveEncodingFixed = chosenEncoding.Code;
                    }
                    else
                    {
                        Base.Config.FileSaveEncoding = activeOption;
                    }
                }

                /* Check chosen subtitle format */
                chosenSubtitleType = formatComboBox.ChosenSubtitleType;
                if (Base.Config.FileSaveFormatOption == ConfigFileSaveFormatOption.RememberLastUsed)
                {
                    Base.Config.FileSaveFormatFixed = chosenSubtitleType;
                }

                /* Check chosen newline type */
                chosenNewlineType = newlineComboBox.ChosenNewlineType;
                if (Base.Config.FileSaveNewlineOption == ConfigFileSaveNewlineOption.RememberLastUsed)
                {
                    Base.Config.FileSaveNewline = chosenNewlineType;
                }

                chosenFilename = (Dialog as FileChooserDialog).Filename;
                SetReturnValue(true);
            }
            return(false);
        }
Пример #30
0
        public void AddTimer(SubtitleType key, float timeToTimeIN)
        {
            if (timeToTimeIN == 0)
            {
                //Debug.Log(key + " subtitle time is set to zero no timer added");
                return;
            }


            if (!timersDictionary.ContainsKey(key))
            {
                Timer timer = new Timer();
                timer.timeToTime = timeToTimeIN;
                timersDictionary.Add(key, timer);
            }
            else
            {
                timersDictionary[key].currentTime = 0;
                timersDictionary[key].timeToTime  = timeToTimeIN;
                timersDictionary[key].canCount    = true;
            }
        }
Пример #31
0
        private void OnFormatChanged(object o, EventArgs args)
        {
            FileChooserDialog dialog = Dialog as FileChooserDialog;

            string filename = dialog.Filename;

            if ((filename == null) || (filename == String.Empty))
            {
                return;
            }

            string folder = dialog.CurrentFolder;

            if ((folder != null) && (folder != String.Empty))
            {
                filename = filename.Substring(folder.Length + 1);
            }

            SubtitleType subtitleType = formatComboBox.ChosenSubtitleType;

            filename           = UpdateFilenameExtension(filename, subtitleType);
            dialog.CurrentName = filename;
        }
Пример #32
0
        public void RegisterSubtitleMonitor(int videoSeq, Language language, SubtitleType type, TimeSpan timespan)
        {
            ValidateStrictlyPostiveInteger(videoSeq, nameof(videoSeq));

            lock (_lock)
            {
                SubtitleMonitorTask task = new SubtitleMonitorTask(videoSeq, language, type, timespan, _service);
                if (!_subtitleTasks.ContainsKey(task.Id.Value))
                {
                    task.ExceptionThrown   += ExceptionThrownRepeater;
                    task.SubtitleAvailable += SubtitleAvailableRepeater;
                    bool success = _subtitleTasks.TryAdd(task.Id.Value, task);
                    if (!success)
                    {
                        ExceptionThrown.Invoke(null, new FailedToRegisterSubtitleMonitorException(videoSeq, language.Value, type.Value, Monitor.Subtitle, "Failed to register a task with the monitor service."));
                    }
                    else
                    {
                        task.StartTask();
                    }
                }
            }
        }
Пример #33
0
	/* Public methods */

	/// <summary>Get information about an available subtitle type.</summary>
	/// <param name="type">The subtitle type.</param>
	/// <returns>The information about the specified subtitle type.</returns>
	public static SubtitleTypeInfo GetAvailableType (SubtitleType type) {
		SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(type);
		return new SubtitleTypeInfo(format);
	}
	internal static SubtitleFormat GetFormat (SubtitleType subtitleType) {
		if (subtitleType == SubtitleType.Unknown)
			return null;
		else
			return subtitleFormats[(int)subtitleType - 1];
	}
Пример #35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Subtitle"/> class.
 /// </summary>
 /// <param name="sourceId">
 /// The source Id.
 /// </param>
 /// <param name="trackNumber">
 /// The track number.
 /// </param>
 /// <param name="language">
 /// The language.
 /// </param>
 /// <param name="languageCode">
 /// The language code.
 /// </param>
 /// <param name="subtitleType">
 /// The subtitle type.
 /// </param>
 /// <param name="canBurn">
 /// The can Burn.
 /// </param>
 /// <param name="canForce">
 /// The can Force.
 /// </param>
 public Subtitle(int sourceId, int trackNumber, string language, string languageCode, SubtitleType subtitleType, bool canBurn, bool canForce)
 {
     this.SourceId     = sourceId;
     this.TrackNumber  = trackNumber;
     this.Language     = language;
     this.LanguageCode = languageCode;
     this.SubtitleType = subtitleType;
     this.CanBurnIn    = canBurn;
     this.CanForce     = canForce;
 }
Пример #36
0
        /// <summary>
        /// Convert Interop Title objects to App Services Title object
        /// </summary>
        /// <param name="titles">
        /// The titles.
        /// </param>
        /// <returns>
        /// The convert titles.
        /// </returns>
        internal static List<Title> ConvertTitles(JsonScanObject titles)
        {
            List<Title> titleList = new List<Title>();
            foreach (SourceTitle title in titles.TitleList)
            {
                Title converted = new Title
                    {
                        TitleNumber = title.Index,
                        Duration = new TimeSpan(0, title.Duration.Hours, title.Duration.Minutes, title.Duration.Seconds),
                        Resolution = new Size(title.Geometry.Width, title.Geometry.Height),
                        AngleCount = title.AngleCount,
                        ParVal = new Size(title.Geometry.PAR.Num, title.Geometry.PAR.Den),
                        AutoCropDimensions = new Cropping
                        {
                            Top = title.Crop[0],
                            Bottom = title.Crop[1],
                            Left = title.Crop[2],
                            Right = title.Crop[3]
                        },
                        Fps = ((double)title.FrameRate.Num) / title.FrameRate.Den,
                        SourceName = title.Path,
                        MainTitle = titles.MainFeature == title.Index,
                        Playlist = title.Type == 1 ? string.Format(" {0:d5}.MPLS", title.Playlist).Trim() : null,
                        FramerateNumerator = title.FrameRate.Num,
                        FramerateDenominator = title.FrameRate.Den
                    };

                int currentTrack = 1;
                foreach (SourceChapter chapter in title.ChapterList)
                {
                    string chapterName = !string.IsNullOrEmpty(chapter.Name) ? chapter.Name : string.Empty;
                    converted.Chapters.Add(new Chapter(currentTrack, chapterName, new TimeSpan(chapter.Duration.Hours, chapter.Duration.Minutes, chapter.Duration.Seconds)));
                    currentTrack++;
                }

                int currentAudioTrack = 1;
                foreach (SourceAudioTrack track in title.AudioList)
                {
                    converted.AudioTracks.Add(new Audio(currentAudioTrack, track.Language, track.LanguageCode, track.Description, string.Empty, track.SampleRate, track.BitRate));
                    currentAudioTrack++;
                }

                int currentSubtitleTrack = 1;
                foreach (SourceSubtitleTrack track in title.SubtitleList)
                {
                    SubtitleType convertedType = new SubtitleType();

                    switch (track.Source)
                    {
                        case 0:
                            convertedType = SubtitleType.VobSub;
                            break;
                        case 4:
                            convertedType = SubtitleType.UTF8Sub;
                            break;
                        case 5:
                            convertedType = SubtitleType.TX3G;
                            break;
                        case 6:
                            convertedType = SubtitleType.SSA;
                            break;
                        case 1:
                            convertedType = SubtitleType.SRT;
                            break;
                        case 2:
                            convertedType = SubtitleType.CC;
                            break;
                        case 3:
                            convertedType = SubtitleType.CC;
                            break;
                        case 7:
                            convertedType = SubtitleType.PGS;
                            break;
                    }

                    bool canBurn = HBFunctions.hb_subtitle_can_burn(track.Source) > 0;
                    bool canSetForcedOnly = HBFunctions.hb_subtitle_can_force(track.Source) > 0;

                    converted.Subtitles.Add(new Subtitle(track.Source, currentSubtitleTrack, track.Language, track.LanguageCode, convertedType, canBurn, canSetForcedOnly));
                    currentSubtitleTrack++;
                }

                titleList.Add(converted);
            }

            return titleList;
        }
Пример #37
0
        public Title CreateTitle(SourceTitle title, int mainFeature)
        {
            Title converted = new Title
            {
                TitleNumber        = title.Index,
                Duration           = new TimeSpan(0, title.Duration.Hours, title.Duration.Minutes, title.Duration.Seconds),
                Resolution         = new Size(title.Geometry.Width, title.Geometry.Height),
                AngleCount         = title.AngleCount,
                ParVal             = new Size(title.Geometry.PAR.Num, title.Geometry.PAR.Den),
                AutoCropDimensions = new Cropping
                {
                    Top    = title.Crop[0],
                    Bottom = title.Crop[1],
                    Left   = title.Crop[2],
                    Right  = title.Crop[3]
                },
                Fps                  = ((double)title.FrameRate.Num) / title.FrameRate.Den,
                SourceName           = title.Path,
                MainTitle            = mainFeature == title.Index,
                Playlist             = title.Type == 1 ? string.Format(" {0:d5}.MPLS", title.Playlist).Trim() : null,
                FramerateNumerator   = title.FrameRate.Num,
                FramerateDenominator = title.FrameRate.Den,
                Type                 = title.Type
            };

            int currentTrack = 1;

            foreach (SourceChapter chapter in title.ChapterList)
            {
                string chapterName = !string.IsNullOrEmpty(chapter.Name) ? chapter.Name : string.Empty;
                converted.Chapters.Add(new Chapter(currentTrack, chapterName, new TimeSpan(chapter.Duration.Hours, chapter.Duration.Minutes, chapter.Duration.Seconds)));
                currentTrack++;
            }

            int currentAudioTrack = 1;

            foreach (SourceAudioTrack track in title.AudioList)
            {
                converted.AudioTracks.Add(new Audio(currentAudioTrack, track.Language, track.LanguageCode, track.Description, track.Codec, track.SampleRate, track.BitRate, track.ChannelLayout, track.Name));
                currentAudioTrack++;
            }

            int currentSubtitleTrack = 1;

            foreach (SourceSubtitleTrack track in title.SubtitleList)
            {
                SubtitleType convertedType = new SubtitleType();

                switch (track.Source)
                {
                case (int)hb_subtitle_s_subsource.VOBSUB:
                    convertedType = SubtitleType.VobSub;
                    break;

                case (int)hb_subtitle_s_subsource.CC608SUB:
                case (int)hb_subtitle_s_subsource.CC708SUB:
                    convertedType = SubtitleType.CC;
                    break;

                case (int)hb_subtitle_s_subsource.IMPORTSRT:
                    convertedType = SubtitleType.SRT;
                    break;

                case (int)hb_subtitle_s_subsource.UTF8SUB:
                    convertedType = SubtitleType.UTF8Sub;
                    break;

                case (int)hb_subtitle_s_subsource.TX3GSUB:
                    convertedType = SubtitleType.TX3G;
                    break;

                case (int)hb_subtitle_s_subsource.SSASUB:
                    convertedType = SubtitleType.SSA;
                    break;

                case (int)hb_subtitle_s_subsource.PGSSUB:
                    convertedType = SubtitleType.PGS;
                    break;
                }

                IHbFunctionsProvider provider    = IoC.Get <IHbFunctionsProvider>(); // TODO remove IoC call
                IHbFunctions         hbFunctions = provider.GetHbFunctionsWrapper();

                bool canBurn          = hbFunctions.hb_subtitle_can_burn(track.Source) > 0;
                bool canSetForcedOnly = hbFunctions.hb_subtitle_can_force(track.Source) > 0;

                converted.Subtitles.Add(new Subtitle(track.Source, currentSubtitleTrack, track.Language, track.LanguageCode, convertedType, canBurn, canSetForcedOnly, track.Name));
                currentSubtitleTrack++;
            }

            SourceMetadata metadata = title.MetaData;

            if (title.MetaData != null)
            {
                converted.Metadata = new Metadata(
                    metadata.AlbumArtist,
                    metadata.Album,
                    metadata.Artist,
                    metadata.Comment,
                    metadata.Composer,
                    metadata.Description,
                    metadata.Genre,
                    metadata.LongDescription,
                    metadata.Name,
                    metadata.ReleaseDate);
            }

            return(converted);
        }
Пример #38
0
	/// <summary>Creates a new instance of the <see cref="FileProperties" /> class, given its properties.</summary>
	/// <param name="path">The file's path.</param>
	/// <param name="encoding">The file's character coding.</param>
	/// <param name="subtitleType">The file's subtitle type.</param>
	/// <param name="timingMode">The file's timing mode. This is more useful for the subtitle types that support both the time and frame modes.</param>
	public FileProperties (string path, Encoding encoding, SubtitleType subtitleType, TimingMode timingMode)
		: this(path, encoding, subtitleType, timingMode, NewlineType.Unknown) {
	}
Пример #39
0
        /// <summary>
        /// Convert Interop Title objects to App Services Title object
        /// </summary>
        /// <param name="titles">
        /// The titles.
        /// </param>
        /// <returns>
        /// The convert titles.
        /// </returns>
        private static List<Title> ConvertTitles(IEnumerable<Interop.SourceData.Title> titles)
        {
            List<Title> titleList = new List<Title>();
            foreach (Interop.SourceData.Title title in titles)
            {
                Title converted = new Title
                    {
                        TitleNumber = title.TitleNumber,
                        Duration = title.Duration,
                        Resolution = new Size(title.Resolution.Width, title.Resolution.Height),
                        AspectRatio = title.AspectRatio,
                        AngleCount = title.AngleCount,
                        ParVal = new Size(title.ParVal.Width, title.ParVal.Height),
                        AutoCropDimensions = title.AutoCropDimensions,
                        Fps = title.Framerate
                    };

                foreach (Interop.SourceData.Chapter chapter in title.Chapters)
                {
                    converted.Chapters.Add(new Chapter(chapter.ChapterNumber, string.Empty, chapter.Duration));
                }

                foreach (Interop.SourceData.AudioTrack track in title.AudioTracks)
                {
                    converted.AudioTracks.Add(new AudioTrack(track.TrackNumber, track.Language, track.LanguageCode, track.Description, string.Empty, track.SampleRate, track.Bitrate));
                }

                foreach (Interop.SourceData.Subtitle track in title.Subtitles)
                {
                    SubtitleType convertedType = new SubtitleType();

                    switch (track.SubtitleSource)
                    {
                        case Interop.SourceData.SubtitleSource.VobSub:
                            convertedType = SubtitleType.VobSub;
                            break;
                        case Interop.SourceData.SubtitleSource.UTF8:
                            convertedType = SubtitleType.UTF8Sub;
                            break;
                        case Interop.SourceData.SubtitleSource.TX3G:
                            convertedType = SubtitleType.TX3G;
                            break;
                        case Interop.SourceData.SubtitleSource.SSA:
                            convertedType = SubtitleType.SSA;
                            break;
                        case Interop.SourceData.SubtitleSource.SRT:
                            convertedType = SubtitleType.SRT;
                            break;
                        case Interop.SourceData.SubtitleSource.CC608:
                            convertedType = SubtitleType.CC;
                            break;
                        case Interop.SourceData.SubtitleSource.CC708:
                            convertedType = SubtitleType.CC;
                            break;
                    }

                    converted.Subtitles.Add(new Subtitle(track.TrackNumber, track.Language, track.LanguageCode, convertedType));
                }

                titleList.Add(converted);
            }

            return titleList;
        }
	private string UpdateFilenameExtension (string filename, SubtitleType type) {
		SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);
		string newExtensionDotted = "." + typeInfo.PreferredExtension;

		int index = -1;
		string extensionDotted = "." + GetFilenameExtension(filename, out index);

		if (extensionDotted == newExtensionDotted) //filename already has the correct extension
			return filename;
		else if (index == -1) //filename doesn't have an extension, appending
			return filename + newExtensionDotted;
		else if (Subtitles.IsSubtitleExtension(extensionDotted))  { //filename's extension is a subtitle extension
			int dotIndex = index - 1;
			return filename.Substring(0, dotIndex) + newExtensionDotted;
		}
		else //filename's extension is not a subtitle extension
			return filename + newExtensionDotted;
	}
	protected override bool ProcessResponse (ResponseType response) {
		if (response == ResponseType.Ok) {

			/* Check chosen encoding */
			chosenEncoding = encodingComboBoxComponent.ChosenEncoding;
			if (Base.Config.PrefsDefaultsFileSaveEncodingOption == ConfigFileSaveEncodingOption.RememberLastUsed) {
				int activeAction = encodingComboBoxComponent.ActiveSelection;
				ConfigFileSaveEncoding activeOption = (ConfigFileSaveEncoding)Enum.ToObject(typeof(ConfigFileSaveEncoding), activeAction);
				if (((int)activeOption) >= ((int)ConfigFileSaveEncoding.Fixed)) {
					Base.Config.PrefsDefaultsFileSaveEncodingFixed = chosenEncoding.Name;
				}
				else {
					Base.Config.PrefsDefaultsFileSaveEncoding = activeOption;
				}
			}

			/* Check chosen subtitle format */
			chosenSubtitleType = formatComboBoxComponent.ChosenSubtitleType;
			if (Base.Config.PrefsDefaultsFileSaveFormatOption == ConfigFileSaveFormatOption.RememberLastUsed) {
				Base.Config.PrefsDefaultsFileSaveFormatFixed = chosenSubtitleType;
			}

			/* Check chosen newline type */
			chosenNewlineType = newlineComboBoxComponent.ChosenNewlineType;
			if (Base.Config.PrefsDefaultsFileSaveNewlineOption == ConfigFileSaveNewlineOption.RememberLastUsed) {
				Base.Config.PrefsDefaultsFileSaveNewline = chosenNewlineType;
			}

			/* Check chosen filename */
			chosenFilename = AddExtensionIfNeeded(chosenSubtitleType);

			SetReturnValue(true);
		}
		return false;
	}
	private string AddExtensionIfNeeded (SubtitleType type) {
		string filename = dialog.Filename;
		int index = 0;
		string extension = GetFilenameExtension(filename, out index);

		SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);
		if (typeInfo.HasExtension(extension))
			return filename;
		else
			return filename + "." + typeInfo.PreferredExtension;
	}
Пример #43
0
 public SubtitleFilter(string fileName, SubtitleType type, int track = -1)
 {
     FileName = fileName;
     Type = type;
     Track = track;
 }
Пример #44
0
	/// <summary>Initializes a new instance of the <see cref="SubtitleTypeInfo" /> class.</summary>
	/// <param name="name">The name of the subtitle type.</param>
	/// <param name="type">The subtitle type.</param>
	/// <param name="mode">The subtitle mode.</param>
	/// <param name="extensions">The extensions the subtitle type uses.</param>
	public SubtitleTypeInfo (string name, SubtitleType type, SubtitleMode mode, string[] extensions) {
		this.name = name;
		this.type = type;
		this.mode = mode;
		this.extensions = extensions;
	}
Пример #45
0
        /// <summary>
        /// Convert Interop Title objects to App Services Title object
        /// </summary>
        /// <param name="titles">
        /// The titles.
        /// </param>
        /// <returns>
        /// The convert titles.
        /// </returns>
        private static List <Title> ConvertTitles(JsonScanObject titles)
        {
            List <Title> titleList = new List <Title>();

            foreach (SourceTitle title in titles.TitleList)
            {
                Title converted = new Title
                {
                    TitleNumber        = title.Index,
                    Duration           = new TimeSpan(0, title.Duration.Hours, title.Duration.Minutes, title.Duration.Seconds),
                    Resolution         = new Size(title.Geometry.Width, title.Geometry.Height),
                    AngleCount         = title.AngleCount,
                    ParVal             = new Size(title.Geometry.PAR.Num, title.Geometry.PAR.Den),
                    AutoCropDimensions = new Cropping
                    {
                        Top    = title.Crop[0],
                        Bottom = title.Crop[1],
                        Left   = title.Crop[2],
                        Right  = title.Crop[3]
                    },
                    Fps                  = ((double)title.FrameRate.Num) / title.FrameRate.Den,
                    SourceName           = title.Path,
                    MainTitle            = titles.MainFeature == title.Index,
                    Playlist             = title.Type == 1 ? string.Format(" {0:d5}.MPLS", title.Playlist).Trim() : null,
                    FramerateNumerator   = title.FrameRate.Num,
                    FramerateDenominator = title.FrameRate.Den,
                    Type                 = title.Type
                };

                int currentTrack = 1;
                foreach (SourceChapter chapter in title.ChapterList)
                {
                    string chapterName = !string.IsNullOrEmpty(chapter.Name) ? chapter.Name : string.Empty;
                    converted.Chapters.Add(new Chapter(currentTrack, chapterName, new TimeSpan(chapter.Duration.Hours, chapter.Duration.Minutes, chapter.Duration.Seconds)));
                    currentTrack++;
                }

                int currentAudioTrack = 1;
                foreach (SourceAudioTrack track in title.AudioList)
                {
                    converted.AudioTracks.Add(new Audio(currentAudioTrack, track.Language, track.LanguageCode, track.Description, track.Codec, track.SampleRate, track.BitRate, track.ChannelLayout));
                    currentAudioTrack++;
                }

                int currentSubtitleTrack = 1;
                foreach (SourceSubtitleTrack track in title.SubtitleList)
                {
                    SubtitleType convertedType = new SubtitleType();

                    switch (track.Source)
                    {
                    case 0:
                        convertedType = SubtitleType.VobSub;
                        break;

                    case 4:
                        convertedType = SubtitleType.UTF8Sub;
                        break;

                    case 5:
                        convertedType = SubtitleType.TX3G;
                        break;

                    case 6:
                        convertedType = SubtitleType.SSA;
                        break;

                    case 1:
                        convertedType = SubtitleType.SRT;
                        break;

                    case 2:
                        convertedType = SubtitleType.CC;
                        break;

                    case 3:
                        convertedType = SubtitleType.CC;
                        break;

                    case 7:
                        convertedType = SubtitleType.PGS;
                        break;
                    }

                    bool canBurn          = HBFunctions.hb_subtitle_can_burn(track.Source) > 0;
                    bool canSetForcedOnly = HBFunctions.hb_subtitle_can_force(track.Source) > 0;

                    converted.Subtitles.Add(new Subtitle(track.Source, currentSubtitleTrack, track.Language, track.LanguageCode, convertedType, canBurn, canSetForcedOnly));
                    currentSubtitleTrack++;
                }

                titleList.Add(converted);
            }

            return(titleList);
        }
Пример #46
0
	internal SubtitleInput (Encoding fallbackEncoding, SubtitleType subtitleType) {
		this.fallbackEncoding = fallbackEncoding;
		this.subtitleType = subtitleType;
	}
Пример #47
0
 internal SubtitleInput(Encoding fallbackEncoding, SubtitleType subtitleType)
 {
     this.fallbackEncoding = fallbackEncoding;
     this.subtitleType     = subtitleType;
 }
Пример #48
0
	/* Private members */

	private ParseHeaderDelegate GetHeaderParser (SubtitleType subtitleType) {
		switch (subtitleType) {
			case SubtitleType.SubViewer1:
				return new ParseHeaderDelegate(ParseHeaderSubViewer1);
			case SubtitleType.SubViewer2:
				return new ParseHeaderDelegate(ParseHeaderSubViewer2);
			case SubtitleType.KaraokeLyricsLRC:
				return new ParseHeaderDelegate(ParseHeaderKaraokeLyricsLRC);
			case SubtitleType.KaraokeLyricsVKT:
				return new ParseHeaderDelegate(ParseHeaderKaraokeLyricsVKT);
			case SubtitleType.MPSub:
				return new ParseHeaderDelegate(ParseHeaderMPSub);
			case SubtitleType.SubStationAlpha:
				return new ParseHeaderDelegate(ParseHeaderSubStationAlphaAAS);
			case SubtitleType.AdvancedSubStationAlpha:
				return new ParseHeaderDelegate(ParseHeaderSubStationAlphaAAS);
			default:
				return null;
		}
	}