Get Content Metadata by Filename (REST)

Overview

The REST Web Service, located at /content_metadata_by_filename, can return the Content ID and other metadata for a file. The REST service results are limited to 1K in size. You can use the Content ID to delete the content via SOAP, for example.

Request URL

http://myserver:3000/content_metadata_by_filename/Sample.m2p

Parameters

Parameter Type Required Max Length Description
filename String Y 128 The filename of the content file on the server. In the above example URL, Sample.m2p is the filename.

The filename can be determined by looking at the details page for any content.

Code Examples

PHP

This example uses PHP 5’s handy simplexml_load_file() function. This function converts the XML return into an ordinary PHP object. Change myserver and Sample.m2p accordingly:

< ?php
$xml = simplexml_load_file(
  'http://myserver:3000/content_metadata_by_filename/Sample.m2p'
);
// print_r($xml); // Shows all properties of the object. Good for debugging.
 
// Access the XML elements like you normally access Properties of a PHP object:
echo($xml->name);
echo($xml->description);
echo($xml->{'actual-duration'}); // Enclose dashed Properties in {''}.
echo($xml->{'created-at'});
echo($xml->duration);
// ...and so on...
?>

We recommend that you wrap the simplexml_load_file() call above in some additional error handling to gracefully trap cases when connectivity to the server is offline. The PHP documentation has a good example of this.

Return

Success

A typical return is in this example:

< ?xml version="1.0" encoding="UTF-8" ?>
<content -file>
  <!-- The actual duration of the content in microseconds. -->
  <actual -duration type="integer">30130</actual>
  <contributor nil="true"/> <!-- No contributor is listed. -->
  <!-- The date this file was imported onto the server. -->
  <created -at type="datetime">2009-07-29T13:09:47-04:00</created>
  <!-- The content is scheduled for deletion on December 31, 2009 at 6:00 PM.
       If the deletion date were blank, this line would read nil. -->
  <delete -datetime type="datetime">2009-12-31T18:00:00-05:00 </delete>
  <!-- The description used in the EPG. -->
  <description>Sample Content for TelVue</description>
  <duration type="integer">31</duration> <!-- Content’s runtime in secs. -->
  <!-- The episode name.  If the Episode field were blank, this would read episode
       nil= true. -->
  <episode>Premiere</episode>
  <!-- If this content had an episode code it would be displayed here. -->
  <episode -code nil="true" />
  <!-- The content’s actual filename -->
  <filename>Sample.m2p</filename>
  <!-- This content’s ID is 152. Content IDs may range from 1 – 1000 or more. -->
  <id type="integer">152</id>
  <import_datetime type="datetime">2009-07-29T13:09:47-04:00</import_datetime>
  <!-- No location is listed. -->
  <location />
  <!-- The content’s name, as displayed at the top of the Edit Content and
       Show Content pages. -->
  <name>Sample</name>
  <!-- The program name.  If the Program field were blank, this would read
       program nil= true. -->
  <program>Sample Content</program>
  <!-- If this content had a program code it would be displayed here. -->
  <program -code nil="true" />
  <categories type="array">
    <category>
      <id type="integer">1</id> <!-- This content is in 1 category. -->
      <name>Community</name> <!-- This content is in the Community category. -->
    </category>
  </categories>
  <!-- This content is on the server, rather than being unattached (TBD). -->
  <attached>true</attached>
</content>

The program’s Content ID can be found in the “id” field in the response.

Failure

File not Found

< ?xml version="1.0" encoding="UTF-8"?>
<content>
  <error>Content with filename: Sample.m2p does not exist.</error>
</content>
Facebooktwittergoogle_pluslinkedin

4 Comments

  1. Kevin Reynen says:

    We’re having issues dealing with dash in content-file and actual-duration with PHP’s simplexml_load_file.

    According to php.net I should be able to reference it using {‘ ‘} like $xml->{‘actual-duration’}, but that’s not working for us.

    Can you post an example of accessing this with simplexml_load_file?

  2. rbrooks says:

    Kevin, we’ve updated the article with a code example using simplexml_load_file(). It tested successfully on our end.

    HTH. Thanks!

  3. We were having the same problem as Kevin in #1. Using the updated example I used the curly braces around elements with “dashes” as suggested by Kevin and now it works. Unless I missed something, it looks like you need the {”} to make it work. You might want to update your example to include an element with a dash:

    name);
    echo($xml->description);
    echo($xml->duration);
    echo($xml->{‘episode-code’}; //element with a dash needs curly braces
    // …and so on…
    ?>

  4. rbrooks says:

    Code example updated accordingly. Thanks, Daniel!

    I found a post about this in the PHP docs too.