Bunnyx.Stream (Bunnyx v0.4.0)

Copy Markdown View Source

Stream video management. Upload, manage, and deliver videos through bunny.net's Stream platform.

Stream uses a separate client from the main API because it has its own authentication (a library-specific API key) and a different base URL. Create one with Bunnyx.Stream.new/1.

Usage

client = Bunnyx.Stream.new(api_key: "lib-api-key-...", library_id: 12345)

{:ok, video} = Bunnyx.Stream.create(client, title: "My Video")
{:ok, nil} = Bunnyx.Stream.upload(client, video.guid, video_binary)
{:ok, video} = Bunnyx.Stream.get(client, video.guid)
{:ok, page} = Bunnyx.Stream.list(client)
{:ok, nil} = Bunnyx.Stream.delete(client, video.guid)

Summary

Functions

Adds or updates a caption track for a video.

Adds an output codec to a video (0 = x264, 1 = vp9, 2 = hevc, 3 = av1).

Cleans up unconfigured resolution files from a video.

Creates a video. The video must be uploaded separately with upload/3.

Creates a collection with the given name.

Deletes a video.

Deletes a caption track from a video.

Fetches a video from a URL for the library to download and encode.

Fetches a video by GUID.

Fetches a collection by GUID.

Returns the video watch heatmap data.

Lists videos in the library.

Lists collections in the library.

Creates a new Stream client.

Returns oEmbed data for a video URL.

Triggers re-encoding of a video.

Sets a video thumbnail from a URL.

Triggers AI-powered smart actions for a video.

Triggers transcription for a video.

Updates a video's metadata.

Updates a collection's name.

Uploads video data to a previously created video.

Returns raw heatmap data for a video.

Returns player configuration and playback URLs for a video.

Returns resolution availability and encoding info for a video.

Returns video statistics for the library or a specific video.

Returns storage size breakdown for a video.

Types

t()

@type t() :: %Bunnyx.Stream{library_id: pos_integer(), req: Req.Request.t()}

Functions

add_caption(client, video_id, srclang, label, captions_file)

