Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
docs(samples): Update slates and CDN keys to use LROs (#150)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
irataxy committed May 19, 2023
1 parent ae8075e commit b2f73e7
Show file tree
Hide file tree
Showing 20 changed files with 488 additions and 70 deletions.
1 change: 0 additions & 1 deletion samples/snippets/cdn_key_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
updated_akamai_key = updated_cloud_cdn_private_key


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

utils.delete_stale_cdn_keys(project_id, location)
Expand Down
3 changes: 2 additions & 1 deletion samples/snippets/create_cdn_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ def create_cdn_key(
private_key=private_key,
)

response = client.create_cdn_key(
operation = client.create_cdn_key(
parent=parent, cdn_key_id=cdn_key_id, cdn_key=cdn_key
)
response = operation.result()
print(f"CDN key: {response.name}")
return response

Expand Down
3 changes: 2 additions & 1 deletion samples/snippets/create_cdn_key_akamai.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ def create_cdn_key_akamai(
),
)

response = client.create_cdn_key(
operation = client.create_cdn_key(
parent=parent, cdn_key_id=cdn_key_id, cdn_key=cdn_key
)
response = operation.result()
print(f"CDN key: {response.name}")
return response

Expand Down
111 changes: 111 additions & 0 deletions samples/snippets/create_live_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env python

# Copyright 2023 Google Inc. All Rights Reserved.
#
# 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.

"""Google Cloud Video Stitcher sample for creating a live config. Live
configs are used to configure live sessions.
Example usage:
python create_live_config.py --project_id <project-id> --location <location> \
--live_config_id <live-config-id> --live_stream_uri <uri> --ad_tag_uri <uri> \
--slate_id <id>
"""

# [START videostitcher_create_live_config]

import argparse

from google.cloud.video import stitcher_v1
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
VideoStitcherServiceClient,
)


def create_live_config(
project_id: str,
location: str,
live_config_id: str,
live_stream_uri: str,
ad_tag_uri: str,
slate_id: str,
) -> str:
"""Creates a live config.
Args:
project_id: The GCP project ID.
location: The location in which to create the live config.
live_config_id: The user-defined live config ID.
live_stream_uri: Uri of the livestream to stitch; this URI must reference either an MPEG-DASH
manifest (.mpd) file or an M3U playlist manifest (.m3u8) file.
ad_tag_uri: Uri of the ad tag.
slate_id: The user-defined slate ID of the default slate to use when no slates are specified in an ad break's message."""

client = VideoStitcherServiceClient()

parent = f"projects/{project_id}/locations/{location}"
default_slate = f"projects/{project_id}/locations/{location}/slates/{slate_id}"

live_config = stitcher_v1.types.LiveConfig(
source_uri=live_stream_uri,
ad_tag_uri=ad_tag_uri,
ad_tracking="SERVER",
default_slate=default_slate,
)

operation = client.create_live_config(
parent=parent, live_config_id=live_config_id, live_config=live_config
)
response = operation.result()
print(f"Live config: {response.name}")
return response


# [END videostitcher_create_live_config]

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
parser.add_argument(
"--location",
help="The location in which to create the live config.",
default="us-central1",
)
parser.add_argument(
"--live_config_id",
help="The user-defined live config ID.",
required=True,
)
parser.add_argument(
"--live_stream_uri",
help="The uri of the livestream to stitch (.mpd or .m3u8 file) in double quotes.",
required=True,
)
parser.add_argument(
"--ad_tag_uri",
help="Uri of the ad tag in double quotes.",
required=True,
)
parser.add_argument(
"--slate_id",
help="The user-defined slate ID of the default slate.",
required=True,
)
args = parser.parse_args()
create_live_config(
args.project_id,
args.location,
args.live_config_id,
args.live_stream_uri,
args.ad_tag_uri,
args.slate_id,
)
40 changes: 10 additions & 30 deletions samples/snippets/create_live_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
which to insert ads.
Example usage:
python create_live_session.py --project_id <project-id> \
--location <location> --live_stream_uri <uri> --ad_tag_uri <uri> \
--slate_id <slate-id>
--location <location> --live_config_id <live-config-id>
"""

# [START videostitcher_create_live_session]
Expand All @@ -32,30 +31,23 @@
)


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

client = VideoStitcherServiceClient()

parent = f"projects/{project_id}/locations/{location}"

# Create dictionaries and pass them to the LiveSession constructor
ad_tag_map = {"default": stitcher_v1.AdTag(uri=ad_tag_uri)}

live_session = stitcher_v1.types.LiveSession(
source_uri=live_stream_uri, ad_tag_map=ad_tag_map, default_slate_id=slate_id
live_config = (
f"projects/{project_id}/locations/{location}/liveConfigs/{live_config_id}"
)

live_session = stitcher_v1.types.LiveSession(live_config=live_config)

response = client.create_live_session(parent=parent, live_session=live_session)
print(f"Live session: {response.name}")
return response
Expand All @@ -72,25 +64,13 @@ def create_live_session(
default="us-central1",
)
parser.add_argument(
"--live_stream_uri",
help="The Uri of the livestream to stitch (.mpd or .m3u8 file) in double quotes.",
required=True,
)
parser.add_argument(
"--ad_tag_uri",
help="Uri of the ad tag in double quotes.",
required=True,
)
parser.add_argument(
"--slate_id",
help="The user-defined slate ID of the default slate.",
"--live_config_id",
help="The user-defined live config ID.",
required=True,
)
args = parser.parse_args()
create_live_session(
args.project_id,
args.location,
args.live_stream_uri,
args.ad_tag_uri,
args.slate_id,
args.live_config_id,
)
3 changes: 2 additions & 1 deletion samples/snippets/create_slate.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def create_slate(project_id: str, location: str, slate_id: str, slate_uri: str)
uri=slate_uri,
)

response = client.create_slate(parent=parent, slate_id=slate_id, slate=slate)
operation = client.create_slate(parent=parent, slate_id=slate_id, slate=slate)
response = operation.result()
print(f"Slate: {response.name}")
return response

Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/create_vod_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def create_vod_session(
parent = f"projects/{project_id}/locations/{location}"

vod_session = stitcher_v1.types.VodSession(
source_uri=source_uri, ad_tag_uri=ad_tag_uri
source_uri=source_uri, ad_tag_uri=ad_tag_uri, ad_tracking="SERVER"
)

response = client.create_vod_session(parent=parent, vod_session=vod_session)
Expand Down
3 changes: 2 additions & 1 deletion samples/snippets/delete_cdn_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def delete_cdn_key(project_id: str, location: str, cdn_key_id: str) -> str:
client = VideoStitcherServiceClient()

name = f"projects/{project_id}/locations/{location}/cdnKeys/{cdn_key_id}"
response = client.delete_cdn_key(name=name)
operation = client.delete_cdn_key(name=name)
response = operation.result()
print("Deleted CDN key")
return response

Expand Down
68 changes: 68 additions & 0 deletions samples/snippets/delete_live_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python

# Copyright 2023 Google Inc. All Rights Reserved.
#
# 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.

"""Google Cloud Video Stitcher sample for deleting a live config.
Example usage:
python delete_live_config.py --project_id <project-id> --location <location> \
--live_config_id <live-config-id>
"""

# [START videostitcher_delete_live_config]

import argparse

from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
VideoStitcherServiceClient,
)


def delete_live_config(project_id: str, location: str, live_config_id: str) -> str:
"""Deletes a live config.
Args:
project_id: The GCP project ID.
location: The location of the live config.
live_config_id: The user-defined live config ID."""

client = VideoStitcherServiceClient()

name = f"projects/{project_id}/locations/{location}/liveConfigs/{live_config_id}"
operation = client.delete_live_config(name=name)
response = operation.result()
print("Deleted live config")
return response


# [END videostitcher_delete_live_config]

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
parser.add_argument(
"--location",
help="The location of the live config.",
required=True,
)
parser.add_argument(
"--live_config_id",
help="The user-defined live config ID.",
required=True,
)
args = parser.parse_args()
delete_live_config(
args.project_id,
args.location,
args.live_config_id,
)
3 changes: 2 additions & 1 deletion samples/snippets/delete_slate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def delete_slate(project_id: str, location: str, slate_id: str) -> str:
client = VideoStitcherServiceClient()

name = f"projects/{project_id}/locations/{location}/slates/{slate_id}"
response = client.delete_slate(name=name)
operation = client.delete_slate(name=name)
response = operation.result()
print("Deleted slate")
return response

Expand Down
67 changes: 67 additions & 0 deletions samples/snippets/get_live_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python

# Copyright 2023 Google Inc. All Rights Reserved.
#
# 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.

"""Google Cloud Video Stitcher sample for getting a live config.
Example usage:
python get_live_config.py --project_id <project-id> --location <location> \
--live_config_id <live-config-id>
"""

# [START videostitcher_get_live_config]

import argparse

from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
VideoStitcherServiceClient,
)


def get_live_config(project_id: str, location: str, live_config_id: str) -> str:
"""Gets a live config.
Args:
project_id: The GCP project ID.
location: The location of the live config.
live_config_id: The user-defined live config ID."""

client = VideoStitcherServiceClient()

name = f"projects/{project_id}/locations/{location}/liveConfigs/{live_config_id}"
response = client.get_live_config(name=name)
print(f"Live config: {response.name}")
return response


# [END videostitcher_get_live_config]

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
parser.add_argument(
"--location",
help="The location of the live config.",
required=True,
)
parser.add_argument(
"--live_config_id",
help="The user-defined live config ID.",
required=True,
)
args = parser.parse_args()
get_live_config(
args.project_id,
args.location,
args.live_config_id,
)
Loading

0 comments on commit b2f73e7

Please sign in to comment.