Get a VOD config

Get details for a Video Stitcher VOD config resource.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

C#

Before trying this sample, follow the C# setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API C# API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


using Google.Cloud.Video.Stitcher.V1;

public class GetVodConfigSample
{
    public VodConfig GetVodConfig(
        string projectId, string location, string vodConfigId)
    {
        // Create the client.
        VideoStitcherServiceClient client = VideoStitcherServiceClient.Create();

        GetVodConfigRequest request = new GetVodConfigRequest
        {
            VodConfigName = VodConfigName.FromProjectLocationVodConfig(projectId, location, vodConfigId)
        };

        // Call the API.
        VodConfig response = client.GetVodConfig(request);

        // Return the result.
        return response;
    }
}

Go

Before trying this sample, follow the Go setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Go API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import (
	"context"
	"encoding/json"
	"fmt"
	"io"

	stitcher "cloud.google.com/go/video/stitcher/apiv1"
	stitcherstreampb "cloud.google.com/go/video/stitcher/apiv1/stitcherpb"
)

// getVodConfig gets a previously-created VOD config.
func getVodConfig(w io.Writer, projectID, vodConfigID string) error {
	// projectID := "my-project-id"
	// vodConfigID := "my-vod-config-id"
	location := "us-central1"
	ctx := context.Background()
	client, err := stitcher.NewVideoStitcherClient(ctx)
	if err != nil {
		return fmt.Errorf("stitcher.NewVideoStitcherClient: %w", err)
	}
	defer client.Close()

	req := &stitcherstreampb.GetVodConfigRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/vodConfigs/%s", projectID, location, vodConfigID),
	}

	response, err := client.GetVodConfig(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetVodConfig: %w", err)
	}
	b, err := json.MarshalIndent(response, "", " ")
	if err != nil {
		return fmt.Errorf("json.MarshalIndent: %w", err)
	}

	fmt.Fprintf(w, "VOD config:\n%s", string(b))
	return nil
}

Java

Before trying this sample, follow the Java setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Java API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


import com.google.cloud.video.stitcher.v1.GetVodConfigRequest;
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
import com.google.cloud.video.stitcher.v1.VodConfig;
import com.google.cloud.video.stitcher.v1.VodConfigName;
import java.io.IOException;

public class GetVodConfig {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String location = "us-central1";
    String vodConfigId = "my-vod-config-id";

    getVodConfig(projectId, location, vodConfigId);
  }

  // Gets a video on demand (VOD) config.
  public static VodConfig getVodConfig(String projectId, String location, String vodConfigId)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests.
    try (VideoStitcherServiceClient videoStitcherServiceClient =
        VideoStitcherServiceClient.create()) {
      GetVodConfigRequest getVodConfigRequest =
          GetVodConfigRequest.newBuilder()
              .setName(VodConfigName.of(projectId, location, vodConfigId).toString())
              .build();

      VodConfig response = videoStitcherServiceClient.getVodConfig(getVodConfigRequest);
      System.out.println("VOD config: " + response.getName());
      return response;
    }
  }
}

Node.js

Before trying this sample, follow the Node.js setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Node.js API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// projectId = 'my-project-id';
// location = 'us-central1';
// vodConfigId = 'my-vod-config-id';

// Imports the Video Stitcher library
const {VideoStitcherServiceClient} =
  require('@google-cloud/video-stitcher').v1;
// Instantiates a client
const stitcherClient = new VideoStitcherServiceClient();

async function getVodConfig() {
  // Construct request
  const request = {
    name: stitcherClient.vodConfigPath(projectId, location, vodConfigId),
  };
  const [vodConfig] = await stitcherClient.getVodConfig(request);
  console.log(`VOD config: ${vodConfig.name}`);
}

getVodConfig().catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

PHP

Before trying this sample, follow the PHP setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API PHP API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

use Google\Cloud\Video\Stitcher\V1\Client\VideoStitcherServiceClient;
use Google\Cloud\Video\Stitcher\V1\GetVodConfigRequest;

/**
 * Gets a VOD config.
 *
 * @param string $callingProjectId     The project ID to run the API call under
 * @param string $location             The location of the VOD config
 * @param string $vodConfigId         The ID of the VOD config
 */
function get_vod_config(
    string $callingProjectId,
    string $location,
    string $vodConfigId
): void {
    // Instantiate a client.
    $stitcherClient = new VideoStitcherServiceClient();

    $formattedName = $stitcherClient->vodConfigName($callingProjectId, $location, $vodConfigId);
    $request = (new GetVodConfigRequest())
        ->setName($formattedName);
    $vodConfig = $stitcherClient->getVodConfig($request);

    // Print results
    printf('VOD config: %s' . PHP_EOL, $vodConfig->getName());
}

Python

Before trying this sample, follow the Python setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Python API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


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

Ruby

Before trying this sample, follow the Ruby setup instructions in the Video Stitcher API quickstart using client libraries. For more information, see the Video Stitcher API Ruby API reference documentation.

To authenticate to Video Stitcher API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

require "google/cloud/video/stitcher"

##
# Get a VOD config
#
# @param project_id [String] Your Google Cloud project (e.g. `my-project`)
# @param location [String] The location (e.g. `us-central1`)
# @param vod_config_id [String] Your VOD config name (e.g. `my-vod-config`)
#
def get_vod_config project_id:, location:, vod_config_id:
  # Create a Video Stitcher client.
  client = Google::Cloud::Video::Stitcher.video_stitcher_service

  # Build the resource name of the VOD config.
  name = client.vod_config_path project: project_id, location: location,
                                vod_config: vod_config_id

  # Get the VOD config.
  vod_config = client.get_vod_config name: name

  # Print the vod config name.
  puts "VOD config: #{vod_config.name}"
end

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.