Scheduling Media Center recordings remotely with an iPhone
fmw | November 25, 2009This project came about when I noticed an App in the AppStore called “RadioTimes” by tvCompass. This has the facility to send an email to someone with the details of a program. There is an API for creating scheduled recordings in Media Center, using “c2r” (“click to record”) XML files and so it began. By choice I would write in C++ or Perl, but the Media Center API is .NET so I had to knuckle down and get to grips with C# – well, it’s been something I’ve been meaning to do for a while. And you can only really learn a language if you have a real need.
The task at hand is not as simple you’d think, largely because of subtle differences in program titles and channel names between the RadioTimes iPhone App and the EPG in Media Center.
This gets sent as an email message as follows
I thought you might be interested in...
"Ray Mears Northern Wilderness - 4/6 - In Arctic Footsteps"
BBC2 North West
Today 15/11 - 20:00
Ray Mears goes on an epic advent... http://d.click365.tv?2057045
Sent from Radio Times on your iPhone. For more information go to:
http://radiotimes.click365.tv
The EPG in Media Center knows this channel as simply “BBC TWO”, and this program as simply “Ray Mears Northern Wilderness”.
These two problems are dealt with in different ways.
The program title
Media Center allows us to request a schedule with “exact” or “contains” matching, where “contains” apparently really means “starts with”. If you schedule something in “contains” mode, you may get more than you expected because it will find programs at other times and on other channels – it appears that the inexact mode on title matching doesn’t pay strong attention to the time and channel. The documentation suggests that it’s possible to schedule a recording using just time and channel, but I could never get it to work.
So, we’re better using “exact” if we can. Based on examining a number of titles, it appears that the RadioTimes version is typically just appending series information on the end of a title which would match. The code removes whole words one at a time from the right and retries. If that fails, it does the same again but this time with “contains” specified. The fifth attempt below works.
Ray Mears Northern Wilderness – 4/6 – In Arctic Footsteps
Ray Mears Northern Wilderness – 4/6 – In Arctic
Ray Mears Northern Wilderness – 4/6 – In
Ray Mears Northern Wilderness – 4/6
Ray Mears Northern Wilderness
Ray Mears Northern
Ray Mears
This is harder and the current solution is to specify some aliases in the mc2.exe.conf file.
<!-- channel aliases --> <!-- key is the value Media Center uses, values are those to be found in emails --> <add key="BBC TWO" value="BBC2 North West|BBC2|BBC 2" /> <add key="BBC ONE" value="BBC1|BBC 1" /> <add key="ITV1" value="ITV|ITV1 Granada" /> <add key="Fiver" value="fiver" />
You can get the list of Media Center channel names by running mc2.exe with a –c argument.
Suppose you don’t have an iPhone (or don’t have it to hand)? No problem. You can use the normal www.radiotimes.co.uk website and paste the info into an email. You need to be careful to select the right data:
Then paste this into an email – preferably a text-only email but mc2.exe will make a valiant attempt to sledgehammer (really) its way through the markup and still work.
Ray Mears Northern Wilderness
Sunday 15 November
8:00pm - 9:00pm
BBC2
In a nutshell
- This definitely works with Media Center for Windows 7, probably works on Vista and hasn’t got a prayer of working on XP MC. And no, I don’t care about XP.
- Setup a POP3 mailbox somewhere dedicated to Media Center.
- Send emails to this address from RadioTimes on the iPhone.
- Put mc2.exe and mc2.exe.config in the same folder, and edit mc2.exe.config as necessary.
- Schedule mc2.exe to wake up every so often, read the emails and schedule recordings. If it processes any emails, will email you the current schedule and attach a log file.
Setting it up
You need mc2.exe and mc2.exe.config in the same directory. You need to edit the config file appropriately to setup the Pop* and Mail* values and any variations to the aliases.
<?xml version="1.0" ?> <configuration> <system.diagnostics> <switches> <clear/> <!-- These control how much/what appears in the output log --> <!-- POP is the incoming email, MC is the Media Center API stuff --> <!-- Parse is the parsing of the emails to find titles etc --> <!-- SMPT is any errors associated with sending the reply back --> <!-- 0=off, 1=Error 2=Warning 3=Info 4=Verbose --> <add name="POP" value ="1"/> <add name="MC" value ="3"/> <add name="Parse" value ="4"/> <add name="SMPT " value ="1"/> </switches> </system.diagnostics> <appSettings> <!-- inbound email --> <add key="PopServer" value="pop.example.com" /> <add key="PopPort" value="110" /> <add key="PopUser" value="mediacenter1234" /> <add key="PopPassword" value="password" /> <add key="PopSsl" value="false" /> <!-- outbound email --> <add key="MailFrom" value="mediacenter@yourdomain.com" /> <add key="MailTo" value="you@yourdomain.com" /> <add key="MailHost" value="mailhost.your.isp.co.uk" /> <!-- channel aliases --> <!-- key is the value Media Center uses, values are those to be found in emails --> <add key="BBC TWO" value="BBC2 North West|BBC2|BBC 2" /> <add key="BBC ONE" value="BBC1|BBC 1" /> <add key="ITV1" value="ITV|ITV1 Granada" /> <add key="Fiver" value="fiver" /> <!-- add more channels as necessary --> </appSettings> </configuration>
Testing it
Send a schedule request email to the POP3 account.
Then run mc2.exe from the command line with the –e (process emails) and –t (test mode) and –v (verbose) flags.
mc2.exe –e –t –v
Scheduling it
Setup a Scheduled Task to run it as often as suits you. Just specify –e alone and you’re done. I have mine set to wake up at a quarter to the hour for the 12 hours starting at 09:45.
Other things
You can also use mc2.exe to export all your current scheduled recordings to .c2r files. It will also make an attempt to export any series you have setup, but there’s no API for that so it has a go at parsing the hidden “backup” file created by Media Center. Series are only exported on MC for Windows 7.


Fantastic. I’ll give this a try tonight!
This sounds great. Is the source code available? I wouldn’t mind seeing how this is done. In theory it shouldn’t be too hard to use Twitter or something as the input source, as opposed to email.
Dan,
Sorry, I can’t make the source available now – but I’ll let you know if that situation changes. There’s no particular magic – the MC API is very small and (mostly!) correctly documented in MSDN. If you use mc2 to generate some .c2r files from existing scheduled recordings you’ll have a working starting point.
What’s the advantage of using twitter over email as the input source? It’s certainly convenient to have an email output.
Miles
[...] Email Recording Scheduling [...]