@spec add_caption(t() | keyword(), String.t(), String.t(), String.t(), String.t()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Adds or updates a caption track for a video.

add_output_codec(client, video_id, codec_id)

@spec add_output_codec(t() | keyword(), String.t(), integer()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Adds an output codec to a video (0 = x264, 1 = vp9, 2 = hevc, 3 = av1).

cleanup_resolutions(client, video_id, opts \\ [])

@spec cleanup_resolutions(t() | keyword(), String.t(), keyword()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Cleans up unconfigured resolution files from a video.

Options

  • :dry_run — if true, returns info without deleting (default false)

create(client, attrs)

@spec create(t() | keyword(), Bunnyx.Params.attrs()) ::
  {:ok, Bunnyx.Stream.Video.t()} | {:error, Bunnyx.Error.t()}

Creates a video. The video must be uploaded separately with upload/3.

Attributes

  • :title (required) — video title
  • :collection_id — collection to place the video in
  • :thumbnail_time — time in ms to extract the thumbnail from

create_collection(client, name)

@spec create_collection(t() | keyword(), String.t()) ::
  {:ok, Bunnyx.Stream.Collection.t()} | {:error, Bunnyx.Error.t()}

Creates a collection with the given name.

delete(client, video_id)

@spec delete(t() | keyword(), String.t()) :: {:ok, nil} | {:error, Bunnyx.Error.t()}

Deletes a video.

delete_caption(client, video_id, srclang)

@spec delete_caption(t() | keyword(), String.t(), String.t()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Deletes a caption track from a video.

delete_collection(client, collection_id)

@spec delete_collection(t() | keyword(), String.t()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Deletes a collection.

fetch(client, attrs)

@spec fetch(
  t() | keyword(),
  keyword()
) :: {:ok, Bunnyx.Stream.Video.t()} | {:error, Bunnyx.Error.t()}

Fetches a video from a URL for the library to download and encode.

Attributes

  • :url (required) — source URL
  • :title — video title
  • :headers — headers to send with the fetch request

get(client, video_id)

@spec get(t() | keyword(), String.t()) ::
  {:ok, Bunnyx.Stream.Video.t()} | {:error, Bunnyx.Error.t()}

Fetches a video by GUID.

get_collection(client, collection_id)

@spec get_collection(t() | keyword(), String.t()) ::
  {:ok, Bunnyx.Stream.Collection.t()} | {:error, Bunnyx.Error.t()}

Fetches a collection by GUID.

heatmap(client, video_id)

@spec heatmap(t() | keyword(), String.t()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Returns the video watch heatmap data.

list(client, opts \\ [])

@spec list(
  t() | keyword(),
  keyword()
) ::
  {:ok,
   %{
     items: [Bunnyx.Stream.Video.t()],
     current_page: integer(),
     total_items: integer(),
     per_page: integer()
   }}
  | {:error, Bunnyx.Error.t()}

Lists videos in the library.

Options

  • :page — page number
  • :per_page — items per page
  • :search — search term
  • :collection — filter by collection ID
  • :order_by — sort field (default "date")

list_collections(client, opts \\ [])

@spec list_collections(
  t() | keyword(),
  keyword()
) ::
  {:ok,
   %{
     items: [Bunnyx.Stream.Collection.t()],
     current_page: integer(),
     total_items: integer(),
     per_page: integer()
   }}
  | {:error, Bunnyx.Error.t()}

Lists collections in the library.

Options

  • :page — page number
  • :per_page — items per page
  • :search — search term
  • :order_by — sort field
  • :include_thumbnails — include preview image URLs

new(opts)

@spec new(keyword()) :: t()

Creates a new Stream client.

Options

  • :api_key (required) — video library API key
  • :library_id (required) — video library ID
  • :receive_timeout — socket receive timeout in milliseconds (default 15_000)
  • :finch — a custom Finch pool name

oembed(client, url, opts \\ [])

@spec oembed(t() | keyword(), String.t(), keyword()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Returns oEmbed data for a video URL.

Options

  • :max_width — maximum embed width
  • :max_height — maximum embed height
  • :token — authentication token
  • :expires — token expiration timestamp

reencode(client, video_id)

@spec reencode(t() | keyword(), String.t()) :: {:ok, nil} | {:error, Bunnyx.Error.t()}

Triggers re-encoding of a video.

repackage(client, video_id, opts \\ [])

@spec repackage(t() | keyword(), String.t(), keyword()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Repackages a video.

Options

  • :keep_original_files — keep originals after repackaging (default true)

set_thumbnail(client, video_id, thumbnail_url)

@spec set_thumbnail(t() | keyword(), String.t(), String.t()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Sets a video thumbnail from a URL.

smart_actions(client, video_id, opts \\ [])

@spec smart_actions(t() | keyword(), String.t(), keyword()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Triggers AI-powered smart actions for a video.

Options

  • :generate_title — auto-generate title
  • :generate_description — auto-generate description
  • :generate_chapters — auto-generate chapters
  • :generate_moments — auto-generate moments
  • :source_language — source language code

transcribe(client, video_id, opts \\ [])

@spec transcribe(t() | keyword(), String.t(), keyword()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Triggers transcription for a video.

Options

  • :target_languages — list of ISO 639-1 language codes
  • :source_language — source language code
  • :generate_title — auto-generate title
  • :generate_description — auto-generate description
  • :generate_chapters — auto-generate chapters
  • :generate_moments — auto-generate moments
  • :force — force re-transcription

update(client, video_id, attrs)

@spec update(t() | keyword(), String.t(), Bunnyx.Params.attrs()) ::
  {:ok, Bunnyx.Stream.Video.t()} | {:error, Bunnyx.Error.t()}

Updates a video's metadata.

Attributes

  • :title — video title
  • :collection_id — collection ID
  • :chapters — list of chapter maps
  • :moments — list of moment maps
  • :meta_tags — list of meta tag maps

update_collection(client, collection_id, name)

@spec update_collection(t() | keyword(), String.t(), String.t()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Updates a collection's name.

upload(client, video_id, data)

@spec upload(t() | keyword(), String.t(), binary()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Uploads video data to a previously created video.

video_heatmap_data(client, video_id)

@spec video_heatmap_data(t() | keyword(), String.t()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Returns raw heatmap data for a video.

video_play_data(client, video_id)

@spec video_play_data(t() | keyword(), String.t()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Returns player configuration and playback URLs for a video.

video_resolutions(client, video_id)

@spec video_resolutions(t() | keyword(), String.t()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Returns resolution availability and encoding info for a video.

video_statistics(client, opts \\ [])

@spec video_statistics(
  t() | keyword(),
  keyword()
) :: {:ok, map()} | {:error, Bunnyx.Error.t()}

Returns video statistics for the library or a specific video.

Options

  • :date_from — start date (ISO 8601 string)
  • :date_to — end date (ISO 8601 string)
  • :hourly — group by hour instead of day
  • :video_guid — filter by specific video GUID

video_storage_info(client, video_id)

@spec video_storage_info(t() | keyword(), String.t()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Returns storage size breakdown for a video.