Get Channel Schedule as RSS (REST) – DEPRECATED

Overview

The Schedule RSS feed, linked from the dashboard, provides information about a channel’s upcoming schedule in RSS (XML) format. There are a few options about how much data to have this service return.

Request URL

There are three optional parameters that can be passed to the URL: Channel ID, Start Date, and End Date. URL format is:

http://myserver:3000/xml/rss2/[1-20][/?start=YYYYMMDD][&end=YYYYMMDD]

Substitute your server’s hostname, domain, or IP address for myserver. Optional parameters are show in brackets [].

Parameters

There are three optional parameters that can be passed to the URL:

Parameter Type Required Format Description
id Integer Range from 1 to 20 (depending on your server) Channel ID. If omitted, Channel 1 is used.
start DataTime YYYYMMDD Filter results to exclude everything prior to this date. If omitted, today’s date is used.
end DataTime YYYYMMDD Filter results to exclude everything after this date. If omitted, range ends one week from today.

Examples of valid URL parameters and what they return:

  • http://myserver:3000/xml/rss2 – Returns one week of data for Channel 1.
  • http://myserver:3000/xml/rss2/3/ – Returns one week of data for Channel 3.
  • http://myserver:3000/xml/rss2/?start=YYYYMMDD&end=YYYYMMDD – Returns data from date range specified for Channel 1.
  • http://myserver:3000/xml/rss2/3/?start=YYYYMMDD&end=YYYYMMDD – Returns data from date range specified for Channel 3.
  • http://myserver:3000/xml/rss2/3/?end=YYYYMMDD – Returns data from today to end date specified for Channel 3.
  • http://myserver:3000/xml/rss2/?start=YYYYMMDD – Returns data from today to one week from now for Channel 1.

Code Examples

Testing

Testing different feed parameters can be done with a web browser. The /xml/rss2 URL displays a basic RSS 2.0 feed of the channel schedule.

In your browser, go to http://myserver:3000/xml/rss2 (substitute the hostname of your server).

The information displayed depends on your browser, but typically includes program names, date and time of broadcast, and a description from the content metadata as in this example.

Screenshot: Schedule RSS

When requested with no parameters, as in the example above, the schedule shows 1 week of data.

You can request a specific date range using the optional start and end parameters. These take a date and time in the format of YYYYMMDDor YYYYMMDD, so 2 AM on Thursday, 12/10/2009 would be expressed as 20091210020000

If you specify a start value and no end, 1 week from the start value is shown. If you specify an end value with no start, from now to the end value is shown. Otherwise, the schedule from start to end is shown.

Parsing Date Field

The date is presented in RFC 2822 format, commonly used in email formatting. This format contains both relative time (that is, modified by time zone), and the timezone information (represented as +/- Greenwich Mean Time). The example below uses GMT -5, or Eastern Standard Time. The timezone information is placed at the end of the title string after a ” – ” separator.

In all programming languages, to get the desired date format:

  • Parse it from the title.
  • Use the language’s date-parsing features to get the RFC representation into a Date object.

PHP

function parsePsgRss($title_string) {
  $marker = ' - ';
  $last_occur = strrpos($title_string, $marker);
  $just_date_string = substr(
    $title_string,
    $last_occur + strlen($marker),
    strlen($title_string) - $last_occur - strlen($marker)
  );
  $timestamp = strtotime($just_date_string);
  $hr_date = date("g:i A", $timestamp);
 
  return $hr_date;
}
 
echo parsePsgRss("Sample Program Two - Tue, 13 Jan 2009 22:00:00 -0500");

In this PHP example, the combination of the substr() and strrpos() functions find the last occurrence of the string ” – ” in the full title, then split the string starting from that last occurrence to the end.

NOTE: The strrpos() function behaves differently in PHP 4 than in PHP 5. If you are running PHP 4, please see the PHP online documentation to determine the syntax for strrpos() in PHP 4.

Once you have the hr_date, PHP’s strtotime() function can read RFC2822 directly. That converts it to a Unix timestamp (seconds since the epoch). Other PHP date functions then take that timestamp directly. For example, Date takes a date format string to return just “10:00 PM” in this example string.

JavaScript

function getDateObject(title_string) {
  if (title_string.toUpperCase() != "NA") {
    return new Date(title_string.split(" - ")[1]);
  } else {
    return null;
  }
}
 
// Given a Javascript date object, return time in friendly format (8:00 AM).
function getHHMM(date) {
  // Accepts JS Date and returns time as H:MM AM/PM.
  hours = (date.getHours() > 12) ? (date.getHours() - 12) : date.getHours();
  minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  time = hours + ":" + minutes + " " + ((date.getHours() > 11) ? 'PM' : 'AM');
  return time;
}

The first function parses off the RFC time and turns it into a Javascript Date object, a built-in object in Javascript. The second function takes a date object, and returns just “10:00 PM”.

One way to call the two Javascript functions is:

getHHMM(getDateObject("Sample Program Two - Tue, 13 Jan 2009 22:00:00 -0500");

Returns

Success

Here is an example snippet from the RSS feed XML response:

< ?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:psg="http://192.168.1.160:3000/psg_namespace/">
  <channel>
    <title>PSG Channel 1</title>
    <description>PSG Broadcast Channel 1</description>
    <item>
      <title>Sample Program Two - Tue, 09 Dec 2008 12:00:00 -0500</title>
      <description>Another sample program, this one also with metadata.</description>
      <psg:thumbnail>http://192.168.1.160:3000/thumbnails/2.jpg
      <link>http://10.10.10.10</link>
      <duration>30.0</duration>
      <guid>test1.mpg</guid>
    </psg:thumbnail></item>
    <item>
      <title>Sample Program One - Tue, 09 Dec 2008 12:00:30 -0500</title>
      <description>A sample program with metadata.</description>
      <psg:thumbnail>http://192.168.1.160:3000/thumbnails/1.jpg
      <link>http://10.10.10.10</link>
      <duration>357.0</duration>
      <guid>Poor_Steve_final.mpg</guid>
    </psg:thumbnail></item>
    <item>
      <title>Sample Program Two - Tue, 09 Dec 2008 12:06:27 -0500</title>
      <description>Another sample program, this one also with metadata.</description>
      <psg:thumbnail>http://192.168.1.160:3000/thumbnails/2.jpg
      <psg:attribute name="Custom Attribute">Value</psg:attribute> 
      <psg:attribute name="Custom Attribute 2">Custom</psg:attribute>
      <link>http://10.10.10.10</link>
      <duration>30.0</duration>
      <guid>test1.mpg</guid>
    </psg:thumbnail></item>
    ...
  </channel>
</rss>

Several key fields of the content metadata are made available, including the Program field (as part of title), the description, the thumbnail, and duration. The title field also includes the scheduled play date and time, including the time zone. Thus, whatever code is ingesting this data should parse the title field, splitting the data into the respective fields of date and time (formatted as you desire) and Program.

A Note on What “Title” Contains in the RSS. For each content file, if you fill in the “Program” metadata field, then “Program” is the string presented as “title” in the RSS. Otherwise, the filename is presented in the RSS. The fields Program Code, Episode, and Episode Code have no impact here. The RSS title will be “Program” or, if Program is blank, the filename.

Failure

Invalid Channel

< ?xml version="1.0" encoding="UTF-8"?>
<errors>
  There were problems with your schedule query parameters.
  An invalid channel was specified.
</errors>

Invalid Start or End Date

< ?xml version="1.0" encoding="UTF-8"?>
<errors>There were problems with your schedule query parameters.</errors>

History

Deprecated
Princeton Server 3.6.5

Leave a Reply