As I mentioned in part 1, the WSH and some VBScript can be used to do more than move files around. Another use is in parsing the data in files. Parsing text files is very easy to do, but there are no built-in functions for accessing binary data. You will find, however, that others have made up for this shortcoming by implementing their own classes for manipulating binary files. See for example this site with example code. This example uses only VBScript code to create a Binary Object class, although better performance is achieved using dll's or COM objects. However, for the purposes of my demonstration, I used the CBin.vbs code in the tsbin.zip file at the above site. If you would like to run my demo script, you will have to download this zip archive and put the CBin.vbs file in the same folder as the script when you run it. My example pulls a list of wav files from a given folder and reads the binary file header and prints out the CartChunk Content Depot data. One could use this information for making scripted decisions about when to copy or move files or perhaps to push the future XML pad information in the file to a database for a "Now Playing" or other application. Currently, I don't have any other good uses for this script besides reporting what is there, but maybe it is useful to you. Maybe you could use it to email someone when a new file shows up. I would love to hear some more ideas. So, without further ado, here is my code for your perusal.
ConDepReader_v1_0_1.zip
UPDATE (2/22/2007): After reading some posts on Pubtech lamenting the lack of a spreadsheet of CutIDs, I updated the script (now v1.0.1) to output a report of files and CutIDs in CSV format for use in Excel or whatever.
Tuesday, February 20, 2007
Your WSH is my command, part 2
Posted by
John McMellen
at
3:38 PM
0
comments
Labels: contentdepot, scripting, vbscript, windows
Tuesday, January 30, 2007
Your WSH is my command, part 1
Several recent projects converged on a single need to automate basic server tasks, such as synchronizing folder contents, media conversion, etc. My first priority was to pull special "promo" audio files off of our Content Depot storage receiver and put them in another safe location so that our staff could edit them or otherwise use them in their spot production without having to navigate the critical parts of the storage receiver file system. The Windows Scripting Host (WSH) is ideally suited to automating such tasks. It is installed on every Windows XP and Server computer, is easily scripted and very powerful. In fact, there are several useful scripts included on your installation in the System32 directory, scripts that can automate printer management and filter event logs. I know what you're thinking, though. "VBS files are bad! They are viruses! That's why Norton blocks them!" They can be used by attackers, commonly in email, but are very useful for many Windows tasks. The Microsoft Technet journal carries a regular column called "Scripting Guys" that details many excellent scripting uses. You can also find VB scripts at the heart of the Samurize desktop widget software.
On to the fun stuff, though. As I mentioned, I wanted to get promos off of the storage receiver and into another folder on a different computer where they could be safely operated on. Using VBScript and the WSH, I created a list of files in the source location that match a regular expression, check that they are newer than files in the destination or don't exist in the destination location and copy them. This script then runs on an interval using "Scheduled Tasks" in Control Panel. I also found that using the command line Mplayer software, I could automate the conversion of these files to uncompressed wav files in the destination. Sweet! Lastly, I check to see if there are any files in the destination that aren't in the source location. These are deleted from the destination and walah! We are synchronized!
This type of scripting would also be useful for retrieving many other types of files from the storage receiver, items like images, rundowns, etc. that at this time are locked away because no one wants their staff monkeying around in that folder looking for these files. They could be automatically emailed or pushed to a web server or content management system for use. The WSH makes it easy to automate.
I am including a link to my script for your examination. In part 2, I will show you how I used a script to retrieve and report on the Cartchunk data stored in the wav files.
PromoSyncConv_v1_1.zip
MSDN Reference Material for WSH
Posted by
John McMellen
at
2:01 PM
0
comments
Labels: contentdepot, scripting, vbscript, windows