Skip to content

Commit 3ca038a

Browse files
irataxyparthea
authored andcommitted
docs(samples): Update slates and CDN keys to use LROs (#150)
* docs(samples): Update slates and CDN keys to use LROs. Add samples and tests for live configs and update live session samples. * clear out old resources * add error checking to deleting resources * use default LRO timeouts
1 parent 3b3cf46 commit 3ca038a

20 files changed

+488
-70
lines changed

video/stitcher/cdn_key_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
updated_akamai_key = updated_cloud_cdn_private_key
5151

5252

53-
@pytest.mark.skip()
5453
def test_cdn_key_operations(capsys: pytest.fixture) -> None:
5554

5655
utils.delete_stale_cdn_keys(project_id, location)

video/stitcher/create_cdn_key.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ def create_cdn_key(
7575
private_key=private_key,
7676
)
7777

78-
response = client.create_cdn_key(
78+
operation = client.create_cdn_key(
7979
parent=parent, cdn_key_id=cdn_key_id, cdn_key=cdn_key
8080
)
81+
response = operation.result()
8182
print(f"CDN key: {response.name}")
8283
return response
8384

video/stitcher/create_cdn_key_akamai.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ def create_cdn_key_akamai(
5858
),
5959
)
6060

61-
response = client.create_cdn_key(
61+
operation = client.create_cdn_key(
6262
parent=parent, cdn_key_id=cdn_key_id, cdn_key=cdn_key
6363
)
64+
response = operation.result()
6465
print(f"CDN key: {response.name}")
6566
return response
6667

video/stitcher/create_live_config.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2023 Google Inc. All Rights Reserved.
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 live config. Live
18+
configs are used to configure live sessions.
19+
Example usage:
20+
python create_live_config.py --project_id <project-id> --location <location> \
21+
--live_config_id <live-config-id> --live_stream_uri <uri> --ad_tag_uri <uri> \
22+
--slate_id <id>
23+
"""
24+
25+
# [START videostitcher_create_live_config]
26+
27+
import argparse
28+
29+
from google.cloud.video import stitcher_v1
30+
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
31+
VideoStitcherServiceClient,
32+
)
33+
34+
35+
def create_live_config(
36+
project_id: str,
37+
location: str,
38+
live_config_id: str,
39+
live_stream_uri: str,
40+
ad_tag_uri: str,
41+
slate_id: str,
42+
) -> str:
43+
"""Creates a live config.
44+
Args:
45+
project_id: The GCP project ID.
46+
location: The location in which to create the live config.
47+
live_config_id: The user-defined live config ID.
48+
live_stream_uri: Uri of the livestream to stitch; this URI must reference either an MPEG-DASH
49+
manifest (.mpd) file or an M3U playlist manifest (.m3u8) file.
50+
ad_tag_uri: Uri of the ad tag.
51+
slate_id: The user-defined slate ID of the default slate to use when no slates are specified in an ad break's message."""
52+
53+
client = VideoStitcherServiceClient()
54+
55+
parent = f"projects/{project_id}/locations/{location}"
56+
default_slate = f"projects/{project_id}/locations/{location}/slates/{slate_id}"
57+
58+
live_config = stitcher_v1.types.LiveConfig(
59+
source_uri=live_stream_uri,
60+
ad_tag_uri=ad_tag_uri,
61+
ad_tracking="SERVER",
62+
default_slate=default_slate,
63+
)
64+
65+
operation = client.create_live_config(
66+
parent=parent, live_config_id=live_config_id, live_config=live_config
67+
)
68+
response = operation.result()
69+
print(f"Live config: {response.name}")
70+
return response
71+
72+
73+
# [END videostitcher_create_live_config]
74+
75+
if __name__ == "__main__":
76+
parser = argparse.ArgumentParser()
77+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
78+
parser.add_argument(
79+
"--location",
80+
help="The location in which to create the live config.",
81+
default="us-central1",
82+
)
83+
parser.add_argument(
84+
"--live_config_id",
85+
help="The user-defined live config ID.",
86+
required=True,
87+
)
88+
parser.add_argument(
89+
"--live_stream_uri",
90+
help="The uri of the livestream to stitch (.mpd or .m3u8 file) in double quotes.",
91+
required=True,
92+
)
93+
parser.add_argument(
94+
"--ad_tag_uri",
95+
help="Uri of the ad tag in double quotes.",
96+
required=True,
97+
)
98+
parser.add_argument(
99+
"--slate_id",
100+
help="The user-defined slate ID of the default slate.",
101+
required=True,
102+
)
103+
args = parser.parse_args()
104+
create_live_config(
105+
args.project_id,
106+
args.location,
107+
args.live_config_id,
108+
args.live_stream_uri,
109+
args.ad_tag_uri,
110+
args.slate_id,
111+
)

video/stitcher/create_live_session.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
which to insert ads.
1919
Example usage:
2020
python create_live_session.py --project_id <project-id> \
21-
--location <location> --live_stream_uri <uri> --ad_tag_uri <uri> \
22-
--slate_id <slate-id>
21+
--location <location> --live_config_id <live-config-id>
2322
"""
2423

2524
# [START videostitcher_create_live_session]
@@ -32,30 +31,23 @@
3231
)
3332

3433

35-
def create_live_session(
36-
project_id: str, location: str, live_stream_uri: str, ad_tag_uri: str, slate_id: str
37-
) -> str:
34+
def create_live_session(project_id: str, location: str, live_config_id: str) -> str:
3835
"""Creates a live session. Live sessions are ephemeral resources that expire
3936
after a few minutes.
4037
Args:
4138
project_id: The GCP project ID.
4239
location: The location in which to create the session.
43-
live_stream_uri: Uri of the livestream to stitch; this URI must reference either an MPEG-DASH
44-
manifest (.mpd) file or an M3U playlist manifest (.m3u8) file.
45-
ad_tag_uri: Uri of the ad tag.
46-
slate_id: The user-defined slate ID of the default slate to use when no slates are specified in an ad break's message."""
40+
live_config_id: The user-defined live config ID."""
4741

4842
client = VideoStitcherServiceClient()
4943

5044
parent = f"projects/{project_id}/locations/{location}"
51-
52-
# Create dictionaries and pass them to the LiveSession constructor
53-
ad_tag_map = {"default": stitcher_v1.AdTag(uri=ad_tag_uri)}
54-
55-
live_session = stitcher_v1.types.LiveSession(
56-
source_uri=live_stream_uri, ad_tag_map=ad_tag_map, default_slate_id=slate_id
45+
live_config = (
46+
f"projects/{project_id}/locations/{location}/liveConfigs/{live_config_id}"
5747
)
5848

49+
live_session = stitcher_v1.types.LiveSession(live_config=live_config)
50+
5951
response = client.create_live_session(parent=parent, live_session=live_session)
6052
print(f"Live session: {response.name}")
6153
return response
@@ -72,25 +64,13 @@ def create_live_session(
7264
default="us-central1",
7365
)
7466
parser.add_argument(
75-
"--live_stream_uri",
76-
help="The Uri of the livestream to stitch (.mpd or .m3u8 file) in double quotes.",
77-
required=True,
78-
)
79-
parser.add_argument(
80-
"--ad_tag_uri",
81-
help="Uri of the ad tag in double quotes.",
82-
required=True,
83-
)
84-
parser.add_argument(
85-
"--slate_id",
86-
help="The user-defined slate ID of the default slate.",
67+
"--live_config_id",
68+
help="The user-defined live config ID.",
8769
required=True,
8870
)
8971
args = parser.parse_args()
9072
create_live_session(
9173
args.project_id,
9274
args.location,
93-
args.live_stream_uri,
94-
args.ad_tag_uri,
95-
args.slate_id,
75+
args.live_config_id,
9676
)

video/stitcher/create_slate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def create_slate(project_id: str, location: str, slate_id: str, slate_uri: str)
4747
uri=slate_uri,
4848
)
4949

50-
response = client.create_slate(parent=parent, slate_id=slate_id, slate=slate)
50+
operation = client.create_slate(parent=parent, slate_id=slate_id, slate=slate)
51+
response = operation.result()
5152
print(f"Slate: {response.name}")
5253
return response
5354

video/stitcher/create_vod_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def create_vod_session(
4848
parent = f"projects/{project_id}/locations/{location}"
4949

5050
vod_session = stitcher_v1.types.VodSession(
51-
source_uri=source_uri, ad_tag_uri=ad_tag_uri
51+
source_uri=source_uri, ad_tag_uri=ad_tag_uri, ad_tracking="SERVER"
5252
)
5353

5454
response = client.create_vod_session(parent=parent, vod_session=vod_session)

video/stitcher/delete_cdn_key.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def delete_cdn_key(project_id: str, location: str, cdn_key_id: str) -> str:
3939
client = VideoStitcherServiceClient()
4040

4141
name = f"projects/{project_id}/locations/{location}/cdnKeys/{cdn_key_id}"
42-
response = client.delete_cdn_key(name=name)
42+
operation = client.delete_cdn_key(name=name)
43+
response = operation.result()
4344
print("Deleted CDN key")
4445
return response
4546

video/stitcher/delete_live_config.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2023 Google Inc. All Rights Reserved.
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 live config.
18+
Example usage:
19+
python delete_live_config.py --project_id <project-id> --location <location> \
20+
--live_config_id <live-config-id>
21+
"""
22+
23+
# [START videostitcher_delete_live_config]
24+
25+
import argparse
26+
27+
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
28+
VideoStitcherServiceClient,
29+
)
30+
31+
32+
def delete_live_config(project_id: str, location: str, live_config_id: str) -> str:
33+
"""Deletes a live config.
34+
Args:
35+
project_id: The GCP project ID.
36+
location: The location of the live config.
37+
live_config_id: The user-defined live config ID."""
38+
39+
client = VideoStitcherServiceClient()
40+
41+
name = f"projects/{project_id}/locations/{location}/liveConfigs/{live_config_id}"
42+
operation = client.delete_live_config(name=name)
43+
response = operation.result()
44+
print("Deleted live config")
45+
return response
46+
47+
48+
# [END videostitcher_delete_live_config]
49+
50+
if __name__ == "__main__":
51+
parser = argparse.ArgumentParser()
52+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
53+
parser.add_argument(
54+
"--location",
55+
help="The location of the live config.",
56+
required=True,
57+
)
58+
parser.add_argument(
59+
"--live_config_id",
60+
help="The user-defined live config ID.",
61+
required=True,
62+
)
63+
args = parser.parse_args()
64+
delete_live_config(
65+
args.project_id,
66+
args.location,
67+
args.live_config_id,
68+
)

video/stitcher/delete_slate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def delete_slate(project_id: str, location: str, slate_id: str) -> str:
3939
client = VideoStitcherServiceClient()
4040

4141
name = f"projects/{project_id}/locations/{location}/slates/{slate_id}"
42-
response = client.delete_slate(name=name)
42+
operation = client.delete_slate(name=name)
43+
response = operation.result()
4344
print("Deleted slate")
4445
return response
4546

video/stitcher/get_live_config.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 2023 Google Inc. All Rights Reserved.
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 live config.
18+
Example usage:
19+
python get_live_config.py --project_id <project-id> --location <location> \
20+
--live_config_id <live-config-id>
21+
"""
22+
23+
# [START videostitcher_get_live_config]
24+
25+
import argparse
26+
27+
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
28+
VideoStitcherServiceClient,
29+
)
30+
31+
32+
def get_live_config(project_id: str, location: str, live_config_id: str) -> str:
33+
"""Gets a live config.
34+
Args:
35+
project_id: The GCP project ID.
36+
location: The location of the live config.
37+
live_config_id: The user-defined live config ID."""
38+
39+
client = VideoStitcherServiceClient()
40+
41+
name = f"projects/{project_id}/locations/{location}/liveConfigs/{live_config_id}"
42+
response = client.get_live_config(name=name)
43+
print(f"Live config: {response.name}")
44+
return response
45+
46+
47+
# [END videostitcher_get_live_config]
48+
49+
if __name__ == "__main__":
50+
parser = argparse.ArgumentParser()
51+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
52+
parser.add_argument(
53+
"--location",
54+
help="The location of the live config.",
55+
required=True,
56+
)
57+
parser.add_argument(
58+
"--live_config_id",
59+
help="The user-defined live config ID.",
60+
required=True,
61+
)
62+
args = parser.parse_args()
63+
get_live_config(
64+
args.project_id,
65+
args.location,
66+
args.live_config_id,
67+
)

0 commit comments

Comments
 (0)