Using batch file and VBS script to realize _asp foundation of website Video automatic recording

Source: Internet
Author: User
Tags ftp commands ftp login sprintf
Using batch files and VBS scripts to automate Web site video recording




Now television stations basically have their own portals, we can make full use of the advantages of the network to expand the impact of local television stations. In fact, the practice of hanging the daily ace of local TV shows on the website has become one of the necessary steps to build a television website. But then the problem is: The daily need for manual recording process, will bring great inconvenience to managers. On the basis of Windows timed task, the batch program and the script program are organically assembled, which can solve the problem effectively.



1: The establishment of the Code task

We will use a computer with a video capture card to complete the coding process. Although the pressure code is not the focus of this article, but it is necessary to explain. The main thing is to use helix producer PLUS9 to create a code parameter file, in fact it is just an XML file with a RPJF suffix (Figure 1). It should be noted that the audio input options have line input and microphone input two, which need to match the actual access line; In addition, you do not have to select the 2 Pass vedio encoding option, which will not have any effect except to show a warning; Because most of the current network access mode is dial-up and DSL, so only need to generate 56k and 384k rate of video files; Finally, the recording of the finished video file, the name of the best date to identify, such as: 20060301.rm.

<?xml version= "1.0" encoding= "UTF-8"?>
<job xmlns= "http://ns.real.com/tools/job.1.0.1" >
<enabletwopass type= "bool" >false</enableTwoPass>
<clipInfo>
<entry>
<name>Author</name>
<value type= "string" >ZSTV</value>
</entry>
<entry>
<name>Copyright</name>
<value type= "string" > (c) ZSTV2006 </value>
</entry>
<entry>
<name>Keywords</name>
<value type= "string" >ZSNews[2006-03-21]</value>
</entry>
<entry>
<name>Title</name>
<value type= "string" >ZSNews[2006-03-21]</value>
</entry>
</clipInfo>
<input>
<captureInput>
<audiodeviceid type= "string" >intel (r) Integrated audio</audiodeviceid>
....................................

We can create a batch file called Shixian.bat to call the parameter file shown above, the internal details are as follows:

Producer-j "D:\SHIXIAN\SHIXIAN.RPJF"-DAW-LC "E,i"

The default recording process monitors audio changes in real time and logs it to a file called Producer.log, but produces a lot of wanging, quickly making the log file huge and potentially causing an unexpected interruption of the recording process, so we can turn off audio monitoring using the-daw parameter , and then use LC "E,i" to indicate that only errors and information are logged. After doing so, the recording process is more stable.

As long as you add a daily task to execute the Shixian.bat file in the plan, we get an RM file with the same file attributes and name every day. A 20060321.rm file with the 2006-03-21 attribute will be generated here every day. It sounds awkward, and worse, it doesn't lessen the manager's job because he has to turn on the server every day to change his name. And even if it's fortunate to hire a diligent administrator (he doesn't mind doing this repetitive thing every day), he's still not able to change the properties of the date displayed in the file, as determined during the recording process. Unless.......



2: Set up the task of modifying the code parameter file

The principle is simple: Update the date-dependent XML fields in the code parameter file every day. In this example, the attributes and file names of the file display date. Here is the script code to update the date field:

Dim Regor

Set regor=new RegExp ' establishes a regular expression object

Regor.ignorecase=true ' ignores case

Regor.global=true ' search applies to entire string

regor.pattern= "^ ([0-9]{1}) $" to establish a search pattern for a single digit expression

Dim mytime

Mytime=date ' dates the system with the DATE function and assigns the value to the MyDate

Yy=year (mytime) ' Extracts the year from the system date

Mm=month (mytime) ' Extracts the month in the system date

Dd=day (mytime) ' Extracts date from the system date

If Regor.test (mm) Then ' detection month is a single digit (January to September)

Mm=regor.replace (mm, "0$1") ' If yes, add 0 before the month to make it two digits

End If

If Regor.test (dd) Then ' detection date is a single digit (day to 9th)

Dd=regor.replace (DD, "0$1") ' If yes, add 0 before the date to make it two digits

End If

Mytime=yy & "-" & mm & "-" & DD ' merged date to "Yy-mm-dd" form

Dest=yy & mm & DD ' merged date is "YYMMDD" form

Pattern1= "(. *[^0-9]) ([0-9]{4}\-[0-9]{2}\-[0-9]{2}) ([^0-9].*)"

' Set mode variable PATTERN1 to '%d%d%d%d-%d%d-%d%d '

