Edit additional audio tracks on a video

Edits additional audio tracks on a video. Editing the default status of an audio track to `true` will mark all other audio tracks on the video default status to `false`.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Edit additional audio tracks on a video
8
 * Edits additional audio tracks on a video. Editing the default status of an audio track to `true` will mark all other audio tracks on the video default status to `false`.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  account_identifier: string,
13
  identifier: string,
14
  audio_identifier: string,
15
  body: { default?: boolean; label?: string; [k: string]: unknown }
16
) {
17
  const url = new URL(
18
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/stream/${identifier}/audio/${audio_identifier}`
19
  );
20

21
  const response = await fetch(url, {
22
    method: "PATCH",
23
    headers: {
24
      "X-AUTH-EMAIL": auth.email,
25
      "X-AUTH-KEY": auth.key,
26
      "Content-Type": "application/json",
27
      Authorization: "Bearer " + auth.token,
28
    },
29
    body: JSON.stringify(body),
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37