You are here

function scald_dailymotion_feed in Scald: Media Management made easy 6

Analyze a DailyMotion RSS feed, reformating the informations about its items in an easy to manipulate objects containing the informations we're interested in.

Parameters

$type: DailyMotion RSS feed type. Examples include 'user', 'video', 'tag'...

$id: The identifier, related to the type mentionned above. If you're requestion a user feed, then, its the username...

Return value

array Each array value is an object containing the following members:

  • id: the DailyMotion video id
  • author: the DailyMotion username of the user who uploaded the video
  • title: the video title
  • thumbnail: an associative array, containing the source ('src'), width and height of the video's thumbnail
  • pubDate: the publication date of the video
2 calls to scald_dailymotion_feed()
scald_dailymotion_cron in scald_dailymotion/scald_dailymotion.module
Implements hook_cron.
scald_dailymotion_search_form in scald_dailymotion/scald_dailymotion.pages.inc
Generates the search and search results form.

File

scald_dailymotion/scald_dailymotion.module, line 174
Defines a DailyMotion provider for Scald.

Code

function scald_dailymotion_feed($type, $id) {
  $url = DAILYMOTION_RSS . $type . '/' . urlencode($id);
  $xml = drupal_http_request($url);
  $items = array();
  if ($xml->code != 404 && !empty($xml->data)) {
    $dom = new DOMDocument();
    $dom
      ->loadXML($xml->data);
    if ($dom) {
      foreach ($dom
        ->getElementsByTagName('item') as $item) {
        $info = new stdClass();

        // Fetch from the feed
        // ... the video id
        $info->id = $item
          ->getElementsByTagNameNS(NS_DM, 'id')
          ->item(0)->nodeValue;

        // ... its title
        $title = $item
          ->getElementsByTagName('title')
          ->item(0);
        $info->title = $title->nodeValue;

        // ... and usefull informations about its thumbnails
        $thumb = $item
          ->getElementsByTagNameNS(NS_MEDIA, 'thumbnail')
          ->item(0);
        $info->thumbnail = array(
          'src' => $thumb
            ->getAttribute('url'),
          'width' => $thumb
            ->getAttribute('width'),
          'height' => $thumb
            ->getAttribute('height'),
        );

        // ... also get the author
        $info->author = $item
          ->getElementsByTagNameNS(NS_DM, 'author')
          ->item(0)->nodeValue;

        // ... and the publication date
        $info->pubDate = date('c', strtotime($item
          ->getElementsByTagName('pubDate')
          ->item(0)->nodeValue));
        $items[] = $info;
      }
    }
  }
  return $items;
}