Skip to content

Commit ce5e0fb

Browse files
partheairataxygcf-owl-bot[bot]renovate-botdizcology
authored
migrate code from googleapis/python-video-live-stream (#10200)
* docs(samples): add code samples (#21) * docs(samples): add code samples * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix region tags * enforce Python type hints * use build specific projects for samples testing * Remove project number env variable. Remove cloud storage dependency. Clean up resources > 3 hours old (instead of 2 days old). * Remove project number in favor of project ID. Avoid infinite loops in responses to LROs. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Anthonios Partheniou <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> * chore(deps): update all dependencies (#33) * chore(deps): update dependency google-cloud-video-live-stream to v0.1.2 (#34) * ci: try to stop channel again before deleting it in the test (#36) * Try to stop channel again before deleting it in the test. * docs(samples): try to stop channel again before deleting it in the test. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> * docs(samples): add sample for creating a channel with a failover backup input (#37) * chore(deps): update dependency google-cloud-video-live-stream to v0.1.3 (#39) * chore: remove dependency google-api-python-client in samples (#40) * chore(deps): update dependency google-api-python-client to v2.47.0 * chore: remove dependency google-api-python-client in samples Co-authored-by: Anthonios Partheniou <[email protected]> * chore(deps): update dependency grpcio to v1.46.0 (#41) * chore(deps): update dependency grpcio to v1.46.1 (#44) * chore(deps): update dependency grpcio to v1.46.3 (#47) * chore(deps): update dependency google-cloud-video-live-stream to v0.1.4 (#48) * docs: align channel config with best practices (#71) skipping optional check for kokoro pre-release dependencies. * chore(deps): update all dependencies (#70) * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <[email protected]> * docs(samples): fix timeout for LROs; first call can take up to 10 minutes (#82) Co-authored-by: Anthonios Partheniou <[email protected]> * docs(samples): fix timeout for create input and start channel LROs; first call can take up to 15 minutes (#86) * chore(deps): update all dependencies (#87) * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <[email protected]> * chore(deps): update all dependencies to v1.0.1 (#90) * chore(deps): update all dependencies to v1.0.1 * revert Co-authored-by: Anthonios Partheniou <[email protected]> * chore(deps): update dependency google-cloud-video-live-stream to v1.0.2 (#94) * chore(deps): update dependency grpcio to v1.48.1 (#101) Co-authored-by: Anthonios Partheniou <[email protected]> * chore(deps): update dependency pytest to v7.1.3 (#106) * chore(deps): update dependency grpcio to v1.49.0 (#111) * chore(deps): update dependency grpcio to v1.49.1 (#112) Co-authored-by: Anthonios Partheniou <[email protected]> * chore(deps): update dependency google-cloud-video-live-stream to v1.0.3 (#115) * chore(deps): update dependency google-cloud-video-live-stream to v1.0.4 (#118) * chore(deps): update dependency grpcio to v1.50.0 (#119) * chore(deps): update dependency pytest to v7.2.0 (#120) * chore(deps): update dependency grpcio to v1.51.1 (#128) Co-authored-by: Anthonios Partheniou <[email protected]> * chore(deps): update dependency google-cloud-video-live-stream to v1.1.0 (#131) * chore(deps): update dependency google-cloud-video-live-stream to v1.2.0 (#135) * chore(deps): update dependency pytest to v7.2.1 (#136) * chore(deps): update dependency google-cloud-video-live-stream to v1.2.1 (#139) * chore(deps): update all dependencies (#146) * chore(deps): update dependency pytest to v7.2.2 (#149) * chore(deps): update all dependencies (#155) * chore(deps): update dependency pytest to v7.3.0 (#156) * chore(deps): update dependency pytest to v7.3.1 (#157) * chore(deps): update dependency grpcio to v1.54.0 (#158) * chore(deps): update dependency grpcio to v1.54.2 (#159) * chore(deps): update dependency pytest to v7.3.2 (#163) * chore(deps): update all dependencies (#164) Co-authored-by: Anthonios Partheniou <[email protected]> * chore(deps): update dependency google-cloud-video-live-stream to v1.4.1 (#169) * chore(deps): update dependency grpcio to v1.56.2 (#173) Co-authored-by: Anthonios Partheniou <[email protected]> * chore(deps): update dependency google-cloud-video-live-stream to v1.5.0 (#179) * chore(deps): update dependency grpcio to v1.57.0 (#181) * docs(samples): add samples and tests for pools and assets (#180) * docs(samples): add samples and tests for pools and assets * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <[email protected]> * chore(deps): update dependency google-cloud-video-live-stream to v1.5.1 (#183) * fix licence headers * Update video/live-stream/noxfile_config.py Co-authored-by: Leah E. Cole <[email protected]> * update CODEOWNERS and blunderbuss.yml * restrict requirements.txt by python version * skip python version 2.7 * Update video/live-stream/noxfile_config.py Co-authored-by: Dan Lee <[email protected]> * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update video/live-stream/README.md Co-authored-by: Dan Lee <[email protected]> * Update video/live-stream/README.md Co-authored-by: Dan Lee <[email protected]> --------- Co-authored-by: Nicholas Cook <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: WhiteSource Renovate <[email protected]> Co-authored-by: WhiteSource Renovate <[email protected]> Co-authored-by: Yu-Han Liu <[email protected]> Co-authored-by: Leah E. Cole <[email protected]> Co-authored-by: Dan Lee <[email protected]>
1 parent fd0dd89 commit ce5e0fb

35 files changed

+2424
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
/healthcare/**/* @GoogleCloudPlatform/healthcare-life-sciences @GoogleCloudPlatform/python-samples-reviewers
108108
/retail/**/* @GoogleCloudPlatform/cloud-retail-team @GoogleCloudPlatform/python-samples-reviewers
109109
/billing/**/* @GoogleCloudPlatform/billing-samples-maintainers @GoogleCloudPlatform/python-samples-reviewers
110+
/video/live-stream/* @GoogleCloudPlatform/cloud-media-team @GoogleCloudPlatform/python-samples-reviewers
110111
/video/stitcher/* @GoogleCloudPlatform/cloud-media-team @GoogleCloudPlatform/python-samples-reviewers
111112

112113
# Deprecated

.github/blunderbuss.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ assign_prs_by:
307307
- labels:
308308
- "api: cloudmedia"
309309
- "api: videostitcher"
310+
- "api: videolivestream"
310311
to:
311312
- GoogleCloudPlatform/cloud-media-team
312313
- labels:

video/live-stream/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Live Stream API Python Samples
2+
3+
This directory contains samples for the Live Stream API. Use this API to
4+
transcode live, linear video streams into a variety of formats. The Live Stream
5+
API benefits broadcasters, production companies, businesses, and individuals
6+
looking to transform their live video content for use across a variety of user
7+
devices. For more information, see the
8+
[Live Stream API documentation](https://cloud.google.com/livestream/).
9+
10+
## Setup
11+
12+
To run the samples, you need to first follow the steps in
13+
[Before you begin](https://cloud.google.com/livestream/docs/how-to/before-you-begin).
14+
15+
For more information on authentication, refer to the
16+
[Authentication Getting Started Guide](https://cloud.google.com/docs/authentication/getting-started).
17+
18+
## Install Dependencies
19+
20+
1. Clone python-docs-samples repository and change directories to the sample directory
21+
you want to use.
22+
23+
$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
24+
25+
1. Install [pip](https://pip.pypa.io/) and
26+
[virtualenv](https://virtualenv.pypa.io/) if you do not already have them. You
27+
may want to refer to the
28+
[Python Development Environment Setup Guide](https://cloud.google.com/python/setup)
29+
for Google Cloud Platform for instructions.
30+
31+
1. Create a virtualenv. Samples are compatible with Python 3.6+.
32+
33+
$ virtualenv env
34+
$ source env/bin/activate
35+
36+
1. Install the dependencies needed to run the samples.
37+
38+
$ pip install -r requirements.txt
39+
40+
## Testing
41+
42+
Make sure to enable the Live Stream API on the test project. Set the following
43+
environment variable:
44+
45+
* `GOOGLE_CLOUD_PROJECT`

video/live-stream/asset_test.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2023 Google LLC. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import uuid
17+
18+
from google.api_core.exceptions import FailedPrecondition, NotFound
19+
from google.protobuf import empty_pb2 as empty
20+
import pytest
21+
22+
import create_asset
23+
import delete_asset
24+
import get_asset
25+
import list_assets
26+
import utils
27+
28+
project_name = os.environ["GOOGLE_CLOUD_PROJECT"]
29+
location = "us-central1"
30+
asset_id = f"my-python-test-asset-{uuid.uuid4()}"
31+
asset_uri = "gs://cloud-samples-data/media/ForBiggerEscapes.mp4"
32+
33+
34+
def test_asset_operations(capsys: pytest.fixture) -> None:
35+
# Clean up old resources in the test project
36+
responses = list_assets.list_assets(project_name, location)
37+
for response in responses:
38+
next_asset_id = response.name.rsplit("/", 1)[-1]
39+
if utils.is_resource_stale(response.create_time):
40+
try:
41+
delete_asset.delete_asset(project_name, location, next_asset_id)
42+
except FailedPrecondition as e:
43+
print(f"Ignoring FailedPrecondition, details: {e}")
44+
except NotFound as e:
45+
print(f"Ignoring NotFound, details: {e}")
46+
47+
asset_name_project_id = (
48+
f"projects/{project_name}/locations/{location}/assets/{asset_id}"
49+
)
50+
51+
# Tests
52+
53+
response = create_asset.create_asset(project_name, location, asset_id, asset_uri)
54+
assert asset_name_project_id in response.name
55+
56+
list_assets.list_assets(project_name, location)
57+
out, _ = capsys.readouterr()
58+
assert asset_name_project_id in out
59+
60+
response = get_asset.get_asset(project_name, location, asset_id)
61+
assert asset_name_project_id in response.name
62+
63+
response = delete_asset.delete_asset(project_name, location, asset_id)
64+
assert response == empty.Empty()
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright 2022 Google LLC. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import uuid
17+
18+
import pytest
19+
20+
import create_channel
21+
import create_channel_event
22+
import create_input
23+
import delete_channel
24+
import delete_channel_event
25+
import delete_input
26+
import get_channel_event
27+
import list_channel_events
28+
import start_channel
29+
import stop_channel
30+
31+
project_name = os.environ["GOOGLE_CLOUD_PROJECT"]
32+
location = "us-central1"
33+
input_id = f"python-test-input-{uuid.uuid4()}"
34+
channel_id = f"python-test-channel-{uuid.uuid4()}"
35+
event_id = f"python-test-event-{uuid.uuid4()}"
36+
output_bucket_name = f"python-test-bucket-{uuid.uuid4()}"
37+
output_uri = f"gs://{output_bucket_name}/channel-test/"
38+
39+
40+
def test_channel_event_operations(capsys: pytest.fixture) -> None:
41+
# Set up
42+
43+
event_name_project_id = f"projects/{project_name}/locations/{location}/channels/{channel_id}/events/{event_id}"
44+
45+
create_input.create_input(project_name, location, input_id)
46+
47+
create_channel.create_channel(
48+
project_name, location, channel_id, input_id, output_uri
49+
)
50+
51+
start_channel.start_channel(project_name, location, channel_id)
52+
53+
# Tests
54+
55+
response = create_channel_event.create_channel_event(
56+
project_name, location, channel_id, event_id
57+
)
58+
assert event_name_project_id in response.name
59+
60+
response = get_channel_event.get_channel_event(
61+
project_name, location, channel_id, event_id
62+
)
63+
assert event_name_project_id in response.name
64+
65+
list_channel_events.list_channel_events(project_name, location, channel_id)
66+
out, _ = capsys.readouterr()
67+
assert event_name_project_id in out
68+
69+
response = delete_channel_event.delete_channel_event(
70+
project_name, location, channel_id, event_id
71+
)
72+
assert response is None
73+
74+
# Clean up
75+
76+
stop_channel.stop_channel(project_name, location, channel_id)
77+
delete_channel.delete_channel(project_name, location, channel_id)
78+
delete_input.delete_input(project_name, location, input_id)

video/live-stream/channel_test.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Copyright 2022 Google LLC. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import uuid
17+
18+
from google.api_core.exceptions import FailedPrecondition, NotFound
19+
from google.protobuf import empty_pb2 as empty
20+
import pytest
21+
22+
import create_channel
23+
import create_channel_with_backup_input
24+
import create_input
25+
import delete_channel
26+
import delete_channel_event
27+
import delete_input
28+
import get_channel
29+
import list_channel_events
30+
import list_channels
31+
import start_channel
32+
import stop_channel
33+
import update_channel
34+
import utils
35+
36+
project_name = os.environ["GOOGLE_CLOUD_PROJECT"]
37+
location = "us-central1"
38+
input_id = f"python-test-input-{uuid.uuid4()}"
39+
updated_input_id = f"python-test-up-input-{uuid.uuid4()}"
40+
channel_id = f"python-test-channel-{uuid.uuid4()}"
41+
output_bucket_name = f"python-test-bucket-{uuid.uuid4()}"
42+
output_uri = f"gs://{output_bucket_name}/channel-test/"
43+
44+
45+
def test_channel_operations(capsys: pytest.fixture) -> None:
46+
# Clean up old resources in the test project
47+
channel_responses = list_channels.list_channels(project_name, location)
48+
49+
for response in channel_responses:
50+
next_channel_id = response.name.rsplit("/", 1)[-1]
51+
input_attachments = response.input_attachments
52+
if utils.is_resource_stale(response.create_time):
53+
try:
54+
event_responses = list_channel_events.list_channel_events(
55+
project_name, location, next_channel_id
56+
)
57+
for response in event_responses:
58+
next_event_id = response.name.rsplit("/", 1)[-1]
59+
try:
60+
delete_channel_event.delete_channel_event(
61+
project_name, location, next_channel_id, next_event_id
62+
)
63+
except NotFound as e:
64+
print(f"Ignoring NotFound, details: {e}")
65+
try:
66+
stop_channel.stop_channel(project_name, location, next_channel_id)
67+
except FailedPrecondition as e:
68+
print(f"Ignoring FailedPrecondition, details: {e}")
69+
try:
70+
delete_channel.delete_channel(
71+
project_name, location, next_channel_id
72+
)
73+
except FailedPrecondition as e:
74+
print(f"Ignoring FailedPrecondition, try to stop channel: {e}")
75+
try:
76+
stop_channel.stop_channel(
77+
project_name, location, next_channel_id
78+
)
79+
except FailedPrecondition as e:
80+
print(f"Ignoring FailedPrecondition, details: {e}")
81+
except NotFound as e:
82+
print(f"Ignoring NotFound, details: {e}")
83+
except NotFound as e:
84+
print(f"Ignoring NotFound, details: {e}")
85+
86+
for input_attachment in input_attachments:
87+
next_input_id = input_attachment.input.rsplit("/", 1)[-1]
88+
try:
89+
delete_input.delete_input(project_name, location, next_input_id)
90+
except NotFound as e:
91+
print(f"Ignoring NotFound, details: {e}")
92+
93+
# Set up
94+
95+
channel_name_project_id = (
96+
f"projects/{project_name}/locations/{location}/channels/{channel_id}"
97+
)
98+
99+
create_input.create_input(project_name, location, input_id)
100+
create_input.create_input(project_name, location, updated_input_id)
101+
102+
# Tests
103+
104+
response = create_channel.create_channel(
105+
project_name, location, channel_id, input_id, output_uri
106+
)
107+
assert channel_name_project_id in response.name
108+
109+
list_channels.list_channels(project_name, location)
110+
out, _ = capsys.readouterr()
111+
assert channel_name_project_id in out
112+
113+
response = update_channel.update_channel(
114+
project_name, location, channel_id, updated_input_id
115+
)
116+
assert channel_name_project_id in response.name
117+
for input_attachment in response.input_attachments:
118+
assert "updated-input" in input_attachment.key
119+
120+
response = get_channel.get_channel(project_name, location, channel_id)
121+
assert channel_name_project_id in response.name
122+
123+
start_channel.start_channel(project_name, location, channel_id)
124+
out, _ = capsys.readouterr()
125+
assert "Started channel" in out
126+
127+
stop_channel.stop_channel(project_name, location, channel_id)
128+
out, _ = capsys.readouterr()
129+
assert "Stopped channel" in out
130+
131+
response = delete_channel.delete_channel(project_name, location, channel_id)
132+
assert response == empty.Empty()
133+
134+
response = create_channel_with_backup_input.create_channel_with_backup_input(
135+
project_name, location, channel_id, input_id, updated_input_id, output_uri
136+
)
137+
assert channel_name_project_id in response.name
138+
139+
# Clean up
140+
141+
delete_channel.delete_channel(project_name, location, channel_id)
142+
delete_input.delete_input(project_name, location, input_id)
143+
delete_input.delete_input(project_name, location, updated_input_id)

0 commit comments

Comments
 (0)