Skip to content

Commit

Permalink
docs(samples): add Video Stitcher slate and CDN key code samples and …
Browse files Browse the repository at this point in the history
…tests (#6)

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [X] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/nodejs-video-stitcher/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [X] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)

Fixes b:202972969
  • Loading branch information
irataxy authored Jun 10, 2022
1 parent b8c82d9 commit 49d6b22
Show file tree
Hide file tree
Showing 12 changed files with 788 additions and 1 deletion.
79 changes: 79 additions & 0 deletions media/video-stitcher/createCdnKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(
projectId,
location,
cdnKeyId,
hostname,
gCdnKeyname,
gCdnPrivateKey,
akamaiTokenKey = ''
) {
// [START video_stitcher_create_cdn_key]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// cdnKeyId = 'my-cdn-key';
// hostname = 'cdn.example.com';
// gCdnKeyname = 'gcdn-key';
// gCdnPrivateKey = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg==';
// akamaiTokenKey = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg==';

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function createCdnKey() {
// Construct request
const request = {
parent: stitcherClient.locationPath(projectId, location),
cdnKey: {
hostname: hostname,
},
cdnKeyId: cdnKeyId,
};

if (akamaiTokenKey !== '') {
request.cdnKey.akamaiCdnKey = {
tokenKey: akamaiTokenKey,
};
} else {
request.cdnKey.googleCdnKey = {
keyName: gCdnKeyname,
privateKey: gCdnPrivateKey,
};
}

const [cdnKey] = await stitcherClient.createCdnKey(request);
console.log(`CDN key: ${cdnKey.name}`);
}

createCdnKey();
// [END video_stitcher_create_cdn_key]
}

// node createCdnKey.js <projectId> <location> <cdnKeyId> <hostname> <gCdnKeyname> <gCdnPrivateKey> <akamaiTokenKey>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
56 changes: 56 additions & 0 deletions media/video-stitcher/createSlate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, slateId, slateUri) {
// [START video_stitcher_create_slate]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// slateId = 'my-slate';
// slateUri = 'https://my-slate-uri/test.mp4';

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function createSlate() {
// Construct request
const request = {
parent: stitcherClient.locationPath(projectId, location),
slate: {
uri: slateUri,
},
slateId: slateId,
};
const [slate] = await stitcherClient.createSlate(request);
console.log(`Slate: ${slate.name}`);
}

createSlate();
// [END video_stitcher_create_slate]
}

// node createSlate.js <projectId> <location> <slateId> <slateUri>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
51 changes: 51 additions & 0 deletions media/video-stitcher/deleteCdnKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, cdnKeyId) {
// [START video_stitcher_delete_cdn_key]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// cdnKeyId = 'my-cdn-key';

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function deleteCdnKey() {
// Construct request
const request = {
name: stitcherClient.cdnKeyPath(projectId, location, cdnKeyId),
};
await stitcherClient.deleteCdnKey(request);
console.log('Deleted CDN key');
}

deleteCdnKey();
// [END video_stitcher_delete_cdn_key]
}

// node deleteCdnKey.js <projectId> <location> <cdnKeyId>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
51 changes: 51 additions & 0 deletions media/video-stitcher/deleteSlate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, slateId) {
// [START video_stitcher_delete_slate]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// slateId = 'my-slate';

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function deleteSlate() {
// Construct request
const request = {
name: stitcherClient.slatePath(projectId, location, slateId),
};
await stitcherClient.deleteSlate(request);
console.log('Deleted slate');
}

deleteSlate();
// [END video_stitcher_delete_slate]
}

// node deleteSlate.js <projectId> <location> <slateId>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
51 changes: 51 additions & 0 deletions media/video-stitcher/getCdnKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, cdnKeyId) {
// [START video_stitcher_get_cdn_key]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// cdnKeyId = 'my-cdn-key';

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function getCdnKey() {
// Construct request
const request = {
name: stitcherClient.cdnKeyPath(projectId, location, cdnKeyId),
};
const [cdnKey] = await stitcherClient.getCdnKey(request);
console.log(`CDN key: ${cdnKey.name}`);
}

getCdnKey();
// [END video_stitcher_get_cdn_key]
}

// node getCdnKey.js <projectId> <location> <cdnKeyId>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
51 changes: 51 additions & 0 deletions media/video-stitcher/getSlate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, slateId) {
// [START video_stitcher_get_slate]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// slateId = 'my-slate';

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function getSlate() {
// Construct request
const request = {
name: stitcherClient.slatePath(projectId, location, slateId),
};
const [slate] = await stitcherClient.getSlate(request);
console.log(`Slate: ${slate.name}`);
}

getSlate();
// [END video_stitcher_get_slate]
}

// node getSlate.js <projectId> <location> <slateId>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
51 changes: 51 additions & 0 deletions media/video-stitcher/listCdnKeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location) {
// [START video_stitcher_list_cdn_keys]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function listCdnKeys() {
const iterable = await stitcherClient.listCdnKeysAsync({
parent: stitcherClient.locationPath(projectId, location),
});
console.info('CDN keys:');
for await (const response of iterable) {
console.log(response.name);
}
}

listCdnKeys();
// [END video_stitcher_list_cdn_keys]
}

// node listCdnKeys.js <projectId> <location>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
Loading

0 comments on commit 49d6b22

Please sign in to comment.