Skip to content

Commit 8b00f38

Browse files
authored
docs(samples): add samples for VOD config (GoogleCloudPlatform#12018)
1 parent 45d38ad commit 8b00f38

10 files changed

Lines changed: 547 additions & 18 deletions
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
)

video/stitcher/create_vod_session.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
session in which to insert ads.
1919
Example usage:
2020
python create_vod_session.py --project_id <project-id> \
21-
--location <location> --source_uri <uri> --ad_tag_uri <uri>
21+
--location <location> --vod_config_id <vod-config-id>
2222
"""
2323

2424
# [START videostitcher_create_vod_session]
@@ -32,16 +32,15 @@
3232

3333

3434
def create_vod_session(
35-
project_id: str, location: str, source_uri: str, ad_tag_uri: str
35+
project_id: str, location: str, vod_config_id: str
3636
) -> stitcher_v1.types.VodSession:
3737
"""Creates a VOD session. VOD sessions are ephemeral resources that expire
3838
after a few hours.
3939
Args:
4040
project_id: The GCP project ID.
4141
location: The location in which to create the session.
42-
source_uri: Uri of the media to stitch; this URI must reference either an MPEG-DASH
43-
manifest (.mpd) file or an M3U playlist manifest (.m3u8) file.
44-
ad_tag_uri: Uri of the ad tag.
42+
vod_config_id: The user-defined VOD config ID to use to create the
43+
session.
4544
4645
Returns:
4746
The VOD session resource.
@@ -50,9 +49,12 @@ def create_vod_session(
5049
client = VideoStitcherServiceClient()
5150

5251
parent = f"projects/{project_id}/locations/{location}"
52+
vod_config_name = (
53+
f"projects/{project_id}/locations/{location}/vodConfigs/{vod_config_id}"
54+
)
5355

5456
vod_session = stitcher_v1.types.VodSession(
55-
source_uri=source_uri, ad_tag_uri=ad_tag_uri, ad_tracking="SERVER"
57+
vod_config=vod_config_name, ad_tracking="SERVER"
5658
)
5759

5860
response = client.create_vod_session(parent=parent, vod_session=vod_session)
@@ -71,19 +73,13 @@ def create_vod_session(
7173
default="us-central1",
7274
)
7375
parser.add_argument(
74-
"--source_uri",
75-
help="The Uri of the media to stitch (.mpd or .m3u8 file) in double quotes.",
76-
required=True,
77-
)
78-
parser.add_argument(
79-
"--ad_tag_uri",
80-
help="Uri of the ad tag in double quotes.",
76+
"--vod_config_id",
77+
help="The user-defined VOD config ID.",
8178
required=True,
8279
)
8380
args = parser.parse_args()
8481
create_vod_session(
8582
args.project_id,
8683
args.location,
87-
args.source_uri,
88-
args.ad_tag_uri,
84+
args.vod_config_id,
8985
)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 deleting a VOD config.
18+
Example usage:
19+
python delete_vod_config.py --project_id <project-id> --location <location> \
20+
--vod_config_id <vod-config-id>
21+
"""
22+
23+
# [START videostitcher_delete_vod_config]
24+
25+
import argparse
26+
27+
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
28+
VideoStitcherServiceClient,
29+
)
30+
from google.protobuf import empty_pb2 as empty
31+
32+
33+
def delete_vod_config(
34+
project_id: str, location: str, vod_config_id: str
35+
) -> empty.Empty:
36+
"""Deletes a VOD config.
37+
Args:
38+
project_id: The GCP project ID.
39+
location: The location of the VOD config.
40+
vod_config_id: The user-defined VOD config ID."""
41+
42+
client = VideoStitcherServiceClient()
43+
44+
name = f"projects/{project_id}/locations/{location}/vodConfigs/{vod_config_id}"
45+
operation = client.delete_vod_config(name=name)
46+
response = operation.result()
47+
print("Deleted VOD config")
48+
return response
49+
50+
51+
# [END videostitcher_delete_vod_config]
52+
53+
if __name__ == "__main__":
54+
parser = argparse.ArgumentParser()
55+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
56+
parser.add_argument(
57+
"--location",
58+
help="The location of the VOD config.",
59+
required=True,
60+
)
61+
parser.add_argument(
62+
"--vod_config_id",
63+
help="The user-defined VOD config ID.",
64+
required=True,
65+
)
66+
args = parser.parse_args()
67+
delete_vod_config(
68+
args.project_id,
69+
args.location,
70+
args.vod_config_id,
71+
)

video/stitcher/get_vod_config.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 getting a VOD config.
18+
Example usage:
19+
python get_vod_config.py --project_id <project-id> --location <location> \
20+
--vod_config_id <vod-config-id>
21+
"""
22+
23+
# [START videostitcher_get_vod_config]
24+
25+
import argparse
26+
27+
from google.cloud.video import stitcher_v1
28+
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
29+
VideoStitcherServiceClient,
30+
)
31+
32+
33+
def get_vod_config(
34+
project_id: str, location: str, vod_config_id: str
35+
) -> stitcher_v1.types.VodConfig:
36+
"""Gets a VOD config.
37+
Args:
38+
project_id: The GCP project ID.
39+
location: The location of the VOD config.
40+
vod_config_id: The user-defined VOD config ID.
41+
42+
Returns:
43+
The VOD config resource.
44+
"""
45+
46+
client = VideoStitcherServiceClient()
47+
48+
name = f"projects/{project_id}/locations/{location}/vodConfigs/{vod_config_id}"
49+
response = client.get_vod_config(name=name)
50+
print(f"VOD config: {response.name}")
51+
return response
52+
53+
54+
# [END videostitcher_get_vod_config]
55+
56+
if __name__ == "__main__":
57+
parser = argparse.ArgumentParser()
58+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
59+
parser.add_argument(
60+
"--location",
61+
help="The location of the VOD config.",
62+
required=True,
63+
)
64+
parser.add_argument(
65+
"--vod_config_id",
66+
help="The user-defined VOD config ID.",
67+
required=True,
68+
)
69+
args = parser.parse_args()
70+
get_vod_config(
71+
args.project_id,
72+
args.location,
73+
args.vod_config_id,
74+
)

video/stitcher/list_vod_configs.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 listing all VOD configs in a location.
18+
Example usage:
19+
python list_vod_configs.py --project_id <project-id> --location <location>
20+
"""
21+
22+
# [START videostitcher_list_vod_configs]
23+
24+
import argparse
25+
26+
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
27+
pagers,
28+
VideoStitcherServiceClient,
29+
)
30+
31+
32+
def list_vod_configs(project_id: str, location: str) -> pagers.ListVodConfigsPager:
33+
"""Lists all VOD configs in a location.
34+
Args:
35+
project_id: The GCP project ID.
36+
location: The location of the VOD configs.
37+
38+
Returns:
39+
An iterable object containing VOD config resources.
40+
"""
41+
42+
client = VideoStitcherServiceClient()
43+
44+
parent = f"projects/{project_id}/locations/{location}"
45+
response = client.list_vod_configs(parent=parent)
46+
print("VOD configs:")
47+
for vod_config in response.vod_configs:
48+
print({vod_config.name})
49+
50+
return response
51+
52+
53+
# [END videostitcher_list_vod_configs]
54+
55+
if __name__ == "__main__":
56+
parser = argparse.ArgumentParser()
57+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
58+
parser.add_argument(
59+
"--location",
60+
help="The location of the VOD configs.",
61+
required=True,
62+
)
63+
args = parser.parse_args()
64+
list_vod_configs(
65+
args.project_id,
66+
args.location,
67+
)

video/stitcher/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
google-api-python-client==2.131.0
22
grpcio==1.62.1
3-
google-cloud-video-stitcher==0.7.9
3+
google-cloud-video-stitcher==0.7.10

0 commit comments

Comments
 (0)