|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright 2024 Google LLC |
| 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 | +"""Google Cloud Video Stitcher sample for creating a VOD config. VOD |
| 18 | +configs are used to configure VOD sessions. |
| 19 | +Example usage: |
| 20 | + python create_vod_config.py --project_id <project-id> --location <location> \ |
| 21 | + --vod_config_id <vod-config-id> --vod_uri <uri> --ad_tag_uri <uri> |
| 22 | +""" |
| 23 | + |
| 24 | +# [START videostitcher_create_vod_config] |
| 25 | + |
| 26 | +import argparse |
| 27 | + |
| 28 | +from google.cloud.video import stitcher_v1 |
| 29 | +from google.cloud.video.stitcher_v1.services.video_stitcher_service import ( |
| 30 | + VideoStitcherServiceClient, |
| 31 | +) |
| 32 | + |
| 33 | + |
| 34 | +def create_vod_config( |
| 35 | + project_id: str, |
| 36 | + location: str, |
| 37 | + vod_config_id: str, |
| 38 | + vod_uri: str, |
| 39 | + ad_tag_uri: str, |
| 40 | +) -> stitcher_v1.types.VodConfig: |
| 41 | + """Creates a VOD config. |
| 42 | + Args: |
| 43 | + project_id: The GCP project ID. |
| 44 | + location: The location in which to create the VOD config. |
| 45 | + vod_config_id: The user-defined VOD config ID. |
| 46 | + vod_uri: URI of the VOD to stitch; this URI must reference either an |
| 47 | + MPEG-DASH manifest (.mpd) file or an M3U playlist manifest |
| 48 | + (.m3u8) file. |
| 49 | + ad_tag_uri: Uri of the ad tag. |
| 50 | +
|
| 51 | + Returns: |
| 52 | + The VOD config resource. |
| 53 | + """ |
| 54 | + |
| 55 | + client = VideoStitcherServiceClient() |
| 56 | + |
| 57 | + parent = f"projects/{project_id}/locations/{location}" |
| 58 | + |
| 59 | + vod_config = stitcher_v1.types.VodConfig( |
| 60 | + source_uri=vod_uri, |
| 61 | + ad_tag_uri=ad_tag_uri, |
| 62 | + ) |
| 63 | + |
| 64 | + operation = client.create_vod_config( |
| 65 | + parent=parent, vod_config_id=vod_config_id, vod_config=vod_config |
| 66 | + ) |
| 67 | + response = operation.result() |
| 68 | + print(f"VOD config: {response.name}") |
| 69 | + return response |
| 70 | + |
| 71 | + |
| 72 | +# [END videostitcher_create_vod_config] |
| 73 | + |
| 74 | +if __name__ == "__main__": |
| 75 | + parser = argparse.ArgumentParser() |
| 76 | + parser.add_argument("--project_id", help="Your Cloud project ID.", required=True) |
| 77 | + parser.add_argument( |
| 78 | + "--location", |
| 79 | + help="The location in which to create the VOD config.", |
| 80 | + default="us-central1", |
| 81 | + ) |
| 82 | + parser.add_argument( |
| 83 | + "--vod_config_id", |
| 84 | + help="The user-defined VOD config ID.", |
| 85 | + required=True, |
| 86 | + ) |
| 87 | + parser.add_argument( |
| 88 | + "--vod_uri", |
| 89 | + help="The URI of the VOD stream to stitch (.mpd or .m3u8 file) in double quotes.", |
| 90 | + required=True, |
| 91 | + ) |
| 92 | + parser.add_argument( |
| 93 | + "--ad_tag_uri", |
| 94 | + help="URI of the ad tag in double quotes.", |
| 95 | + required=True, |
| 96 | + ) |
| 97 | + args = parser.parse_args() |
| 98 | + create_vod_config( |
| 99 | + args.project_id, |
| 100 | + args.location, |
| 101 | + args.vod_config_id, |
| 102 | + args.vod_uri, |
| 103 | + args.ad_tag_uri, |
| 104 | + ) |
0 commit comments