处理后获取上传的视频状态

时间:2013-11-26 19:13:12

标签: php youtube-api google-api-php-client

我正在将视频上传到Youtube服务器端。

我了解状态的顺序:已上传 - >已处理 - >拒绝

我需要获得“拒绝”,这可能需要几秒钟到几分钟才能达到该状态,具体取决于视频文件的大小。

那么,我怎样才能延迟我的脚本,最好不要使用sleep(300),因为它不是很准确,似乎也在整个网站上睡觉了?

此脚本通过命令行在后台运行。

我剪切了脚本只是因为它是标准的可恢复上传脚本,可以在YouTube API v3网站上找到。

------------ SNIPPED -------------

# Create a video insert request
$insert_response = $youtube_service->videos->insert("status,snippet", $google_video, array('mediaUpload' => $media_file_upload));

$upload_status = FALSE;

# Read file and upload chunk by chunk
$handle = fopen($video_path, "rb");
while(!$upload_status && !feof($handle))
{
    $chunk = fread($handle, $chunk_size_bytes);
    $upload_status = $media_file_upload->nextChunk($insert_response, $chunk);
}

fclose($handle);

sleep(300);

$to='somebody@domain.com;'
$reply_to='server@domain.com';
$subject='Video status from domain.com';
$body='';

# Check the video status.
$video_id=random_YouTube_ID;
$check_status=$youtube_service->videos->listVideos($video_id, 'status', array('id' => $video_id));

# Check if the uploaded video status is rejected.
if($check_status['items'][0]['status']['uploadStatus']=="rejected")
{
    # Delete video file from server and database entry here.

    # Check if the rejection status was a duplicate.
    if($check_status['items'][0]['status']['rejectionReason']=="duplicate")
    {
        # Tell the user the video was a duplicate.
        $body.='Your video was rejected because it was a duplicate video';
    }
}
elseif($check_status['items'][0]['status']['uploadStatus']=="processed")
{
    # Tell the user the video was uploaded and processed but has no been accepted or rejected at this time.
    $body.='Your video has been uploaded to YouTube and processed but has not been accepted or rejected at this time';
}
elseif($check_status['items'][0]['status']['uploadStatus']=="uploaded")
{
    # Tell the user the video has been uploaded but not processed at this time.
    $body.='Your video has been uploaded to YouTube but has not been processed at this time.';
}

$mail=new Email();
$mail->sendEmail($subject, $to, $body, $reply_to);

有人有什么想法吗?

0 个答案:

没有答案
相关问题