示例#1
0
        private static void RunCommandLine(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Too many arguments specified");
                return;
            }

            string filePath = args[0];

            if (!File.Exists(filePath))
            {
                Console.WriteLine("Specified file not found");
                return;
            }

            try
            {
                if (Path.GetExtension(filePath).Equals(".ass", StringComparison.InvariantCultureIgnoreCase))
                {
                    SubtitleDocument doc = new AssDocument(filePath, AssStyleOptionsList.Load());
                    new YttDocument(doc).Save(Path.ChangeExtension(filePath, ".ytt"));
                }
                else
                {
                    SubtitleDocument doc = SubtitleDocument.Load(filePath);
                    new SrtDocument(doc).Save(Path.ChangeExtension(filePath, ".srt"));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error occurred: {ex}");
            }
        }
示例#2
0
        private static void RunCommandLine(string[] args)
        {
            CommandLineArguments parsedArgs = ParseArguments(args);

            if (parsedArgs == null)
            {
                return;
            }

            if (!File.Exists(parsedArgs.SourceFilePath))
            {
                Console.WriteLine("Specified source file not found");
                return;
            }

            try
            {
                SubtitleDocument sourceDoc      = SubtitleDocument.Load(parsedArgs.SourceFilePath);
                SubtitleDocument destinationDoc =
                    Path.GetExtension(parsedArgs.DestinationFilePath).ToLower() switch
                {
                    ".ass" => parsedArgs.ForVisualization ? new VisualizingAssDocument(sourceDoc) : new AssDocument(sourceDoc),
                    ".srv3" => new YttDocument(sourceDoc),
                    ".ytt" => new YttDocument(sourceDoc),
                    _ => new SrtDocument(sourceDoc)
                };
                destinationDoc.Save(parsedArgs.DestinationFilePath);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error occurred: {ex}");
            }
        }
示例#3
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);
            }
        }
示例#4
0
        private async void _btnConvert_Click(object sender, EventArgs e)
        {
            try
            {
                string           inputExtension = Path.GetExtension(_txtInputFile.Text).ToLower();
                SubtitleDocument outputDoc;
                string           outputExtension;

                switch (inputExtension)
                {
                case ".ass":
                {
                    AssDocument inputDoc = new AssDocument(_txtInputFile.Text, (List <AssStyleOptions>)_lstStyles.DataSource);
                    outputDoc       = new YttDocument(inputDoc);
                    outputExtension = ".ytt";

                    RefreshStyleList(inputDoc);
                    break;
                }

                case ".ytt":
                case ".srv3":
                {
                    YttDocument inputDoc = new YttDocument(_txtInputFile.Text);
                    outputDoc       = new AssDocument(inputDoc);
                    outputExtension = inputExtension == ".ytt" ? ".reverse.ass" : ".ass";
                    break;
                }

                default:
                {
                    SubtitleDocument inputDoc = SubtitleDocument.Load(_txtInputFile.Text);
                    outputDoc       = new SrtDocument(inputDoc);
                    outputExtension = ".srt";
                    break;
                }
                }

                string outputFilePath = Path.ChangeExtension(_txtInputFile.Text, outputExtension);
                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);
            }
        }
示例#5
0
        private void LoadFile(string filePath)
        {
            ClearUi();

            try
            {
                SubtitleDocument doc = SubtitleDocument.Load(filePath);
                PopulateUi(filePath, doc);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format(Resources.FailedToLoadFile0, ex.Message), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }