diff --git a/video/live-stream/create_channel.py b/video/live-stream/create_channel.py index 1fb664d785f..d025770a681 100644 --- a/video/live-stream/create_channel.py +++ b/video/live-stream/create_channel.py @@ -52,7 +52,7 @@ def create_channel( name=name, input_attachments=[ live_stream_v1.types.InputAttachment( - key="my-input", + key=input_id, input=input, ), ], diff --git a/video/live-stream/create_input.py b/video/live-stream/create_input.py index 5fda7ff086a..e549d716227 100644 --- a/video/live-stream/create_input.py +++ b/video/live-stream/create_input.py @@ -17,7 +17,8 @@ """Google Cloud Live Stream sample for creating an input endpoint. You send an input video stream to this endpoint. Example usage: - python create_input.py --project_id --location --input_id + python create_input.py --project_id --location \ + --input_id [--input_type ] """ # [START livestream_create_input] @@ -31,20 +32,22 @@ def create_input( - project_id: str, location: str, input_id: str + project_id: str, location: str, input_id: str, input_type: str ) -> live_stream_v1.types.Input: """Creates an input. Args: project_id: The GCP project ID. location: The location in which to create the input. - input_id: The user-defined input ID.""" + input_id: The user-defined input ID. + input_type: The input type. + """ client = LivestreamServiceClient() parent = f"projects/{project_id}/locations/{location}" input = live_stream_v1.types.Input( - type_="RTMP_PUSH", + type_=input_type, ) operation = client.create_input(parent=parent, input=input, input_id=input_id) response = operation.result(900) @@ -68,9 +71,16 @@ def create_input( help="The user-defined input ID.", required=True, ) + parser.add_argument( + "--input_type", + help="The input type.", + choices=["RTMP_PUSH", "SRT_PUSH"], + default="RTMP_PUSH", + ) args = parser.parse_args() create_input( args.project_id, args.location, args.input_id, + args.input_type, ) diff --git a/video/live-stream/get_channel.py b/video/live-stream/get_channel.py index 7c6db1e06b2..6c0e4dac42b 100644 --- a/video/live-stream/get_channel.py +++ b/video/live-stream/get_channel.py @@ -43,6 +43,32 @@ def get_channel( name = f"projects/{project_id}/locations/{location}/channels/{channel_id}" response = client.get_channel(name=name) print(f"Channel: {response.name}") + print(f"Creation time: {response.create_time}") + if response.labels: + print("Labels:") + for key, value in response.labels.items(): + print(f" {key}: {value}") + print(f"Update time: {response.update_time}") + print(f"Streaming state: {response.streaming_state.name}") + if response.streaming_error: + print(f"Streaming error: {response.streaming_error.message}") + print(f"Active input: {response.active_input}") + for attachment in response.input_attachments: + print(f"Input attachment: {attachment.key}") + print(f"Output URI: {response.output.uri}") + print(f"Log config: {response.log_config.log_severity.name}") + if response.elementary_streams: + print("Elementary streams:") + for stream in response.elementary_streams: + print(f" {stream.key}") + if response.mux_streams: + print("Mux streams:") + for stream in response.mux_streams: + print(f" {stream.key}") + if response.manifests: + print("Manifests:") + for manifest in response.manifests: + print(f" {manifest.file_name} ({manifest.type_.name})") return response diff --git a/video/live-stream/get_input.py b/video/live-stream/get_input.py index 4da1ab06c09..fc8624d3aa7 100644 --- a/video/live-stream/get_input.py +++ b/video/live-stream/get_input.py @@ -42,7 +42,11 @@ def get_input( name = f"projects/{project_id}/locations/{location}/inputs/{input_id}" response = client.get_input(name=name) - print(f"Input: {response.name}") + print(f"Name: {response.name}") + print(f"Type: {response.type_.name}") + print(f"Tier: {response.tier.name}") + if response.uri: + print(f"URI: {response.uri}") return response diff --git a/video/live-stream/list_channels.py b/video/live-stream/list_channels.py index b1717e8fc6a..6d952a8f794 100644 --- a/video/live-stream/list_channels.py +++ b/video/live-stream/list_channels.py @@ -39,11 +39,13 @@ def list_channels(project_id: str, location: str) -> pagers.ListChannelsPager: parent = f"projects/{project_id}/locations/{location}" page_result = client.list_channels(parent=parent) - print("Channels:") + print("\nThe following Channels are configured in this location:\n") responses = [] for response in page_result: - print(response.name) + print(f"\nChannel: {response.name}") + print(f" Active input: {response.active_input}") + print(f" Output URI: {response.output.uri}") responses.append(response) return responses diff --git a/video/live-stream/update_channel.py b/video/live-stream/update_channel.py index 729ead4716f..aaa44bc36e5 100644 --- a/video/live-stream/update_channel.py +++ b/video/live-stream/update_channel.py @@ -32,14 +32,19 @@ def update_channel( - project_id: str, location: str, channel_id: str, input_id: str + project_id: str, + location: str, + channel_id: str, + input_id: str, + log_config: str = None, ) -> live_stream_v1.types.Channel: """Updates a channel. Args: project_id: The GCP project ID. location: The location of the channel. channel_id: The user-defined channel ID. - input_id: The user-defined input ID for the new input.""" + input_id: The user-defined input ID for the new input. + log_config: The log severity for the channel.""" client = LivestreamServiceClient() input = f"projects/{project_id}/locations/{location}/inputs/{input_id}" @@ -49,12 +54,20 @@ def update_channel( name=name, input_attachments=[ live_stream_v1.types.InputAttachment( - key="updated-input", + key=input_id, input=input, ), ], ) - update_mask = field_mask.FieldMask(paths=["input_attachments"]) + update_mask_paths = ["input_attachments"] + + if log_config: + channel.log_config = live_stream_v1.types.LogConfig( + log_severity=live_stream_v1.types.LogConfig.LogSeverity[log_config] + ) + update_mask_paths.append("log_config") + + update_mask = field_mask.FieldMask(paths=update_mask_paths) operation = client.update_channel(channel=channel, update_mask=update_mask) response = operation.result(600) @@ -83,10 +96,17 @@ def update_channel( help="The user-defined input ID.", required=True, ) + parser.add_argument( + "--log_config", + help="The log severity for the channel.", + choices=["OFF", "DEBUG", "INFO", "WARNING", "ERROR"], + required=False, + ) args = parser.parse_args() update_channel( args.project_id, args.location, args.channel_id, args.input_id, + args.log_config, )