用于访问基于redirector.googlevideo.com的视频文件的API /调用?

时间:2013-10-10 20:07:17

标签: google-mirror-api google-glass

我的问题是,我是否应该使用YouTube API加载我从玻璃录制的视频并将其作为通知附件发送到我的服务器?或者,我应该使用mirror-api调用吗?

例如,我收到的视频的网址如下所示: http://redirector.googlevideo.com/videoplayback?id=875f7e1335214880&itag=22&source=picasa&cmo=sensitive_content%3Dyes&ip=0.0.0.0&ipbits=0&expire=1384018362&sparams=id,itag,source,ip,ipbits,expire&signature=AB8FC431423D6C86024A36F170ECF20C6F02223C.3FA395F9092F2EE5D6B14ACF49A4C18725A8846B&key=lh1

我确实查看了这个类似的答案:Displaying Video on Webpage from Google Glass,但不确定是否应该使用YouTube API。如果我应该,有人可以指出我应该调查哪些电话的正确方向吗?

谢谢!

快速更新以添加更多上下文,因此如果我录制10秒视频并通过自定义联系人卡分享到我的服务器,我会立即得到以下内容(这是我自己的调试输出,通过错误日志):

[error] Error Downloading Attachment - HTTP ResponseCode:404
[error] ContentUrl:         
[error] ContentType:        video/mp4
[error] id                  ps:5933350025312253298
[error] IsProcessing:       1

所以,这完全有意义,因为视频仍在处理中。 现在,如果我等待几分钟并与我的服务器重新分享视频,我会得到以下信息:

[error] Error Downloading Attachment - HTTP ResponseCode:302
[error] ContentUrl:         http://redirector.googlevideo.com/videoplayback?id=e0d5f76ca1fff29a&itag=22&source=picasa&cmo=sensitive_content%3Dyes&ip=0.0.0.0&ipbits=0&expire=1384058057&sparams=id,itag,source,ip,ipbits,expire&signature=CD41362EC3D3DDCD9EA3A63003B4C1A1F95D52C.BAE1608B827661FD47FC8D68DCBCE32F683A013D&key=lh1
[error] ContentType:        video/mp4
[error] id                  ps:5933350025312253298
[error] IsProcessing:       0

相比之下,图像附件始终有效,看起来像这样:

[error] Downloading Attachment - HTTP ResponseCode:200
[error] ContentUrl:         https://www.googleapis.com/mirror/v1/timeline/7f13b01d-ee26-4b02-b6c3-7f885a452fc9/attachments/ps:5933353306000857698?alt=media
[error] ContentType:        image/jpeg
[error] id                  ps:5933353306000857698
[error] IsProcessing:       0

这就是问题所在。我无法找到一种方法来访问视频数据,部分是因为它是一个重定向(似乎??)需要某种类型的auth交换来处理,我无法弄清楚使用哪个API来帮助我这样做

所以,回到我的问题......是否有一种建议的方式让我处理重定向器URL以将视频下载到我的服务器,或者,甚至只是保持它托管在哪里,但包裹一个youtube'围绕它的esque玩家就像G +备份云播放器一样?我的意图是让视频公开可见。

谢谢! 更新:这是我正在使用的代码的要点。我刚开始使用Glass Team提供的示例PHP快速入门:

https://gist.github.com/ozfarman/6953473

2 个答案:

答案 0 :(得分:2)

您应该使用Google API客户端下载附件网址,该网址将为您处理授权和重定向。无论您编写哪种语言,请参阅Timeline.attachments.get文档中提供的示例。

答案 1 :(得分:2)

使用Googles Mirror Api Client检查与时间轴项目关联的附件的状态。视频长度可能需要几分钟才能播放。奇怪的是,如果你从他们的重定向跟随302,你最终会进入一个Picasa域,考虑到它的视频,这有点奇怪,但确实表明谷歌正在对你的视频进行一些预处理,然后交付它。

此代码是我编写的一个排队过程的一部分,用于处理与Google检查时间轴项目的处理状态。来自Google的回调被插入到我的队列服务器中并被工作人员接收,该工作人员每X秒主动检查一次状态以确定媒体是否准备好,如果它超过了多个循环,它只是重新排列另一个工作要接收的工作工人。主动检查而不是在回调中返回非200代码是非常有益的,因为Google会对其api调用进行指数退避,因此对于需要一段时间才能进入正确状态的视频,您最终可能会在回调之间等待很长时间来自谷歌。

公共函数运行($ data){         $ timeline_item_id = $ data ['timeline_item_id'];

    try{
        $glassUtils = new Google_Glass_Utilities();
        $mirrorClient = new Google_Glass_MirrorClient();
        $client = $mirrorClient->get_google_api_client();
        $client->setAccessToken($data['credentials']);
        $mirror_service = new Google_MirrorService($client);
        echo "\nTIMELINE ITEM ID: " . $data['timeline_item_id'] . "\n";
        $timeline_item = $mirror_service->timeline->get($timeline_item_id);
        $caption = $timeline_item->getText();
    }catch (Exception $e){
        echo "ERROR";
        echo $e->getMessage();
        return true;
    }

    //Blocker that waits for the item to be in the active state
    //Should be faster than waiting for extra callbacks from Google
    try{
        $checkCount = 1;
        while(true){
            $blnProceed = true;

            echo "Check " . $checkCount . " of " . $this->maxSearchChecks . " for attachments on timeline item " . $timeline_item_id . "\n";

            $attachments = $mirror_service->timeline_attachments->listTimelineAttachments($timeline_item_id);
            foreach ($attachments->getItems() as $attachment) {
                echo "Attachment content type: " . $attachment->getContentType() . "\n";
                //echo "Attachment content URL: " . $attachment->getContentUrl();
                if($attachment->getIsProcessingContent() && $attachment->getContentType() == 'video/mp4'){
                    $blnProceed = false;
                }
            }

            if(!$blnProceed){
                echo "Attachments were not ready\n";
                if($checkCount == $this->maxSearchChecks){
                    echo "Job hit max checks, requeueing\n";
                    $task = new BackgroundTask();
                    $task->addTask('GlassVideoImport', $saveData);
                    $task->submit();
                    GearmanPearManager::$LOG[] = "Success";
                    return true;
                }else{
                    $checkCount += 1;
                    echo "Sleeping for " . $this->sleepSecs . " seconds before recheck\n";
                    sleep($this->sleepSecs);
                }
            }else{
                echo "GOT THE TIMELINE ITEM AND ATTACHMENT IS READY\n\n\n\n";
                //Continue
                break;
            }
        }
    }catch (Exception $e){
        echo "ERROR";
        echo $e->getMessage();
        return true;
    }

    //Got here so now go get the attachment
    try{
        $attachment = $mirror_service->timeline_attachments->get($data['timeline_item_id'], $data['timeline_attachment_id']);
        $attachmentBinary = $this->downloadAttachment($data['timeline_item_id'], $attachment);

        //Do something with the binary of the attachment


        GearmanPearManager::$LOG[] = "Success";
        return true;
    }
    catch( Exception $e ) {
        echo $e->getMessage() . "\n";
        @unlink($fileRes['localFile']);
        GearmanPearManager::$LOG[] = "Failure";
        return true;
    }
}

private function downloadAttachment($itemId, $attachment) {
    $request = new Google_HttpRequest(
    $attachment->getContentUrl(), 'GET', null, null);
    $httpRequest = Google_Client::$io->authenticatedRequest($request);
    if ($httpRequest->getResponseHttpCode() == 200) {
        return $httpRequest->getResponseBody();
    } else {
        return null;
    }
}