Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions video/stitcher/create_vod_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env python

# Copyright 2024 Google LLC
#
# 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 VOD config. VOD
configs are used to configure VOD sessions.
Example usage:
python create_vod_config.py --project_id <project-id> --location <location> \
--vod_config_id <vod-config-id> --vod_uri <uri> --ad_tag_uri <uri>
"""

# [START videostitcher_create_vod_config]

import argparse

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


def create_vod_config(
project_id: str,
location: str,
vod_config_id: str,
vod_uri: str,
ad_tag_uri: str,
) -> stitcher_v1.types.VodConfig:
"""Creates a VOD config.
Args:
project_id: The GCP project ID.
location: The location in which to create the VOD config.
vod_config_id: The user-defined VOD config ID.
vod_uri: URI of the VOD 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.

Returns:
The VOD config resource.
"""

client = VideoStitcherServiceClient()

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

vod_config = stitcher_v1.types.VodConfig(
source_uri=vod_uri,
ad_tag_uri=ad_tag_uri,
)

operation = client.create_vod_config(
parent=parent, vod_config_id=vod_config_id, vod_config=vod_config
)
response = operation.result()
print(f"VOD config: {response.name}")
return response


# [END videostitcher_create_vod_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 VOD config.",
default="us-central1",
)
parser.add_argument(
"--vod_config_id",
help="The user-defined VOD config ID.",
required=True,
)
parser.add_argument(
"--vod_uri",
help="The URI of the VOD stream 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,
)
args = parser.parse_args()
create_vod_config(
args.project_id,
args.location,
args.vod_config_id,
args.vod_uri,
args.ad_tag_uri,
)
26 changes: 11 additions & 15 deletions video/stitcher/create_vod_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
session in which to insert ads.
Example usage:
python create_vod_session.py --project_id <project-id> \
--location <location> --source_uri <uri> --ad_tag_uri <uri>
--location <location> --vod_config_id <vod-config-id>
"""

# [START videostitcher_create_vod_session]
Expand All @@ -32,16 +32,15 @@


def create_vod_session(
project_id: str, location: str, source_uri: str, ad_tag_uri: str
project_id: str, location: str, vod_config_id: str
) -> stitcher_v1.types.VodSession:
"""Creates a VOD session. VOD sessions are ephemeral resources that expire
after a few hours.
Args:
project_id: The GCP project ID.
location: The location in which to create the session.
source_uri: Uri of the media 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.
vod_config_id: The user-defined VOD config ID to use to create the
session.

Returns:
The VOD session resource.
Expand All @@ -50,9 +49,12 @@ def create_vod_session(
client = VideoStitcherServiceClient()

parent = f"projects/{project_id}/locations/{location}"
vod_config_name = (
f"projects/{project_id}/locations/{location}/vodConfigs/{vod_config_id}"
)

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

response = client.create_vod_session(parent=parent, vod_session=vod_session)
Expand All @@ -71,19 +73,13 @@ def create_vod_session(
default="us-central1",
)
parser.add_argument(
"--source_uri",
help="The Uri of the media 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.",
"--vod_config_id",
help="The user-defined VOD config ID.",
required=True,
)
args = parser.parse_args()
create_vod_session(
args.project_id,
args.location,
args.source_uri,
args.ad_tag_uri,
args.vod_config_id,
)
71 changes: 71 additions & 0 deletions video/stitcher/delete_vod_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python

# Copyright 2024 Google LLC
#
# 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 VOD config.
Example usage:
python delete_vod_config.py --project_id <project-id> --location <location> \
--vod_config_id <vod-config-id>
"""

# [START videostitcher_delete_vod_config]

import argparse

from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
VideoStitcherServiceClient,
)
from google.protobuf import empty_pb2 as empty


def delete_vod_config(
project_id: str, location: str, vod_config_id: str
) -> empty.Empty:
"""Deletes a VOD config.
Args:
project_id: The GCP project ID.
location: The location of the VOD config.
vod_config_id: The user-defined VOD config ID."""

client = VideoStitcherServiceClient()

name = f"projects/{project_id}/locations/{location}/vodConfigs/{vod_config_id}"
operation = client.delete_vod_config(name=name)
response = operation.result()
print("Deleted VOD config")
return response


# [END videostitcher_delete_vod_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 VOD config.",
required=True,
)
parser.add_argument(
"--vod_config_id",
help="The user-defined VOD config ID.",
required=True,
)
args = parser.parse_args()
delete_vod_config(
args.project_id,
args.location,
args.vod_config_id,
)
74 changes: 74 additions & 0 deletions video/stitcher/get_vod_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python

# Copyright 2024 Google LLC
#
# 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 VOD config.
Example usage:
python get_vod_config.py --project_id <project-id> --location <location> \
--vod_config_id <vod-config-id>
"""

# [START videostitcher_get_vod_config]

import argparse

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


def get_vod_config(
project_id: str, location: str, vod_config_id: str
) -> stitcher_v1.types.VodConfig:
"""Gets a VOD config.
Args:
project_id: The GCP project ID.
location: The location of the VOD config.
vod_config_id: The user-defined VOD config ID.

Returns:
The VOD config resource.
"""

client = VideoStitcherServiceClient()

name = f"projects/{project_id}/locations/{location}/vodConfigs/{vod_config_id}"
response = client.get_vod_config(name=name)
print(f"VOD config: {response.name}")
return response


# [END videostitcher_get_vod_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 VOD config.",
required=True,
)
parser.add_argument(
"--vod_config_id",
help="The user-defined VOD config ID.",
required=True,
)
args = parser.parse_args()
get_vod_config(
args.project_id,
args.location,
args.vod_config_id,
)
67 changes: 67 additions & 0 deletions video/stitcher/list_vod_configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python

# Copyright 2024 Google LLC
#
# 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 listing all VOD configs in a location.
Example usage:
python list_vod_configs.py --project_id <project-id> --location <location>
"""

# [START videostitcher_list_vod_configs]

import argparse

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


def list_vod_configs(project_id: str, location: str) -> pagers.ListVodConfigsPager:
"""Lists all VOD configs in a location.
Args:
project_id: The GCP project ID.
location: The location of the VOD configs.

Returns:
An iterable object containing VOD config resources.
"""

client = VideoStitcherServiceClient()

parent = f"projects/{project_id}/locations/{location}"
response = client.list_vod_configs(parent=parent)
print("VOD configs:")
for vod_config in response.vod_configs:
print({vod_config.name})

return response


# [END videostitcher_list_vod_configs]

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 VOD configs.",
required=True,
)
args = parser.parse_args()
list_vod_configs(
args.project_id,
args.location,
)
2 changes: 1 addition & 1 deletion video/stitcher/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
google-api-python-client==2.131.0
grpcio==1.62.1
google-cloud-video-stitcher==0.7.9
google-cloud-video-stitcher==0.7.10
Loading