You are here

function scald_youtube_feed in Scald YouTube 7

Analyze a YouTube RSS feed to extract videos information.

Parameters

string $id: Identifier or string associated with the type. For example, user name, video id or tag.

Return value

array An array of object, each one containing an analyzed video.

1 call to scald_youtube_feed()
scald_youtube_video in ./scald_youtube.module
Analyze the youtube feed for a specific video.

File

./scald_youtube.module, line 455
Defines a YouTube provider for Scald.

Code

function scald_youtube_feed($id) {
  $item = scald_youtube_video_get_info($id);
  $api_key = variable_get('scald_youtube_api_key', '');
  if (empty($api_key)) {
    if (empty($item)) {
      return array();
    }
  }
  else {
    if (empty($item)) {
      $item = scald_youtube_create_default_info($id);
    }
    $url = SCALD_YOUTUBE_API . '/videos?id=' . $id . '&key=' . $api_key . '&part=snippet';
    $response = drupal_http_request($url);
    if ($response->code >= 200 && $response->code < 400 && !empty($response->data)) {
      $json = json_decode($response->data);
      $data = $json->items[0];
      $thumb_size = variable_get('scald_youtube_thumb_size', 'default');
      $item->thumbnail = array(
        'src' => $data->snippet->thumbnails->{$thumb_size}->url,
      );
      $item->title = $data->snippet->title;
      $item->author = $data->snippet->channelTitle;
    }
    else {
      return array();
    }
  }
  return $item;
}