This post demonstrates how you can access Recorded TV metadata programmatically from script and how to use it for your custom scenario. A link for downloading the sample scripts is provided at the bottom of this post.
by Daniel Zilcsak
Why would you need to access Recorded TV metadata?
Initially, my Media Center setup at home only included one Media Center machine. Not too long ago my wife gave me a Zune for by birthday and soon thereafter I started using Windows Home Server. Since my Recorded TV Library was now being used from more than one place, I felt the need to have my shows a bit more organized on the server. I started looking at ways to extract metadata, group TV series in folders and rename shows with the Episode Title and Date, instead of having all files piled up in my Recorded TV folder with a non-intuitive name (naming schema consisting off series name, station call sign, and a recoding date – you know what I mean). Since I could not find an existing way to accomplish that, I built a set of scripts to help me out.
Why script and not an app? Not everybody is a developer and Windows Scripting provided all the means to accomplish what I needed so why bother with a compiled app when scripts are so lightweight and easily customizable.
Scripts
RecordingAttributes.js shows how to enumerate files in a folder and load Recorded TV specific metadata. This is a good example that you can base your own implementation on. This sample will be described in more detail later on in the post.
Here’s the output after running this script against one of my Recorded TV folders:

PrintAllAttributes.js demonstrates how to discover attributes based on the Shell Property System.PropList.FullDetails. This is an attribute itself. Its value contains a list of other attributes that the Windows Shell uses to display full details about an item. For a Recorded TV show, this list includes: System.Title, System.RecordedTV.ProgramDescription, and so on. Run the sample against a folder that contains TV shows to discover them all.
Here’s the output after running this script against one of my Recorded TV folders:
ArrangeInFolders.js is a script that attempts to arrange recordings from a given folder into subfolders based on whether they’re part of a series or not. For each series, the script creates a subfolder [Series Name] and moves all associated episodes there, renaming them at the same time [Episode Name].extension (either wtv or dvr-ms). For non-series, the script renames the files in place using [Title].extension. Now, you can get more details about a recording by just looking at the file path.
Here’s a screenshot from my Recorded TV collection before running the script.
This is how I ran the script:
And once the script has renamed my recordings and arranged them into folders by series name, here’s how the folder structure looks like:
More about RecordingAttributes.js
Let’s take the simplest example and walk though the code a bit.
The statements above checks whether we’re running in wscript or not and if the user has passed at least one argument – the folder name. Because we’re writing a lot of output to the console, we want to make sure we’re executing in cscript (the Windows Scripting Host version that outputs to console). Refer to MSDN for more information about Windows Scripting.
If both of these requirements are met, the script calls the Run method passing the folder name as a parameter.
As seen above, Run()expects a folder path to enumerate Recorded TV files and retrieve their metadata. For clarity, this code does not check for errors nor test that the files in the folder are valid Recorded TV files.
I’m using the Windows Shell Automation Object to enumerate files in the given folder. For detailed information about these objects and their properties and methods see Scriptable Shell Objects in MSDN.
The important thing to mention is that for each file that comes out of the enumeration, I am creating a Recording object and passing the FolderItem as an argument to the constructor; then I am using properties on the newly created Recording object to print out metadata values.
This class is a convenient wrapper for Recorded TV file metadata. File attributes/properties are read from the file using the ExtendedProperty method of the ShellFolderItem object (an extension of the FolderItem object). There are more attributes which can be accessed through the ExtendedProperty method. Refer to Shell Properties and Recorded TV Properties in MSDN.
To discover other metadata you may be able to access, use the PrintAllAttributes.js sample provided with this post and examine the name/value pairs for properties you need to access.
***
Downloads
Download the scripts.zip file with all three sample scripts from the this location.
***
I hope you find this post useful and I welcome and appreciate your comments. Feel free to customize any of these scripts for your own scenario.
About the author
Daniel Zilcsak has been a developer on the Windows TV Development team since 2003, and is currently working on the Windows 7 release of Media Center. He lives in Sammamish, Washington with his wife. When he’s not working with TV technologies, he enjoys mountain biking, hiking and astronomy.
DISCLAIMER:
The opinions expressed here represent my own and not those of my employer.
The sample scripts are provided on an “as is” basis. You bear the risk of using them and Microsoft does not provide any support services. Microsoft gives no express warranties, guarantees or conditions to the fullest extent permitted by law. Microsoft disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, non infringement and warranties related to the sample scripts. Microsoft shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample scripts.