最近看下载了些英文电影,想参照英文字幕来看,结果下载的英文字幕和rmvb格式电影,不能够同步,所以想解决这个问题
方法一:
编辑rmvb格式的电影,这个方法在baidu里边搜索"编辑rmvb格式",有很多解决方法,在此就不再赘述了!
方法二:
编辑英文字幕的时间来与电影相对应,在此我写了一个小程序来实现的,贴出来大家一起研究吧!
html代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditTxt.aspx.cs" Inherits="EditTxt" ValidateRequest="false" %>
<html>
<head runat="server">
<title>Edit Page</title>
<script language="javascript">
function GetPath(obj,flg)
{
if(flg=="1")
{
document.getElementById("<%=this.FileNameTextBox.ClientID %>").value=obj.value;
}
else if(flg=="2")
{
document.getElementById("<%=this.writeTextBox.ClientID %>").value=obj.value;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td width="150px">
Choose Txt file:
</td>
<td width="400px">
<asp:FileUpload ID="fileTxtPath" runat="server" onblur="GetPath(this,'1')" />
<asp:TextBox ID="FileNameTextBox" runat="server" Text="C:\kiss-fg-cd1.eng1.txt"></asp:TextBox></td>
</tr>
<tr>
<td>
Please Input Time:</td>
<td>
h:<asp:TextBox ID="txtHTime" runat="server" Width="40px" Text="0"></asp:TextBox>
m:<asp:TextBox ID="txtMTime" runat="server" Width="40px" Text="0"></asp:TextBox>
s:<asp:TextBox ID="txtSTime" runat="server" Width="40px" Text="0"></asp:TextBox></td>
</tr>
<tr>
<td>
Write In File:
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" onblur="GetPath(this,'2')" />
<asp:TextBox ID="writeTextBox" runat="server" Text="D:\newkiss.txt"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Button ID="btnAddTime" runat="server" Text="Add Time" OnClick="btnAddTime_Click" />
</td>
<td>
<asp:Label ID="MsgLabel" ForeColor="red" runat="server"></asp:Label>
</td>
</tr>
</table>
<table>
<tr>
<td>
<asp:TextBox ID="FileContentTextBox" runat="server" TextMode="MultiLine" Width="300"
Height="500px"></asp:TextBox></td>
<td>
<asp:TextBox ID="newContent" runat="server" TextMode="MultiLine" Width="300" Height="500px"></asp:TextBox></td>
</tr>
</table>
</form>
</body>
</html>
C#代码部分:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
using System.Security.Permissions;
using System.Security.AccessControl;
using System.Runtime.InteropServices;
public partial class EditTxt : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAddTime_Click(object sender, EventArgs e)
{
ReadControlFile();
}
// Adds an ACL entry on the specified file for the specified account.
public static void AddFileSecurity(string fileName, string account, FileSystemRights rights, AccessControlType controlType)
{
// Get a FileSecurity object that represents the current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(account, rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
}
// Removes an ACL entry on the specified file for the specified account.
public static void RemoveFileSecurity(string fileName, string account,FileSystemRights rights, AccessControlType controlType)
{
// Get a FileSecurity object that represents the current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Add the FileSystemAccessRule to the security settings.
fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
}
private void ReadControlFile()
{
int hError = txtHTime.Text.Length > 0 ? Convert.ToInt32(txtHTime.Text) : 0;
int mError = txtMTime.Text.Length > 0 ? Convert.ToInt32(txtMTime.Text) : 0;
int sError = txtSTime.Text.Length > 0 ? Convert.ToInt32(txtSTime.Text) : 0;
FileContentTextBox.Text = "";
newContent.Text = "";
StreamWriter sw;
try
{
//fileTxtPath.PostedFile.FileName
if (!File.Exists(FileNameTextBox.Text))
{
MsgLabel.Text = "This file is no Exist!";
return;
}
else
{
FileIOPermission fileIOPerm1;
fileIOPerm1 = new FileIOPermission(FileIOPermissionAccess.AllAccess, writeTextBox.Text);
fileIOPerm1.AllFiles = FileIOPermissionAccess.Write;
fileIOPerm1.AllLocalFiles = FileIOPermissionAccess.Write;
FileInfo aa = new FileInfo(writeTextBox.Text);
//FileSecurity security = aa.GetAccessControl();
// Add the access control entry to the file.
//AddFileSecurity(writeTextBox.Text, "bitoc.net/shen_hengjun@bitoc.net", FileSystemRights.Write, AccessControlType.Allow);
StreamReader sr = File.OpenText(FileNameTextBox.Text);
sw = File.CreateText(writeTextBox.Text);
String[] lines = File.ReadAllLines(FileNameTextBox.Text);
string content = sr.ReadToEnd();
String regex = "\\d\\d:\\d\\d:\\d\\d,\\d\\d\\d --> \\d\\d:\\d\\d:\\d\\d,\\d\\d\\d";
int timeError = hError * 3600 + mError * 60 + sError;
foreach (string line in lines)
{
MatchCollection mm = Regex.Matches(line, regex);
StringBuilder newLine = new StringBuilder(500);
if (mm.Count > 0)
{
int times;
int second = Convert.ToInt32(line.Substring(6, 2));
int minute = Convert.ToInt32(line.Substring(3, 2));
int hour = Convert.ToInt32(line.Substring(0, 2));
times = timeError + second + minute * 60 + hour * 3600;
String shour = "0" + (times / 3600);
String sminute = "0" + ((times % 3600) / 60);
String ssecond = "0" + (times % 60);
int second2 = Convert.ToInt32(line.Substring(23, 2));
int minute2 = Convert.ToInt32(line.Substring(20, 2));
int hour2 = Convert.ToInt32(line.Substring(17, 2));
times = timeError + second2 + minute2 * 60 + hour2 * 3600;
String shour2 = "0" + (times / 3600);
String sminute2 = "0" + ((times % 3600) / 60);
String ssecond2 = "0" + (times % 60);
newLine.Append(shour.Substring(shour.Length - 2) + ":");
newLine.Append(sminute.Substring(sminute.Length - 2) + ":");
newLine.Append(ssecond.Substring(ssecond.Length - 2) + ",");
newLine.Append(line.Substring(9, 3) + " --> ");
newLine.Append(shour2.Substring(shour2.Length - 2) + ":");
newLine.Append(sminute2.Substring(sminute2.Length - 2) + ":");
newLine.Append(ssecond2.Substring(ssecond2.Length - 2) + ",");
newLine.Append(line.Substring(26, 3));
sw.WriteLine(newLine.ToString());
}
else
{
sw.WriteLine(line);
}
}
sw.Close();
FileContentTextBox.Text = content;
sr.Close();
MsgLabel.Text = "Sucess!!";
StreamReader newsr = File.OpenText(writeTextBox.Text);
newContent.Text = newsr.ReadToEnd();
newsr.Close();
// Remove the access control entry from the file.
//RemoveFileSecurity(writeTextBox.Text, @"DomainName\AccountName", FileSystemRights.ReadData, AccessControlType.Allow);
}
}
catch (Exception ce)
{
MsgLabel.Text = "Fail for :" + ce.ToString();
//sr.Close();
}
finally
{
}
}
}页面的效果是这个样子的:

其中AddFileSecurity和RemoveFileSecurity这两个方法是从微软msdn上抄的,是对要写的那个txt进行属性修改,但是我没调试成功!
在这儿推荐一个电影字幕下载的好网站:http://www.shooter.cn/ 射手网
感谢http://hi.baidu.com/xiaoyaogg/blog/item/9c2053af202d1bfafbed5021.html


浙公网安备 33010602011771号