Skip to content

Commit

Permalink
migrate code from googleapis/python-video-live-stream (#10200)
Browse files Browse the repository at this point in the history
* 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 <partheniou@google.com>
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 <partheniou@google.com>

* 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 <partheniou@google.com>

* docs(samples): fix timeout for LROs; first call can take up to 10 minutes (#82)

Co-authored-by: Anthonios Partheniou <partheniou@google.com>

* 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 <partheniou@google.com>

* 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 <partheniou@google.com>

* 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 <partheniou@google.com>

* 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 <partheniou@google.com>

* 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 <partheniou@google.com>

* 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 <partheniou@google.com>

* 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 <partheniou@google.com>

* 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 <partheniou@google.com>

* 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 <6719667+leahecole@users.noreply.github.com>

* 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 <71398022+dandhlee@users.noreply.github.com>

* 🦉 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 <71398022+dandhlee@users.noreply.github.com>

* Update video/live-stream/README.md

Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>

---------

Co-authored-by: Nicholas Cook <irataxy@users.noreply.github.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: WhiteSource Renovate <renovate@whitesourcesoftware.com>
Co-authored-by: WhiteSource Renovate <bot@renovateapp.com>
Co-authored-by: Yu-Han Liu <yuhanliu@google.com>
Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com>
Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>
  • Loading branch information
8 people committed Sep 15, 2023
1 parent fd0dd89 commit ce5e0fb
Show file tree
Hide file tree
Showing 35 changed files with 2,424 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
/healthcare/**/* @GoogleCloudPlatform/healthcare-life-sciences @GoogleCloudPlatform/python-samples-reviewers
/retail/**/* @GoogleCloudPlatform/cloud-retail-team @GoogleCloudPlatform/python-samples-reviewers
/billing/**/* @GoogleCloudPlatform/billing-samples-maintainers @GoogleCloudPlatform/python-samples-reviewers
/video/live-stream/* @GoogleCloudPlatform/cloud-media-team @GoogleCloudPlatform/python-samples-reviewers
/video/stitcher/* @GoogleCloudPlatform/cloud-media-team @GoogleCloudPlatform/python-samples-reviewers

# Deprecated
Expand Down
1 change: 1 addition & 0 deletions .github/blunderbuss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ assign_prs_by:
- labels:
- "api: cloudmedia"
- "api: videostitcher"
- "api: videolivestream"
to:
- GoogleCloudPlatform/cloud-media-team
- labels:
Expand Down
45 changes: 45 additions & 0 deletions video/live-stream/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Live Stream API Python Samples

This directory contains samples for the Live Stream API. Use this API to
transcode live, linear video streams into a variety of formats. The Live Stream
API benefits broadcasters, production companies, businesses, and individuals
looking to transform their live video content for use across a variety of user
devices. For more information, see the
[Live Stream API documentation](https://cloud.google.com/livestream/).

## Setup

To run the samples, you need to first follow the steps in
[Before you begin](https://cloud.google.com/livestream/docs/how-to/before-you-begin).

For more information on authentication, refer to the
[Authentication Getting Started Guide](https://cloud.google.com/docs/authentication/getting-started).

## Install Dependencies

1. Clone python-docs-samples repository and change directories to the sample directory
you want to use.

$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git

1. Install [pip](https://pip.pypa.io/) and
[virtualenv](https://virtualenv.pypa.io/) if you do not already have them. You
may want to refer to the
[Python Development Environment Setup Guide](https://cloud.google.com/python/setup)
for Google Cloud Platform for instructions.

1. Create a virtualenv. Samples are compatible with Python 3.6+.

$ virtualenv env
$ source env/bin/activate

1. Install the dependencies needed to run the samples.

$ pip install -r requirements.txt

## Testing

Make sure to enable the Live Stream API on the test project. Set the following
environment variable:

* `GOOGLE_CLOUD_PROJECT`
64 changes: 64 additions & 0 deletions video/live-stream/asset_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2023 Google LLC. 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.

import os
import uuid

from google.api_core.exceptions import FailedPrecondition, NotFound
from google.protobuf import empty_pb2 as empty
import pytest

import create_asset
import delete_asset
import get_asset
import list_assets
import utils

project_name = os.environ["GOOGLE_CLOUD_PROJECT"]
location = "us-central1"
asset_id = f"my-python-test-asset-{uuid.uuid4()}"
asset_uri = "gs://cloud-samples-data/media/ForBiggerEscapes.mp4"


def test_asset_operations(capsys: pytest.fixture) -> None:
# Clean up old resources in the test project
responses = list_assets.list_assets(project_name, location)
for response in responses:
next_asset_id = response.name.rsplit("/", 1)[-1]
if utils.is_resource_stale(response.create_time):
try:
delete_asset.delete_asset(project_name, location, next_asset_id)
except FailedPrecondition as e:
print(f"Ignoring FailedPrecondition, details: {e}")
except NotFound as e:
print(f"Ignoring NotFound, details: {e}")

asset_name_project_id = (
f"projects/{project_name}/locations/{location}/assets/{asset_id}"
)

# Tests

response = create_asset.create_asset(project_name, location, asset_id, asset_uri)
assert asset_name_project_id in response.name

list_assets.list_assets(project_name, location)
out, _ = capsys.readouterr()
assert asset_name_project_id in out

response = get_asset.get_asset(project_name, location, asset_id)
assert asset_name_project_id in response.name

response = delete_asset.delete_asset(project_name, location, asset_id)
assert response == empty.Empty()
78 changes: 78 additions & 0 deletions video/live-stream/channel_event_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2022 Google LLC. 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.

import os
import uuid

import pytest

import create_channel
import create_channel_event
import create_input
import delete_channel
import delete_channel_event
import delete_input
import get_channel_event
import list_channel_events
import start_channel
import stop_channel

project_name = os.environ["GOOGLE_CLOUD_PROJECT"]
location = "us-central1"
input_id = f"python-test-input-{uuid.uuid4()}"
channel_id = f"python-test-channel-{uuid.uuid4()}"
event_id = f"python-test-event-{uuid.uuid4()}"
output_bucket_name = f"python-test-bucket-{uuid.uuid4()}"
output_uri = f"gs://{output_bucket_name}/channel-test/"


def test_channel_event_operations(capsys: pytest.fixture) -> None:
# Set up

event_name_project_id = f"projects/{project_name}/locations/{location}/channels/{channel_id}/events/{event_id}"

create_input.create_input(project_name, location, input_id)

create_channel.create_channel(
project_name, location, channel_id, input_id, output_uri
)

start_channel.start_channel(project_name, location, channel_id)

# Tests

response = create_channel_event.create_channel_event(
project_name, location, channel_id, event_id
)
assert event_name_project_id in response.name

response = get_channel_event.get_channel_event(
project_name, location, channel_id, event_id
)
assert event_name_project_id in response.name

list_channel_events.list_channel_events(project_name, location, channel_id)
out, _ = capsys.readouterr()
assert event_name_project_id in out

response = delete_channel_event.delete_channel_event(
project_name, location, channel_id, event_id
)
assert response is None

# Clean up

stop_channel.stop_channel(project_name, location, channel_id)
delete_channel.delete_channel(project_name, location, channel_id)
delete_input.delete_input(project_name, location, input_id)
143 changes: 143 additions & 0 deletions video/live-stream/channel_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Copyright 2022 Google LLC. 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.

import os
import uuid

from google.api_core.exceptions import FailedPrecondition, NotFound
from google.protobuf import empty_pb2 as empty
import pytest

import create_channel
import create_channel_with_backup_input
import create_input
import delete_channel
import delete_channel_event
import delete_input
import get_channel
import list_channel_events
import list_channels
import start_channel
import stop_channel
import update_channel
import utils

project_name = os.environ["GOOGLE_CLOUD_PROJECT"]
location = "us-central1"
input_id = f"python-test-input-{uuid.uuid4()}"
updated_input_id = f"python-test-up-input-{uuid.uuid4()}"
channel_id = f"python-test-channel-{uuid.uuid4()}"
output_bucket_name = f"python-test-bucket-{uuid.uuid4()}"
output_uri = f"gs://{output_bucket_name}/channel-test/"


def test_channel_operations(capsys: pytest.fixture) -> None:
# Clean up old resources in the test project
channel_responses = list_channels.list_channels(project_name, location)

for response in channel_responses:
next_channel_id = response.name.rsplit("/", 1)[-1]
input_attachments = response.input_attachments
if utils.is_resource_stale(response.create_time):
try:
event_responses = list_channel_events.list_channel_events(
project_name, location, next_channel_id
)
for response in event_responses:
next_event_id = response.name.rsplit("/", 1)[-1]
try:
delete_channel_event.delete_channel_event(
project_name, location, next_channel_id, next_event_id
)
except NotFound as e:
print(f"Ignoring NotFound, details: {e}")
try:
stop_channel.stop_channel(project_name, location, next_channel_id)
except FailedPrecondition as e:
print(f"Ignoring FailedPrecondition, details: {e}")
try:
delete_channel.delete_channel(
project_name, location, next_channel_id
)
except FailedPrecondition as e:
print(f"Ignoring FailedPrecondition, try to stop channel: {e}")
try:
stop_channel.stop_channel(
project_name, location, next_channel_id
)
except FailedPrecondition as e:
print(f"Ignoring FailedPrecondition, details: {e}")
except NotFound as e:
print(f"Ignoring NotFound, details: {e}")
except NotFound as e:
print(f"Ignoring NotFound, details: {e}")

for input_attachment in input_attachments:
next_input_id = input_attachment.input.rsplit("/", 1)[-1]
try:
delete_input.delete_input(project_name, location, next_input_id)
except NotFound as e:
print(f"Ignoring NotFound, details: {e}")

# Set up

channel_name_project_id = (
f"projects/{project_name}/locations/{location}/channels/{channel_id}"
)

create_input.create_input(project_name, location, input_id)
create_input.create_input(project_name, location, updated_input_id)

# Tests

response = create_channel.create_channel(
project_name, location, channel_id, input_id, output_uri
)
assert channel_name_project_id in response.name

list_channels.list_channels(project_name, location)
out, _ = capsys.readouterr()
assert channel_name_project_id in out

response = update_channel.update_channel(
project_name, location, channel_id, updated_input_id
)
assert channel_name_project_id in response.name
for input_attachment in response.input_attachments:
assert "updated-input" in input_attachment.key

response = get_channel.get_channel(project_name, location, channel_id)
assert channel_name_project_id in response.name

start_channel.start_channel(project_name, location, channel_id)
out, _ = capsys.readouterr()
assert "Started channel" in out

stop_channel.stop_channel(project_name, location, channel_id)
out, _ = capsys.readouterr()
assert "Stopped channel" in out

response = delete_channel.delete_channel(project_name, location, channel_id)
assert response == empty.Empty()

response = create_channel_with_backup_input.create_channel_with_backup_input(
project_name, location, channel_id, input_id, updated_input_id, output_uri
)
assert channel_name_project_id in response.name

# Clean up

delete_channel.delete_channel(project_name, location, channel_id)
delete_input.delete_input(project_name, location, input_id)
delete_input.delete_input(project_name, location, updated_input_id)
Loading

0 comments on commit ce5e0fb

Please sign in to comment.