![]() |
![]() |
|
برنامه نویسی |
Sub To Srt Converter
This is the source code of this program. It is made in C# with .net 2.0.
//form1.css
/* * Name: Sub to srt converter * Programmer: Paunoiu Alexandru Dumitru * Date: 5.11.2007 * Description: This program converts a .sub file (MicroDVD subtitle) in a .srt file (Subrip subtitle) * Version: 0.1 */
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO;
namespace subtosrt { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void btnConvert_Click(object sender, EventArgs e) { this.Converts(); }
private void Converts() { try { label3.Text = "Status: Working..."; StreamReader g = new StreamReader(textBox1.Text,Encoding.Default); string nfile=""; //process filename and return the path to write string[] v = textBox1.Text.Split('.'); for (int i = 0; i < v.Length - 1; i++) { nfile += v[i] + "."; } nfile += "srt"; //end StreamWriter f = new StreamWriter(nfile,false,Encoding.Default); string tmp; double x = Convert.ToDouble(textBox2.Text); int k=0; //read and write while (!g.EndOfStream) { tmp = g.ReadLine(); v = tmp.Split('{', '}'); k++; double i, j;
i = Convert.ToDouble(v[1]); j = Convert.ToDouble(v[3]);
tmp = tmp.Substring(v[1].Length + v[3].Length + 4); tmp = tmp.Replace("|", "\r\n"); if (tmp[0] == '{') { tmp = tmp.Replace("{Y:i}", ""); tmp = tmp + ""; } i = i / x; j = j / x; int h, m, s, mil; double part; part = Convert.ToDouble (i.ToString().Split('.')[0]); if (i - part > 0) mil = Convert.ToInt32((Convert.ToString(i - part).Split('.')[1] + "000").Substring(0, 3)); else mil = 0; s = (int)part % 60; m = (int)((part - s) % 3600)/60; h = (int)(part - s - m * 60) / 3600;
f.WriteLine(k.ToString()); f.Write( ((h.ToString().Length < 2) ? "0" + h.ToString() : h.ToString()) + ":" + ((m.ToString().Length < 2) ? "0" + m.ToString() : m.ToString()) + ":" + ((s.ToString().Length < 2) ? "0" + s.ToString() : s.ToString()) + "," + (mil.ToString() + "000").Substring(0,3) + " --> " ); part = Convert.ToDouble(j.ToString().Split('.')[0]); if (i - part > 0) mil = Convert.ToInt32((Convert.ToString(j - part).Split('.')[1] + "000").Substring(0, 3)); else mil = 0; s = (int)part % 60; m = (int)((part - s) % 3600) / 60; h = (int)(part - s - m * 60) / 3600; f.WriteLine( ((h.ToString().Length < 2) ? "0" + h.ToString() : h.ToString()) + ":" + ((m.ToString().Length < 2) ? "0" + m.ToString() : m.ToString()) + ":" + ((s.ToString().Length < 2) ? "0" + s.ToString() : s.ToString()) + "," + (mil.ToString() + "000").Substring(0, 3) ); f.WriteLine( tmp ); f.WriteLine(); } f.Close(); g.Close(); label3.Text = "Status: Done!"; } catch (Exception ex) { label3.Text = "Status: Error!"; } }
private void Exit_Click(object sender, EventArgs e) { this.Close(); }
private void btnOpenFileDialog_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = openFileDialog1.FileName; } } } }
//form1.designer.cs
namespace subtosrt { partial class Form1 { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null;
/// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }
#region Windows Form Designer generated code
/// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.btnConvert = new System.Windows.Forms.Button(); this.btnExit = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.label3 = new System.Windows.Forms.Label(); this.btnOpenFileDialog = new System.Windows.Forms.Button(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.ForeColor = System.Drawing.Color.Red; this.label1.Location = new System.Drawing.Point(9, 244); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(194, 13); this.label1.TabIndex = 0; this.label1.Text = "Copyright(c) Paunoiu Alexandru Dumitru"; // // btnConvert // this.btnConvert.Location = new System.Drawing.Point(12, 202); this.btnConvert.Name = "btnConvert"; this.btnConvert.Size = new System.Drawing.Size(75, 23); this.btnConvert.TabIndex = 1; this.btnConvert.Text = "Convert"; this.btnConvert.UseVisualStyleBackColor = true; this.btnConvert.Click += new System.EventHandler(this.btnConvert_Click); // // btnExit // this.btnExit.Location = new System.Drawing.Point(93, 202); this.btnExit.Name = "btnExit"; this.btnExit.Size = new System.Drawing.Size(75, 23); this.btnExit.TabIndex = 2; this.btnExit.Text = "Exit"; this.btnExit.UseVisualStyleBackColor = true; this.btnExit.Click += new System.EventHandler(this.Exit_Click); // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(9, 53); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(45, 13); this.label2.TabIndex = 3; this.label2.Text = "Sub file:"; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(72, 50); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(172, 20); this.textBox1.TabIndex = 4; // // openFileDialog1 // this.openFileDialog1.Filter = "Sub files(*.sub) | *.sub"; this.openFileDialog1.Title = "Open sub file"; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(69, 124); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(83, 13); this.label3.TabIndex = 5; this.label3.Text = "Status: Ready..."; // // btnOpenFileDialog // this.btnOpenFileDialog.Location = new System.Drawing.Point(249, 48); this.btnOpenFileDialog.Name = "btnOpenFileDialog"; this.btnOpenFileDialog.Size = new System.Drawing.Size(37, 23); this.btnOpenFileDialog.TabIndex = 6; this.btnOpenFileDialog.Text = "..."; this.btnOpenFileDialog.UseVisualStyleBackColor = true; this.btnOpenFileDialog.Click += new System.EventHandler(this.btnOpenFileDialog_Click); // // textBox2 // this.textBox2.Location = new System.Drawing.Point(72, 87); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(48, 20); this.textBox2.TabIndex = 7; this.textBox2.Text = "25.000"; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(9, 90); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(57, 13); this.label4.TabIndex = 8; this.label4.Text = "Framerate:"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.label4); this.Controls.Add(this.textBox2); this.Controls.Add(this.btnOpenFileDialog); this.Controls.Add(this.label3); this.Controls.Add(this.textBox1); this.Controls.Add(this.label2); this.Controls.Add(this.btnExit); this.Controls.Add(this.btnConvert); this.Controls.Add(this.label1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Sub to Srt Converter v 0.1"; this.ResumeLayout(false); this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1; private System.Windows.Forms.Button btnConvert; private System.Windows.Forms.Button btnExit; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button btnOpenFileDialog; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label4; } } |
+ نوشته شده در
یکشنبه دهم بهمن ۱۳۸۹ساعت 17:17 توسط ابراری |
|
صفحه نخست پست الکترونیک آرشیو عناوین مطالب وبلاگ |
درباره وبلاگ |
![]() |
پیوندهای روزانه |
جديدترين هاي هک انجمن دانشجویان مهندسی کامپیوتر لارستان دانشگاه آزاد اسلامی واحد لارستان رشته کامپیوتر یاس نقره ای برنامه نویسی آرشیو پیوندهای روزانه |
آرشیو موضوعی |
برق انیمیشن عمران اسمبلی زبان c زبان c# |
پیوندها |
مهندسی عمران لارستان انجمن معماران جوان لینک دونی لاریها برنامه نویسی موبایل |