PowerShell 3.0 Grabber

Discussion about Schedules Direct grabber code and data formats.

PowerShell 3.0 Grabber

Postby johnhicks » Sun Jul 26, 2015 6:34 pm

Because I refuse to install any exe on my Windows system unless I am utterly sure of its providence, I wrote a PowerShell script that will pull the XMLTV data. This will require no installation on any Windows 8 machine (or later); users of earlier versions of Windows may need to download PowerShell 3.0 from Microsoft (http://www.microsoft.com/en-us/download/details.aspx?id=30002). To purpose of this script is to copy the XMLTV file from Schedules Direct to an XML file; it doesn't do anything more than this.

This should be very easy to implement and even schedule to happen automatically. Copy the following code to a simple text editor (like Windows' notepad.exe). Change the user name, password, and filename information (these values are in "<>" brackets in the script) to the values of your account and desired file location. Save the file as "GetSchedulesDirect.ps1" (note that in notepad you will need to change the default file type from "TXT" to "*.*" in order to prevent notepad from saving the file with a .txt extension instead of the necessary .ps1 extension):

Code: Select all
[DateTime]$startDate = Get-Date
$startDate = $startDate.ToUniversalTime().AddDays(-1)
[DateTime]$endDate = $startDate.AddDays(15)
[XML]$envelope = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:download xmlns:m="urn:TMSWebServices" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <startTime xsi:type="xsd:dateTime">' + $startDate.Year.ToString() + '-' + $startDate.Month.ToString() + '-' + $startDate.Day.ToString() + 'T00:00:00Z</startTime>
      <endTime xsi:type="xsd:dateTime">' + $endDate.Year.ToString() + '-' + $endDate.Month.ToString() + '-' + $endDate.Day.ToString() + 'T00:00:00Z</endTime>

Write-Host $envelope.OuterXml
$password = "<replace with your password>" | ConvertTo-SecureString -asPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "<replace with your user name>", $password

[Uri]$uri = 'http://dd.schedulesdirect.org/schedulesdirect/tvlistings/xtvdService'

Invoke-WebRequest $uri -Method post -ContentType "text/xml" -Body $envelope -OutFile "C:\<specify folder>\<output filename>.xml" -Credential $cred

To run this, you can open PowerShell and run the script by typing the (path and) filename. Note that you will need to set PowerShell's Execution Policy to "Remote Signed" if you haven't already. It's easy to run this from a standard command window or by creating a Windows Scheduled Task. In either case, you simply need to specify the command:
Code: Select all
powershell.exe -ExecutionPolicy RemoteSigned -File C:\<path to script>\GetSchedulesDirect.ps1

If you want to schedule the script to download the TV data regularly, you can use Windows' built-in Task Scheduler. Go to the Control Panel and find the "Schedule Tasks" link (under Administrative Tools). In the Task Scheduler, create a new Basic Task. Specify whatever schedule you like. When you get to the "Action" step of the Wizard, select "Start a Program". For the Program/Script name, enter "powershell.exe" (without quotes); for the Add Arguments, enter "-ExecutionPolicy RemoteSigned -File C:\<path to script>\GetSchedulesDirect.ps1" (also without quotes).

I hope this is helpful.

Posts: 1
Joined: Sat Jul 25, 2015 12:16 pm

Re: PowerShell 3.0 Grabber

Postby rmeden » Sun Jul 26, 2015 9:35 pm

That downloads data from SD, which is in Tribune's old XTVD format, not XMLTV.

You don't have to run XMLTV.EXE on Windows. You can install Perl and the necessary modules and run that.

Step by Step instructions to get XMLTV run run with Strawberry Perl is in the XMLTV wiki.

BTW, I can vouch for xmltv.exe, I build it! :)

SD Board Member
Posts: 1480
Joined: Tue Aug 14, 2007 2:31 pm
Location: Cedar Hill, TX

Return to Developers Corner

Who is online

Users browsing this forum: No registered users and 2 guests