Exemplo n.º 1
0
        string IPlugin.DoAction(Form parentForm, string subtitle, double frameRate, string listViewLineSeparatorString, string subtitleFileName, string videoFileName, string rawText)
        {
            subtitle = subtitle.Trim();
            if (string.IsNullOrEmpty(subtitle))
            {
                MessageBox.Show("No subtitle loaded", parentForm.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(string.Empty);
            }

            var list = subtitle.Replace(Environment.NewLine, "\n").Split('\n').ToList();

            var sub = new Subtitle();
            var srt = new SubRip();

            srt.LoadSubtitle(sub, list, subtitleFileName);

            foreach (var paragraph in sub.Paragraphs)
            {
                string pre = string.Empty;
                if (paragraph.Text.StartsWith("{\\") && paragraph.Text.Contains("}"))
                {
                    var idx = paragraph.Text.IndexOf("}", 2, StringComparison.Ordinal) + 1;
                    pre            = paragraph.Text.Substring(0, idx);
                    paragraph.Text = paragraph.Text.Remove(0, idx);
                }
                var lines = paragraph.Text.SplitToLines();
                var sb    = new StringBuilder(paragraph.Text.Length);
                foreach (var line in lines)
                {
                    sb.AppendLine(ReverseStringUnicodeSafe(line));
                }
                paragraph.Text = pre + sb.ToString().TrimEnd().Replace(">i<", "<i>").Replace(">i/<", "</i>");
            }

            return(srt.ToText(sub, string.Empty));
        }
Exemplo n.º 2
0
 public string ToText()
 {
     return(_format.ToText(this, Path.GetFileNameWithoutExtension(FileName)));
 }
Exemplo n.º 3
0
 public string ToText() => _subFormat.ToText(this, Path.GetFileNameWithoutExtension(FileName));
Exemplo n.º 4
0
 public string ToText()
 {
     return(_format.ToText(this));
 }
Exemplo n.º 5
0
 public string ToText()
 {
     return(_format.ToText(_paragraphs));
 }
Exemplo n.º 6
0
        string IPlugin.DoAction(Form parentForm, string subtitle, double frameRate, string listViewLineSeparatorString, string subtitleFileName, string videoFileName, string rawText)
        {
            subtitle = subtitle.Trim();
            if (string.IsNullOrEmpty(subtitle))
            {
                MessageBox.Show("No subtitle loaded", parentForm.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(string.Empty);
            }
            // load subtitle text into object
            var list = new List <string>();

            foreach (var line in subtitle.SplitToLines())
            {
                list.Add(line);
            }
            var sub = new Subtitle();
            var srt = new SubRip();

            srt.LoadSubtitle(sub, list, subtitleFileName);

            // write subtitle to file
            var tempDir = GetTemporaryDirectory();

            File.WriteAllText(Path.Combine(tempDir, "Subtitle.srt"), srt.ToText(sub, "temp"));

            // write program to temp dir
            var asm = System.Reflection.Assembly.GetExecutingAssembly();

            foreach (var r in asm.GetManifestResourceNames())
            {
                if (r.EndsWith(".gz", StringComparison.Ordinal))
                {
                    WriteAndUnzipRes(asm, r, tempDir);
                }
            }

            // Start exe file
            var procInfo = new ProcessStartInfo();

            procInfo.FileName         = Path.Combine(tempDir, "AviFfmpegWriter.exe");
            procInfo.WorkingDirectory = tempDir;
            var p = Process.Start(procInfo);

            p.WaitForExit();

            // Clean up
            try
            {
                Directory.Delete(tempDir, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            /*
             * foreach (var r in asm.GetManifestResourceNames())
             * {
             *  if (r.EndsWith(".gz", StringComparison.Ordinal))
             *  {
             *      try
             *      {
             *          File.Delete(GetFileNameFromRessourceName(r));
             *      }
             *      catch (Exception ex)
             *      {
             *          MessageBox.Show(ex.Message);
             *          Process.Start(procInfo.WorkingDirectory);
             *      }
             *  }
             * }
             * try
             * {
             *  File.Delete(Path.Combine(tempDir, "Subtitle.srt"));
             *  Directory.Delete(tempDir);
             * }
             * catch (Exception ex)
             * {
             *  MessageBox.Show(ex.Message);
             *  Process.Start(procInfo.WorkingDirectory);
             * }*/
            return(string.Empty);
        }