PHP: YouTube v3 API Captions Upload with Sync Flag -


for past couple weeks co workers , me have been working on trying captions on our clients youtube video's through v3 api. after week able captions upload fine but, youtube give message in ui "track content not processed" , doesn't display caption's upload. however, can download original format upload; know file uploaded successfully.

we able sync flag work tells youtube run through transcript , set timings video but, doesn't work. returns telling syncing when go ui video shows caption track name , give's message "track content not processed.". we've used hours had , we're working on our own time solve problem still no luck.

has ran problem before? if so, able work?

i post snippet of code below shows upload portion of our script.

# insert video caption. # create caption snippet video id, language, name , draft status. $captionsnippet = new google_service_youtube_captionsnippet(); $captionsnippet->setvideoid($videoid); $captionsnippet->setlanguage($captionlanguage); $captionsnippet->setname($captionname); $captionsnippet->setisdraft( true );  # create caption snippet. $caption = new google_service_youtube_caption(); $caption->setsnippet($captionsnippet);  // setting defer flag true tells client return request can called $client->setdefer(false);  // file content's of uploaded file $file = file_get_contents( $captionfile['tmp_name'] );  // create request api's captions.insert method create , upload caption. $insertrequest = $youtube->captions->insert("snippet", $caption, array(    'sync' => true,    'data' => $file,    'mimetype' => 'application/octet-stream',    'uploadtype' => 'multipart' )   );   echo '<pre>'; print_r( $insertrequest ); echo '</pre>';  // // read caption file , upload chunk chunk. $status = $insertrequest; fclose($handle);  // if want make other calls after file upload, set setdefer false $client->setdefer(false); 

thank you,
tyler steinhaus

have tried achieve want using functions google have posted themselves?

below taken https://developers.google.com/youtube/v3/code_samples/php

/**  * uploads caption track in draft status matches api request parameters.  * (captions.insert)  *  * @param google_service_youtube $youtube youtube service object.  * @param google_client $client google client.  * @param $videoid youtube video id of video api should  *  return caption tracks.  * @param $captionlanguage language of caption track.  * @param $captionname name of caption track.  * @param $captionfile caption track binary file.  * @param $htmlbody html body.  */ function uploadcaption(google_service_youtube $youtube, google_client $client, $videoid,     $captionfile, $captionname, $captionlanguage, &$htmlbody) {     # insert video caption.     # create caption snippet video id, language, name , draft status.     $captionsnippet = new google_service_youtube_captionsnippet();     $captionsnippet->setvideoid($videoid);     $captionsnippet->setlanguage($captionlanguage);     $captionsnippet->setname($captionname);      # create caption snippet.     $caption = new google_service_youtube_caption();     $caption->setsnippet($captionsnippet);      // specify size of each chunk of data, in bytes. set higher value     // reliable connection fewer chunks lead faster uploads. set lower     // value better recovery on less reliable connections.     $chunksizebytes = 1 * 1024 * 1024;      // setting defer flag true tells client return request can called     // ->execute(); instead of making api call immediately.     $client->setdefer(true);      // create request api's captions.insert method create , upload caption.     $insertrequest = $youtube->captions->insert("snippet", $caption);      // create mediafileupload object resumable uploads.     $media = new google_http_mediafileupload(         $client,         $insertrequest,         '*/*',         null,         true,         $chunksizebytes     );     $media->setfilesize(filesize($captionfile));       // read caption file , upload chunk chunk.     $status = false;     $handle = fopen($captionfile, "rb");     while (!$status && !feof($handle)) {       $chunk = fread($handle, $chunksizebytes);       $status = $media->nextchunk($chunk);     }      fclose($handle);      // if want make other calls after file upload, set setdefer false     $client->setdefer(false);      $htmlbody .= "<h2>inserted video caption track for</h2><ul>";     $captionsnippet = $status['snippet'];     $htmlbody .= sprintf('<li>%s(%s) in %s language, %s status.</li>',         $captionsnippet['name'], $status['id'], $captionsnippet['language'],         $captionsnippet['status']);     $htmlbody .= '</ul>'; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -