惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
美团技术团队
N
Netflix TechBlog - Medium
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
The Cloudflare Blog
量子位
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - Freeman Shen

.NET面试题 (转)C#中的Abstract和Virtual函数区分,因我老弄不明白这个问题,所以转到这儿 Check Constraints限制本表的行数 数据库中主键和外键的设计原则 讲解SQL Injection一篇不错的文章,地址贴一下 Queue<(Of <(T>)>) 类,msdn上的一篇文章,便于查看 初次接触.Net下的信号量(semaphore) 某“高人”谈论股市,对现在行情的分析 左联,右联和内联的区别(图示) 用JavaScript如何获取客户端的操作系统是window2000还是window xp? 在IBatisNet框架,MasterPage,基类中配置Ajaxpro 自从离开哈尔滨后就没再管理这个blog了,以后还得继续努力啊 70-528试题2:仍然是有关xml的 题1的答案是(B),这是一个xml和schema的问题! 70-582试题1 由清明节想到的 今天心情不太好,没什么可写的 由DataBind()而发现的 生命之价
编辑电影字幕,编辑srt格式
Freeman Shen · 2008-06-05 · via 博客园 - Freeman Shen

最近看下载了些英文电影,想参照英文字幕来看,结果下载的英文字幕和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(62));
                        
int minute = Convert.ToInt32(line.Substring(32));
                        
int hour = Convert.ToInt32(line.Substring(02));
                        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(232));
                        
int minute2 = Convert.ToInt32(line.Substring(202));
                        
int hour2 = Convert.ToInt32(line.Substring(172));
                        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(
93+ " --> ");
                        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(
263));
                        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
        
{
        }

    }

}

页面的效果是这个样子的:

其中AddFileSecurityRemoveFileSecurity这两个方法是从微软msdn上抄的,是对要写的那个txt进行属性修改,但是我没调试成功!

在这儿推荐一个电影字幕下载的好网站:

http://www.shooter.cn/  射手网
感谢http://hi.baidu.com/xiaoyaogg/blog/item/9c2053af202d1bfafbed5021.html