Exemplo n.º 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}");
            }
        }
Exemplo n.º 2
0
        private void PopulateUi(string filePath, SubtitleDocument document)
        {
            _txtInputFile.Text = filePath;

            AssDocument assDoc = document as AssDocument;

            if (assDoc != null)
            {
                _grpStyleOptions.Enabled = true;
                RefreshStyleList(assDoc);
            }

            _chkAutoConvert.Enabled = true;
            _chkAutoConvert.Checked = false;

            _subtitleModifyWatcher.EnableRaisingEvents = false;
            _subtitleModifyWatcher.Path   = Path.GetDirectoryName(filePath);
            _subtitleModifyWatcher.Filter = Path.GetFileName(filePath);

            // Aegisub doesn't write straight to the .ass file, but instead creates a separate <name>_tmp_<number>.ass
            // and renames that to the original name.
            _subtitleRenameWatcher.EnableRaisingEvents = false;
            _subtitleRenameWatcher.Path   = Path.GetDirectoryName(filePath);
            _subtitleRenameWatcher.Filter = Path.GetFileNameWithoutExtension(filePath) + "_tmp_*" + Path.GetExtension(filePath);

            _btnConvert.Enabled = true;
        }
Exemplo n.º 3
0
        private void PopulateUi(string filePath, SubtitleDocument doc)
        {
            _txtInputFile.Text = filePath;

            AssDocument assDoc = doc as AssDocument;

            if (assDoc != null)
            {
                _grpStyleOptions.Enabled = true;

                _styles = assDoc.Styles.ToDictionary(s => s.Name);
                foreach (AssStyle style in assDoc.Styles)
                {
                    if (!_styleOptions.ContainsKey(style.Name))
                    {
                        _styleOptions.Add(style.Name, new AssStyleOptions(style));
                    }
                }

                _lstStyles.DataSource = assDoc.Styles.Select(s => _styleOptions[s.Name]).ToList();
                if (_lstStyles.Items.Count > 0)
                {
                    _lstStyles.SelectedIndex = 0;
                }
            }

            _chkAutoConvert.Enabled = true;
            _chkAutoConvert.Checked = false;
            _subtitleWatcher.Path   = Path.GetDirectoryName(filePath);
            _subtitleWatcher.Filter = Path.GetFileName(filePath);
            _btnConvert.Enabled     = true;
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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}");
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        public AssDocument(SubtitleDocument doc)
            : this(new MemoryStream(Resources.DefaultStyles), AssStyleOptionsList.LoadFromString(Resources.DefaultStyleOptions))
        {
            float sizeFactor = (float)doc.VideoDimensions.Height / VideoDimensions.Height;

            foreach (AssStyle style in _styles.Values)
            {
                style.LineHeight *= sizeFactor;
            }

            VideoDimensions = doc.VideoDimensions;

            Lines.Clear();
            Lines.AddRange(doc.Lines.Select(l => l as AssLine ?? new AssLine(l)));
        }
Exemplo n.º 9
0
        private void PopulateUi(string filePath, SubtitleDocument doc)
        {
            _txtInputFile.Text = filePath;

            AssDocument assDoc = doc as AssDocument;

            if (assDoc != null)
            {
                _grpStyleOptions.Enabled = true;

                _styles          = assDoc.Styles.ToDictionary(s => s.Name);
                _defaultFontSize = assDoc.DefaultFontSize;
                foreach (AssStyle style in assDoc.Styles)
                {
                    if (!_styleOptions.ContainsKey(style.Name))
                    {
                        _styleOptions.Add(style.Name, new AssStyleOptions(style));
                    }
                }

                _lstStyles.DataSource = assDoc.Styles.Select(s => _styleOptions[s.Name]).ToList();
                if (_lstStyles.Items.Count > 0)
                {
                    _lstStyles.SelectedIndex = 0;
                }
            }

            _chkAutoConvert.Enabled = true;
            _chkAutoConvert.Checked = false;

            _subtitleModifyWatcher.EnableRaisingEvents = false;
            _subtitleModifyWatcher.Path   = Path.GetDirectoryName(filePath);
            _subtitleModifyWatcher.Filter = Path.GetFileName(filePath);

            // Aegisub doesn't write straight to the .ass file, but instead creates a separate <name>_tmp_<number>.ass
            // and renames that to the original name.
            _subtitleRenameWatcher.EnableRaisingEvents = false;
            _subtitleRenameWatcher.Path   = Path.GetDirectoryName(filePath);
            _subtitleRenameWatcher.Filter = Path.GetFileNameWithoutExtension(filePath) + "_tmp_*" + Path.GetExtension(filePath);

            _btnConvert.Enabled = true;
        }
Exemplo n.º 10
0
 public VisualizingAssDocument(SubtitleDocument doc)
     : base(doc)
 {
     EmulateKaraokeForLinesWithBackgroundOrShadow();
 }