You are here

function _media_youtube_check_upload in Media: YouTube 6

Check the upload status of a video.

Parameters

string $video_id: The video to check.

string $youtube_username: The youtube username owning the video to check.

string $youtube_password: The password of the youtube user.

Return value

array An associative array, keyed as follows: 'status' => The status returned from YouTube. 'message' => A message describing the video's status.

1 call to _media_youtube_check_upload()
media_youtube_check_upload in ./media_youtube.module
Check the upload status of a video

File

includes/media_youtube.api.inc, line 22
Miscellaneous API function calls for Media: YouTube.

Code

function _media_youtube_check_upload($video_id, $youtube_username = NULL, $youtube_password = NULL) {
  _media_youtube_set_include_path();
  $path = media_youtube_zend_path();
  Zend_Loader::loadClass('Zend_Gdata_YouTube', $path);
  Zend_Loader::loadClass('Zend_Gdata_App_Exception', $path);
  Zend_Loader::loadClass('Zend_Gdata_App_HttpException', $path);
  Zend_Loader::loadClass('Zend_Gdata_App_Extension_Control', $path);
  Zend_Loader::loadClass('Zend_Gdata_YouTube_Extension_State', $path);
  Zend_Loader::loadClass('Zend_Gdata_AuthSub', $path);
  Zend_Loader::loadClass('Zend_Gdata_ClientLogin', $path);
  Zend_Loader::loadClass('Zend_Uri_Http', $path);
  $httpClient = _media_youtube_get_auth_sub_http_client($youtube_username, $youtube_password);
  $youTubeService = new Zend_Gdata_YouTube($httpClient);
  try {
    $feed = $youTubeService
      ->getuserUploads('default');
  } catch (Exception $e) {
    $message = 'Unable to retrieve upload feed: @error.';
    $variables = array(
      '@error' => $e
        ->getMessage(),
    );
    watchdog('media_youtube', $message, $variables, WATCHDOG_ERROR);
    return array(
      'status' => t('error'),
      'message' => t($message, $variables),
    );
  }
  $status = 'unknown';
  $message = 'No further status information available yet.';
  if (is_array($feed)) {
    foreach ($feed as $videoEntry) {
      if ($videoEntry
        ->getVideoId() == $video_id) {

        // Check if video is in draft status.
        try {
          $control = $videoEntry
            ->getControl();
        } catch (Zend_Gdata_App_Exception $e) {
          $message = 'Unable to retrieve control element: @error.';
          $variables = array(
            '@error' => $e
              ->getMessage(),
          );
          watchdog('media_youtube', $message, $variables, WATCHDOG_ERROR);
          return array(
            'status' => t('error'),
            'message' => t($message, $variables),
          );
        } catch (Zend_Gdata_App_HttpException $e) {
          $message = 'Unable to retrieve control element: @error.';
          $variables = array(
            '@error' => $e
              ->getMessage(),
          );
          watchdog('media_youtube', $message, $variables, WATCHDOG_ERROR);
          return array(
            'status' => t('error'),
            'message' => t($message, $variables),
          );
        }
        if ($control instanceof Zend_Gdata_App_Extension_Control) {
          if ($control
            ->getDraft() != null && $control
            ->getDraft()
            ->getText() == 'yes') {
            $state = $videoEntry
              ->getVideoState();
            if ($state instanceof Zend_Gdata_YouTube_Extension_State) {
              $status = $state
                ->getName();
              $message = $state
                ->getText();
            }
          }
        }
      }
    }
  }
  return array(
    'status' => t($status),
    'message' => t($message),
  );
}