From Manchester Way

Shared knowledge is a wonderful thing
  • rss
  • Home
  • About
  • Downloads
    • Extract Media Center Audio – wtv2mp3
    • Media Center Mail Client – mc2

Scheduling Media Center recordings remotely with an iPhone

fmw | November 25, 2009

This 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.

 

 rt

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”.

clip_image002

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:

clip_image002[4]

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

  1. 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.
  2. Setup a POP3 mailbox somewhere dedicated to Media Center.
  3. Send emails to this address from RadioTimes on the iPhone.
  4. Put mc2.exe and mc2.exe.config in the same folder, and edit mc2.exe.config as necessary.
  5. 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.

Categories
Media Center, Windows
Tags
iPhone, Media Center
Comments rss
Comments rss
Trackback
Trackback

« Converting Media Center recordings to .mp3 Perl on OpenSolaris »

4 Responses to “Scheduling Media Center recordings remotely with an iPhone”

  1. Steve Godfrey says:
    December 2, 2009 at 9:39 am

    Fantastic. I’ll give this a try tonight!

  2. Dan says:
    December 4, 2009 at 7:33 am

    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.

  3. fmw says:
    December 4, 2009 at 10:08 am

    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

  4. The Digital Media Zone » Blog Archive » Entertainment 2.0-Episode 55: Listener Q&A says:
    December 4, 2009 at 3:00 pm

    [...] Email Recording Scheduling [...]

Leave a Reply

Click here to cancel reply.

Search

Categories

  • Media Center
  • OpenSolaris
  • Windows
rss Comments rss