Пример #1
0
        private async void _btnConvert_Click(object sender, EventArgs e)
        {
            try
            {
                string outputFilePath;
                if (Path.GetExtension(_txtInputFile.Text).Equals(".ass", StringComparison.InvariantCultureIgnoreCase))
                {
                    AssDocument inputDoc  = new AssDocument(_txtInputFile.Text, (List <AssStyleOptions>)_lstStyles.DataSource);
                    YttDocument outputDoc = new YttDocument(inputDoc);
                    outputFilePath = Path.ChangeExtension(_txtInputFile.Text, ".ytt");
                    outputDoc.Save(outputFilePath);
                }
                else
                {
                    SubtitleDocument inputDoc  = SubtitleDocument.Load(_txtInputFile.Text);
                    SrtDocument      outputDoc = new SrtDocument(inputDoc);
                    outputFilePath = Path.ChangeExtension(_txtInputFile.Text, ".srt");
                    outputDoc.Save(outputFilePath);
                }

                _lblConversionSuccess.Text    = string.Format(Resources.SuccessfullyCreated0, Path.GetFileName(outputFilePath));
                _lblConversionSuccess.Visible = true;
                await Task.Delay(4000);

                _lblConversionSuccess.Visible = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Пример #2
0
        public void TestForwardConversion(string assFilePath, List <AssStyleOptions> styleOptions, string expectedYttFilePath)
        {
            SubtitleDocument assDoc = new AssDocument(assFilePath, styleOptions);
            SubtitleDocument yttDoc = new YttDocument(assDoc);

            try
            {
                yttDoc.Save("actual.ytt");

                string actual   = File.ReadAllText("actual.ytt");
                string expected = File.ReadAllText(expectedYttFilePath);
                Assert.That(actual, Is.EqualTo(expected));
            }
            finally
            {
                File.Delete("actual.ytt");
            }
        }
Пример #3
0
        public void TestReverseConversion(string inputYttFilePath)
        {
            SubtitleDocument yttDoc = new YttDocument(inputYttFilePath);
            SubtitleDocument assDoc = new AssDocument(yttDoc);

            try
            {
                assDoc.Save("actual.ass");

                assDoc = new AssDocument("actual.ass", AssStyleOptionsList.LoadFromString(Resources.DefaultStyleOptions));
                yttDoc = new YttDocument(assDoc);
                yttDoc.Save("actual.ytt");

                string actual   = File.ReadAllText("actual.ytt");
                string expected = RoundYttTimestamps(File.ReadAllText(inputYttFilePath));
                Assert.That(actual, Is.EqualTo(expected));
            }
            finally
            {
                File.Delete("actual.ass");
                File.Delete("actual.ytt");
            }
        }