Skip to content

Commit 4b311d9

Browse files
committed
Merge remote-tracking branch 'migration/main' into python-video-live-stream-migration
2 parents 4dd9c1c + 908098e commit 4b311d9

33 files changed

+2410
-0
lines changed

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-video-live-stream and change directories to the sample directory
21+
you want to use.
22+
23+
$ git clone https://github.com/googleapis/python-video-live-stream.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 Inc. 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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright 2022 Google Inc. 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+
42+
# Set up
43+
44+
event_name_project_id = f"projects/{project_name}/locations/{location}/channels/{channel_id}/events/{event_id}"
45+
46+
create_input.create_input(project_name, location, input_id)
47+
48+
create_channel.create_channel(
49+
project_name, location, channel_id, input_id, output_uri
50+
)
51+
52+
start_channel.start_channel(project_name, location, channel_id)
53+
54+
# Tests
55+
56+
response = create_channel_event.create_channel_event(
57+
project_name, location, channel_id, event_id
58+
)
59+
assert event_name_project_id in response.name
60+
61+
response = get_channel_event.get_channel_event(
62+
project_name, location, channel_id, event_id
63+
)
64+
assert event_name_project_id in response.name
65+
66+
list_channel_events.list_channel_events(project_name, location, channel_id)
67+
out, _ = capsys.readouterr()
68+
assert event_name_project_id in out
69+
70+
response = delete_channel_event.delete_channel_event(
71+
project_name, location, channel_id, event_id
72+
)
73+
assert response is None
74+
75+
# Clean up
76+
77+
stop_channel.stop_channel(project_name, location, channel_id)
78+
delete_channel.delete_channel(project_name, location, channel_id)
79+
delete_input.delete_input(project_name, location, input_id)

video/live-stream/channel_test.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Copyright 2022 Google Inc. 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+
47+
# Clean up old resources in the test project
48+
channel_responses = list_channels.list_channels(project_name, location)
49+
50+
for response in channel_responses:
51+
next_channel_id = response.name.rsplit("/", 1)[-1]
52+
input_attachments = response.input_attachments
53+
if utils.is_resource_stale(response.create_time):
54+
try:
55+
event_responses = list_channel_events.list_channel_events(
56+
project_name, location, next_channel_id
57+
)
58+
for response in event_responses:
59+
next_event_id = response.name.rsplit("/", 1)[-1]
60+
try:
61+
delete_channel_event.delete_channel_event(
62+
project_name, location, next_channel_id, next_event_id
63+
)
64+
except NotFound as e:
65+
print(f"Ignoring NotFound, details: {e}")
66+
try:
67+
stop_channel.stop_channel(project_name, location, next_channel_id)
68+
except FailedPrecondition as e:
69+
print(f"Ignoring FailedPrecondition, details: {e}")
70+
try:
71+
delete_channel.delete_channel(
72+
project_name, location, next_channel_id
73+
)
74+
except FailedPrecondition as e:
75+
print(f"Ignoring FailedPrecondition, try to stop channel: {e}")
76+
try:
77+
stop_channel.stop_channel(
78+
project_name, location, next_channel_id
79+
)
80+
except FailedPrecondition as e:
81+
print(f"Ignoring FailedPrecondition, details: {e}")
82+
except NotFound as e:
83+
print(f"Ignoring NotFound, details: {e}")
84+
except NotFound as e:
85+
print(f"Ignoring NotFound, details: {e}")
86+
87+
for input_attachment in input_attachments:
88+
next_input_id = input_attachment.input.rsplit("/", 1)[-1]
89+
try:
90+
delete_input.delete_input(project_name, location, next_input_id)
91+
except NotFound as e:
92+
print(f"Ignoring NotFound, details: {e}")
93+
94+
# Set up
95+
96+
channel_name_project_id = (
97+
f"projects/{project_name}/locations/{location}/channels/{channel_id}"
98+
)
99+
100+
create_input.create_input(project_name, location, input_id)
101+
create_input.create_input(project_name, location, updated_input_id)
102+
103+
# Tests
104+
105+
response = create_channel.create_channel(
106+
project_name, location, channel_id, input_id, output_uri
107+
)
108+
assert channel_name_project_id in response.name
109+
110+
list_channels.list_channels(project_name, location)
111+
out, _ = capsys.readouterr()
112+
assert channel_name_project_id in out
113+
114+
response = update_channel.update_channel(
115+
project_name, location, channel_id, updated_input_id
116+
)
117+
assert channel_name_project_id in response.name
118+
for input_attachment in response.input_attachments:
119+
assert "updated-input" in input_attachment.key
120+
121+
response = get_channel.get_channel(project_name, location, channel_id)
122+
assert channel_name_project_id in response.name
123+
124+
start_channel.start_channel(project_name, location, channel_id)
125+
out, _ = capsys.readouterr()
126+
assert "Started channel" in out
127+
128+
stop_channel.stop_channel(project_name, location, channel_id)
129+
out, _ = capsys.readouterr()
130+
assert "Stopped channel" in out
131+
132+
response = delete_channel.delete_channel(project_name, location, channel_id)
133+
assert response == empty.Empty()
134+
135+
response = create_channel_with_backup_input.create_channel_with_backup_input(
136+
project_name, location, channel_id, input_id, updated_input_id, output_uri
137+
)
138+
assert channel_name_project_id in response.name
139+
140+
# Clean up
141+
142+
delete_channel.delete_channel(project_name, location, channel_id)
143+
delete_input.delete_input(project_name, location, input_id)
144+
delete_input.delete_input(project_name, location, updated_input_id)

0 commit comments

Comments
 (0)