0

I am uploading a video to Youtube server-side.

I understand the order of the statuses: uploaded -> processed -> rejected

I need to get the "rejected" which could take several seconds to several minutes to reach that status depending on the size of the video file.

So, how can I delay my script, preferably without using sleep(300) since it's not very accurate and also seems to be sleeping the ENTIRE website?

This script is running in the background via command line.

I snipped the script just because it's the standard resumable upload script which can be found on the YouTube API v3 website.

------------ 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);

Anyone have any ideas?

Draven
  • 1,467
  • 2
  • 19
  • 47
  • did you get your answer? – Bik May 20 '15 at 07:59
  • @Bik I ended up running a cron every hour or something like that (can't remember exactly how often it runs). – Draven May 20 '15 at 11:24
  • Thanks For Reply. I am trying for two days and can't find any solution for this...... Please check http://stackoverflow.com/questions/30344069/youtube-php-api-check-video-is-duplicate-or-not – Bik May 20 '15 at 11:28

0 Answers0