Skip to content

Commit d07b175

Browse files
SurferJeffAtGooglebshaffer
authored andcommitted
Add a video quickstart and test. (GoogleCloudPlatform#380)
1 parent 925a325 commit d07b175

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ credentials.*
77
**/vendor/
88
**/build/
99
.php_cs.cache
10+
.vscode/

video/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "google/translate-sample",
33
"type": "project",
44
"require": {
5-
"google/cloud-storage": "^1.0",
65
"symfony/console": "^3.1",
76
"google/cloud-videointelligence": "^0.2.0",
87
"stanley-cheung/protobuf-php": "^0.6.0"

video/quickstart.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
/**
3+
* Copyright 2017 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
# Includes the autoloader for libraries installed with composer
19+
require __DIR__ . '/vendor/autoload.php';
20+
21+
# [START videointelligence_quickstart]
22+
# Import a convenient way to print the response.
23+
use DrSlump\Protobuf\Codec\TextFormat;
24+
# Imports the Google Cloud client library
25+
use Google\Cloud\VideoIntelligence\V1beta1\VideoIntelligenceServiceClient;
26+
use google\cloud\videointelligence\v1beta1\Feature;
27+
28+
# Instantiate a client.
29+
$video = new VideoIntelligenceServiceClient();
30+
31+
# Execute a request.
32+
$operation = $video->annotateVideo(
33+
'gs://demomaker/cat.mp4',
34+
[Feature::LABEL_DETECTION]
35+
);
36+
# Wait for the request to complete.
37+
$operation->pollUntilComplete();
38+
# Print the result.
39+
$format = new TextFormat();
40+
if ($operation->operationSucceeded()) {
41+
print $operation->getResult()->serialize($format);
42+
} else {
43+
print $operation->getError()->serialize($format);
44+
}
45+
# [END videointelligence_quickstart]

video/test/QuickStartTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
/**
3+
* Copyright 2017 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
class quickstartTest extends \PHPUnit_Framework_TestCase
19+
{
20+
public function setUp()
21+
{
22+
if (!$creds = getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
23+
$this->markTestSkipped('Set the GOOGLE_APPLICATION_CREDENTIALS ' .
24+
'environment variable');
25+
}
26+
}
27+
28+
public function testQuickstart()
29+
{
30+
// Invoke quickstart.php
31+
$results = include __DIR__ . '/../quickstart.php';
32+
$display = $this->getActualOutput();
33+
$this->assertContains('label_annotations', $display);
34+
}
35+
}

0 commit comments

Comments
 (0)