Pattern2= "(. *[^0-9]) ([0-9]{8}) ([^0-9].*) ' Set mode variable PATTERN2 to 8 consecutive digits

Regor.pattern=pattern1 ' Establish search mode for PATTERN1

Dim tempstring

Set fso = CreateObject ("Scripting.FileSystemObject") ' establishes the System file object

Set f = fso. CreateTextFile ("D:\shixian\temp.txt", True) ' Creates a new text file named Temp

Set FR = fso. GetFile ("D:\SHIXIAN\SHIXIAN.RPJF") ' Gets the encoded parameter file SHIXIAN.RPJF

Set ts = Fr. OpenAsTextStream (1,-2) ' opens the parameter file in read-only text

Do Until TS. AtEndOfStream ' Set the loop until the parameter file is read

Tempstring=ts.readline ' reads parameter files in behavioral units

If Regor.test (tempstring) Then ' searches for row parameters for date fields

Tempstring=regor.replace (tempstring, "$" & MyTime & "$") ' if present, update

End If

REGOR.PATTERN=PATTERN2 ' Establish search mode for PATTERN2

If Regor.test (tempstring) Then ' searches for row parameters for date fields

Tempstring=regor.replace (tempstring, "$" & dest & "$") ' if present, update

End If

Regor.pattern=pattern1 ' re-establish search mode for PATTERN1

F.writeline (tempstring) ' writes the updated data to the Temp.txt file

Loop

Ts.close ' The following is to close and unregister individual objects

F.close

Set regor=nothing

Set ts=nothing

Set fr=nothing

Set f=nothing

Set fso=nothing

Explain why you should add 0 to the month and date of the single digit. An analogy is easier to say: if you do not add 0, then for a file named 2006111.rm, does it mean January 11, 2006 or November 1, 2006? Add 0 to become 20060111.rm on the clear, is the former.

The specific function of this script code is to import the data in the parameter file into a temporary text file, monitor the time-dependent XML fields and update them, and finally generate a temp.txt file. Then all we have to do is call the script with a batch file, delete the old parameter file, and finally rename the Temp.txt to the parameter file.

This is the code in the Update.bat batch file:

@echo off

D:\shixian\update.vbs

If exist "D:\shixian\shixian.rpjf" del "D:\SHIXIAN\SHIXIAN.RPJF"

If exist "D:\shixian\temp.txt" rename D:\shixian\temp.txt shixian.rpjf

As in the first section, you will add this update.bat batch file to your schedule and tasks so that you can start it regularly on a daily basis.



3: Establish an automatic transfer task

To ensure stability, the compression code server is usually separated from the Web server, which requires us to transfer the recorded video files to the Web server on a daily basis. FTP commands in batch files are perfect for this function.

The following is the code in the Transfer.bat batch:

@echo off

Ftp-s:media.txt

If exist "D:\shixian\shixian20060321.rm" Del d:\shixian\shixian20060321.rm

Considering the incredible price of SCSI hard disk, the hard disk space of the code server does not need to be too large, the last line of action is to delete the video files in the code server to save space. Media.txt is an FTP parameter file that records the FTP login server name, username, password, and related operations, in the following form:

Open/server name or IP address/

/user name/

/user Password/

Put/to transfer filename/

Quit

Obviously, the above sections of the code need to update the date literal expression. In the same way, we also need to use a similar update script, the specific code does not repeat.



4: Some ideas for improvement

1: Using Media Player can also achieve the function of the compression code.

2: In the update script, there are several lines of code used on the Declaration and logoff objects, which can be greatly simplified if you use Perl. Because Perl provides a series of action symbols to implement the functionality of regular expressions, Perl is actually born to handle text.
Open (RPJF, "&LT;C:/CODE/10161.RPJF") or Die ("can not open because of $!\n");
Open (TEMP, ">c:/code/temp.txt") or Die ("can not open because of $!\n");
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $ISDST) =localtime ();
$mday =sprintf ("%.2d", $mday);
$mon =sprintf ("%.2d", $mon + 1);
$year +=1900;
$timerF = "$year". $mon "." $mday ";
$timerS = "$year". -"." $mon "." -"." $mday ";
while (<RPJF>) {
Chomp ();
$_=~s/(. *) ([0-9]{8}) (. *)/$1$timerf$3/;
$_=~s/(. *) ([0-9]{4}\-[0-9]{2}\-[0-9]{2}) (. *)/$1$timers$3/;
Print TEMP "$_\n";
}
Close (RPJF);
Close (TEMP);
3: Using disk mapping makes it easier to transfer files, but security issues need to be considered.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.