You are here

function media_youtube_check_status in Media: YouTube 6

Check the availability of a video.

6 calls to media_youtube_check_status()
media_youtube_cron in ./media_youtube.module
Implementation of hook_cron().
media_youtube_emfield_field_extra in ./media_youtube.module
Implement hook_emfield_field_extra().
media_youtube_emfield_status in ./media_youtube.module
Implementation of hook_emfield_status().
media_youtube_video_full_status in ./media_youtube.module
_media_youtube_save_status_data in includes/media_youtube.api.inc

... See full list

File

./media_youtube.module, line 379
Embedded Video Field provider file for YouTube.com.

Code

function media_youtube_check_status($video_id, $reset = FALSE) {
  static $status;
  if ($reset || !isset($status)) {
    $status = array();
  }
  if (!isset($status[$video_id])) {
    if (($cache = cache_get('media_youtube:status:' . $video_id, 'cache_media_youtube_status')) && !$reset) {
      $status[$video_id] = $cache->data;
    }
    else {
      if ($path = media_youtube_zend_path()) {
        Zend_Loader::loadClass('Zend_Gdata_YouTube', $path);
        Zend_Loader::loadClass('Zend_Gdata_App_HttpException', $path);
        Zend_Loader::loadClass('Zend_Gdata_AuthSub', $path);
        Zend_Loader::loadClass('Zend_Gdata_ClientLogin', $path);
        Zend_Loader::loadClass('Zend_Uri_Http', $path);
        $yt = new Zend_Gdata_YouTube();
        try {
          $videoEntry = $yt
            ->getVideoEntry($video_id);
          $status[$video_id] = EMFIELD_STATUS_AVAILABLE;
        } catch (Exception $e) {
          $status[$video_id] = EMFIELD_STATUS_UNAVAILABLE;
          $message = 'Video unavailable at !link: @error.';
          $variables = array(
            '@error' => $e
              ->getMessage(),
            '!link' => l(media_youtube_video_url($video_id), media_youtube_video_url($video_id)),
          );
          watchdog('media_youtube', $message, $variables, WATCHDOG_ERROR);
        }
      }
      else {

        // We don't have the Zend library, so there's no way to know for certain.
        $status[$video_id] = EMFIELD_STATUS_AVAILABLE;
      }
      cache_set('media_youtube:status:' . $video_id, $status[$video_id], 'cache_media_youtube_status', CACHE_TEMPORARY);
    }
  }
  return $status[$video_id];
}