Windows Media Center Team Blog

This blog features contributions from members of the Windows Media Center team at Microsoft.

Accessing Recorded TV metadata programmatically

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:

Recording Attributes Output

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:

PrintAllAttributes Output

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.

RecordedTV - Before

This is how I ran the script:

RecordedTV - Command

And once the script has renamed my recordings and arranged them into folders by series name, here’s how the folder structure looks like:

RecordedTV - After 1

RecordedTV - After 2

 

More about RecordingAttributes.js

Let’s take the simplest example and walk though the code a bit.

image

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.

image

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.

image

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.

Comments

 

great said:

fantastic scripts!! i've been looking for something like this, but i have one small request to make. In Greece the EPG title is in Greek therefore the title attribute is in greek and i want to extract the english title for the renaming and later metadata grabbing.

The bad thing is that the English title is on the program.description attibute in format.
so the program.descriptionattibute is like this: "Greek title: (English Title) : description follows"

Can somehow create a function that will parse the description for the "(" and ")" and capture the english title between the parenthesis ?? i've done it in VB6 old days but i have no idea how to start on here...

any help ???
July 14, 2009 10:03 AM
 

kxr said:

This is exactly what I've been looking for!  I don't suppose there is something similar to set values for title etc?
July 14, 2009 5:28 PM
 

great said:

ok found out about the parsing thing and modified the script to suit my needs.

I checked the other recording attributes from MSDN and i couldn't find an IsMovie attribute...is that possible ??
July 15, 2009 6:31 AM
 

DZilcsak_MSFT said:

kxr, unfortunately, the shell objects used with these scripts don't allow setting properties but if you're familiar with C++ and a bit of COM you can use IStreamBufferRecordingAttribute (http://msdn.microsoft.com/en-us/library/dd694964(VS.85).aspx) exposed by the RecordingAttributes object to enumerate, get or set properties for Recorded TV file.
July 17, 2009 10:51 AM
 

Hagrinas said:

This is great. It's nice and simple and will make it easy to do lots of stuff.  Is there an easy way for the program to get a thumbnail associated with the recording?

If it's one of those things I'm supposed to figure out by myself, forgive me. I'm new at this.

August 5, 2009 8:28 PM
 

Hagrinas said:

I just noticed that the data is not giving the channel number correctly. For example, it's showing 2 for 2.1, and it seems to be doing the same sort of thing for other channels.

I checked Windows explorer to see how it displays program info and it has the same error where channel number is displayed. I don't know if the data for those things are related, but hopefully there's something that will let me get the complete channel number.

August 5, 2009 8:38 PM
 

iank said:

Ahh. This lends itself to nuking the ten bazillion dupe recordings I get.

August 5, 2009 10:55 PM
 

Hagrinas said:

I did something simpler than arrangeinfolders.js.  I tried moving a WTV manually to a sub folder. MC no longer considered it when applying rules for file retention. In other words, if I tell MC to keep the latest 3 recordings, but then move 2 recordings to a sub folder, it will wait until there are three recordings in the directory in which it records before flagging for potential deletion. The ones in the subdirectory will remain until "I watch."  If I move files back from the subdirectory into the original directory, they do not end up back with their old status.

I know there is data elsewhere that keeps track of attributes for series', but I have no idea where to look for data related to this sort of thing.

One alternative is to use scripts to manage all of this entirely on my own. But even that would require a way for me to know the series defaults, and know if somebody changes the keep info manually within MC. Otherwise, I need to build a completely separate UI and reinvent the wheel.

Is there any sort of documentation that shows what is where, or any objects for reading and/or changing the db or parsing XML files or whatever is needed?

October 19, 2009 9:46 AM
 

ARobinso0502 said:

Thanks for the posting... I have been wanting to do something like this for some time but never had the time or wanted to start... I was able to modify your posting to get my local machines RECORDED TV up to my NAS and execute the ArrangeInFolder.js script...  Thanks again...

December 24, 2009 4:19 AM
 

wallaceff said:

Is there a way this app can look up season and episode name and insert SxxExx into the subtitle data?

June 15, 2010 3:35 PM

About PeteBrownMSFT

Pete Brown lives in the Midwest with a wife, two kids, three dogs and one cat. He runs Blue Monkey Communications and has been working with Windows Media Center for the past five years.


Terms of Service | Privacy Statement | Code of Conduct | About