From 9f7821f8912672c67d0ffef7384a1c4df01cf276 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 26 Nov 2026 18:44:55 +0000 Subject: [PATCH 1/2] feat: videos --- CHANGELOG.md | 8 + README.md | 12 +- docs/examples/videos/create-caption.md | 20 + docs/examples/videos/create.md | 19 + docs/examples/videos/delete-caption.md | 16 + docs/examples/videos/delete-rendition.md | 16 + docs/examples/videos/delete.md | 15 + docs/examples/videos/get-caption-manifest.md | 17 + .../examples/videos/get-cmaf-dash-manifest.md | 15 + docs/examples/videos/get-cmaf-hls-manifest.md | 15 + docs/examples/videos/get-dash-manifest.md | 15 + docs/examples/videos/get-hls-manifest.md | 15 + docs/examples/videos/get-rendition.md | 16 + docs/examples/videos/get-thumbnail.md | 19 + docs/examples/videos/get-timeline.md | 15 + docs/examples/videos/get.md | 15 + docs/examples/videos/list-captions.md | 17 + docs/examples/videos/list-codecs.md | 13 + docs/examples/videos/list-renditions.md | 17 + docs/examples/videos/list.md | 16 + docs/examples/videos/update-caption.md | 21 + docs/examples/videos/update.md | 17 + package-lock.json | 4 +- package.json | 2 +- src/client.ts | 2 +- src/enums/video-caption-status.ts | 7 + src/enums/video-codec-id.ts | 5 + src/enums/video-output.ts | 5 + src/enums/video-rendition-status.ts | 8 + src/enums/video-timeline-status.ts | 7 + src/index.ts | 6 + src/models.ts | 329 +++ src/services/videos.ts | 2033 +++++++++++++++++ 33 files changed, 2747 insertions(+), 10 deletions(-) create mode 100644 docs/examples/videos/create-caption.md create mode 100644 docs/examples/videos/create.md create mode 100644 docs/examples/videos/delete-caption.md create mode 100644 docs/examples/videos/delete-rendition.md create mode 100644 docs/examples/videos/delete.md create mode 100644 docs/examples/videos/get-caption-manifest.md create mode 100644 docs/examples/videos/get-cmaf-dash-manifest.md create mode 100644 docs/examples/videos/get-cmaf-hls-manifest.md create mode 100644 docs/examples/videos/get-dash-manifest.md create mode 100644 docs/examples/videos/get-hls-manifest.md create mode 100644 docs/examples/videos/get-rendition.md create mode 100644 docs/examples/videos/get-thumbnail.md create mode 100644 docs/examples/videos/get-timeline.md create mode 100644 docs/examples/videos/get.md create mode 100644 docs/examples/videos/list-captions.md create mode 100644 docs/examples/videos/list-codecs.md create mode 100644 docs/examples/videos/list-renditions.md create mode 100644 docs/examples/videos/list.md create mode 100644 docs/examples/videos/update-caption.md create mode 100644 docs/examples/videos/update.md create mode 100644 src/enums/video-caption-status.ts create mode 100644 src/enums/video-codec-id.ts create mode 100644 src/enums/video-output.ts create mode 100644 src/enums/video-rendition-status.ts create mode 100644 src/enums/video-timeline-status.ts create mode 100644 src/services/videos.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index dbd7683..12e7fa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## 29.5.0 + +* Added: `videos` service to create, list, get, update and delete videos from files in Storage +* Added: `videos.listRenditions`, `getRendition` and `deleteRendition`; renditions are created from a server SDK or the Console +* Added: `videos.createCaption`, `listCaptions`, `updateCaption` and `deleteCaption` for subtitle tracks +* Added: `getHlsManifest`, `getDashManifest`, `getCmafHlsManifest`, `getCmafDashManifest`, `getCaptionManifest`, `getThumbnail` and `getTimeline` playback URLs, and `listCodecs` +* Added: `Video`, `VideoCodec`, `VideoRendition` and `VideoCaption` models, their list models, and the `VideoCodecId`, `VideoOutput`, `VideoRenditionStatus`, `VideoCaptionStatus` and `VideoTimelineStatus` enums + ## 29.4.0 * Added: Atlassian, Instagram, LINE, Linear, Netlify, Patreon, Railway, Reddit, Roblox, Strava, Vercel, VK and WorkOS to `OAuthProvider` diff --git a/README.md b/README.md index dba963f..816655e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ import { Client, Account } from 'appwrite'; ### CDN -Every release is published to `https://sdk.appwrite.io/web/29.4.0/`. +Every release is published to `https://sdk.appwrite.io/web/29.5.0/`. #### ES modules @@ -35,9 +35,9 @@ Each service, helper and enum is its own module, so the browser downloads only w ```html ``` @@ -46,7 +46,7 @@ Each service, helper and enum is its own module, so the browser downloads only w Add the script before any code that uses the SDK. It exposes every export on the global `Appwrite` object: ```html - + @@ -61,7 +61,7 @@ Add the script before any code that uses the SDK. It exposes every export on the The script tag build is also available from jsDelivr: ```html - + ``` ## Getting started diff --git a/docs/examples/videos/create-caption.md b/docs/examples/videos/create-caption.md new file mode 100644 index 0000000..890ee3d --- /dev/null +++ b/docs/examples/videos/create-caption.md @@ -0,0 +1,20 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.createCaption({ + videoId: '', + bucketId: '', + fileId: '', + name: '', + language: 'aar', + xdefault: false, // optional +}); + +console.log(result); +``` diff --git a/docs/examples/videos/create.md b/docs/examples/videos/create.md new file mode 100644 index 0000000..8f9b725 --- /dev/null +++ b/docs/examples/videos/create.md @@ -0,0 +1,19 @@ +```javascript +import { Client, Videos, Permission, Role } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.create({ + videoId: '', + bucketId: '', + fileId: '', + name: '', // optional + permissions: [Permission.read(Role.any())], // optional +}); + +console.log(result); +``` diff --git a/docs/examples/videos/delete-caption.md b/docs/examples/videos/delete-caption.md new file mode 100644 index 0000000..5c2729a --- /dev/null +++ b/docs/examples/videos/delete-caption.md @@ -0,0 +1,16 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.deleteCaption({ + videoId: '', + captionId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/delete-rendition.md b/docs/examples/videos/delete-rendition.md new file mode 100644 index 0000000..395ea69 --- /dev/null +++ b/docs/examples/videos/delete-rendition.md @@ -0,0 +1,16 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.deleteRendition({ + videoId: '', + renditionId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/delete.md b/docs/examples/videos/delete.md new file mode 100644 index 0000000..2c930e6 --- /dev/null +++ b/docs/examples/videos/delete.md @@ -0,0 +1,15 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.delete({ + videoId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/get-caption-manifest.md b/docs/examples/videos/get-caption-manifest.md new file mode 100644 index 0000000..053c474 --- /dev/null +++ b/docs/examples/videos/get-caption-manifest.md @@ -0,0 +1,17 @@ +```javascript +import { Client, Videos, VideoOutput } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = videos.getCaptionManifest({ + videoId: '', + output: VideoOutput.Hls, + captionId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/get-cmaf-dash-manifest.md b/docs/examples/videos/get-cmaf-dash-manifest.md new file mode 100644 index 0000000..952eff4 --- /dev/null +++ b/docs/examples/videos/get-cmaf-dash-manifest.md @@ -0,0 +1,15 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = videos.getCmafDashManifest({ + videoId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/get-cmaf-hls-manifest.md b/docs/examples/videos/get-cmaf-hls-manifest.md new file mode 100644 index 0000000..a45a8c1 --- /dev/null +++ b/docs/examples/videos/get-cmaf-hls-manifest.md @@ -0,0 +1,15 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = videos.getCmafHlsManifest({ + videoId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/get-dash-manifest.md b/docs/examples/videos/get-dash-manifest.md new file mode 100644 index 0000000..c929cfb --- /dev/null +++ b/docs/examples/videos/get-dash-manifest.md @@ -0,0 +1,15 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = videos.getDashManifest({ + videoId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/get-hls-manifest.md b/docs/examples/videos/get-hls-manifest.md new file mode 100644 index 0000000..1461167 --- /dev/null +++ b/docs/examples/videos/get-hls-manifest.md @@ -0,0 +1,15 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = videos.getHlsManifest({ + videoId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/get-rendition.md b/docs/examples/videos/get-rendition.md new file mode 100644 index 0000000..581c566 --- /dev/null +++ b/docs/examples/videos/get-rendition.md @@ -0,0 +1,16 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.getRendition({ + videoId: '', + renditionId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/get-thumbnail.md b/docs/examples/videos/get-thumbnail.md new file mode 100644 index 0000000..6812413 --- /dev/null +++ b/docs/examples/videos/get-thumbnail.md @@ -0,0 +1,19 @@ +```javascript +import { Client, Videos, ImageFormat } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = videos.getThumbnail({ + videoId: '', + thumbnailId: '', + width: 0, // optional + height: 0, // optional + output: ImageFormat.Jpg, // optional +}); + +console.log(result); +``` diff --git a/docs/examples/videos/get-timeline.md b/docs/examples/videos/get-timeline.md new file mode 100644 index 0000000..95bec28 --- /dev/null +++ b/docs/examples/videos/get-timeline.md @@ -0,0 +1,15 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = videos.getTimeline({ + videoId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/get.md b/docs/examples/videos/get.md new file mode 100644 index 0000000..b6a11b4 --- /dev/null +++ b/docs/examples/videos/get.md @@ -0,0 +1,15 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.get({ + videoId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/videos/list-captions.md b/docs/examples/videos/list-captions.md new file mode 100644 index 0000000..a61a2b8 --- /dev/null +++ b/docs/examples/videos/list-captions.md @@ -0,0 +1,17 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.listCaptions({ + videoId: '', + queries: [], // optional + total: false, // optional +}); + +console.log(result); +``` diff --git a/docs/examples/videos/list-codecs.md b/docs/examples/videos/list-codecs.md new file mode 100644 index 0000000..61281c9 --- /dev/null +++ b/docs/examples/videos/list-codecs.md @@ -0,0 +1,13 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.listCodecs(); + +console.log(result); +``` diff --git a/docs/examples/videos/list-renditions.md b/docs/examples/videos/list-renditions.md new file mode 100644 index 0000000..58fc769 --- /dev/null +++ b/docs/examples/videos/list-renditions.md @@ -0,0 +1,17 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.listRenditions({ + videoId: '', + queries: [], // optional + total: false, // optional +}); + +console.log(result); +``` diff --git a/docs/examples/videos/list.md b/docs/examples/videos/list.md new file mode 100644 index 0000000..b1970be --- /dev/null +++ b/docs/examples/videos/list.md @@ -0,0 +1,16 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.list({ + queries: [], // optional + total: false, // optional +}); + +console.log(result); +``` diff --git a/docs/examples/videos/update-caption.md b/docs/examples/videos/update-caption.md new file mode 100644 index 0000000..10010c0 --- /dev/null +++ b/docs/examples/videos/update-caption.md @@ -0,0 +1,21 @@ +```javascript +import { Client, Videos } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.updateCaption({ + videoId: '', + captionId: '', + bucketId: '', // optional + fileId: '', // optional + name: '', // optional + language: 'aar', // optional + xdefault: false, // optional +}); + +console.log(result); +``` diff --git a/docs/examples/videos/update.md b/docs/examples/videos/update.md new file mode 100644 index 0000000..ca16cfc --- /dev/null +++ b/docs/examples/videos/update.md @@ -0,0 +1,17 @@ +```javascript +import { Client, Videos, Permission, Role } from 'appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const videos = new Videos(client); + +const result = await videos.update({ + videoId: '', + name: '', // optional + permissions: [Permission.read(Role.any())], // optional +}); + +console.log(result); +``` diff --git a/package-lock.json b/package-lock.json index 1e54a88..261f2a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "appwrite", - "version": "29.4.0", + "version": "29.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "appwrite", - "version": "29.4.0", + "version": "29.5.0", "license": "BSD-3-Clause", "dependencies": { "buffer": "6.0.3", diff --git a/package.json b/package.json index a8670ad..e25228b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API", - "version": "29.4.0", + "version": "29.5.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index e6f5e9e..de85267 100644 --- a/src/client.ts +++ b/src/client.ts @@ -484,7 +484,7 @@ class Client { 'x-sdk-name': 'Web', 'x-sdk-platform': 'client', 'x-sdk-language': 'web', - 'x-sdk-version': '29.4.0', + 'x-sdk-version': '29.5.0', 'X-Appwrite-Response-Format': '2.7.2', }; diff --git a/src/enums/video-caption-status.ts b/src/enums/video-caption-status.ts new file mode 100644 index 0000000..d0e5098 --- /dev/null +++ b/src/enums/video-caption-status.ts @@ -0,0 +1,7 @@ +export enum VideoCaptionStatus { + Pending = 'pending', + Started = 'started', + Ready = 'ready', + Error = 'error', + Aborted = 'aborted', +} diff --git a/src/enums/video-codec-id.ts b/src/enums/video-codec-id.ts new file mode 100644 index 0000000..decfbc2 --- /dev/null +++ b/src/enums/video-codec-id.ts @@ -0,0 +1,5 @@ +export enum VideoCodecId { + H264 = 'h264', + Hevc = 'hevc', + Vp9 = 'vp9', +} diff --git a/src/enums/video-output.ts b/src/enums/video-output.ts new file mode 100644 index 0000000..80923ef --- /dev/null +++ b/src/enums/video-output.ts @@ -0,0 +1,5 @@ +export enum VideoOutput { + Hls = 'hls', + Dash = 'dash', + Cmaf = 'cmaf', +} diff --git a/src/enums/video-rendition-status.ts b/src/enums/video-rendition-status.ts new file mode 100644 index 0000000..5d37983 --- /dev/null +++ b/src/enums/video-rendition-status.ts @@ -0,0 +1,8 @@ +export enum VideoRenditionStatus { + Pending = 'pending', + Started = 'started', + Ended = 'ended', + Ready = 'ready', + Error = 'error', + Aborted = 'aborted', +} diff --git a/src/enums/video-timeline-status.ts b/src/enums/video-timeline-status.ts new file mode 100644 index 0000000..cddb893 --- /dev/null +++ b/src/enums/video-timeline-status.ts @@ -0,0 +1,7 @@ +export enum VideoTimelineStatus { + Pending = 'pending', + Started = 'started', + Ready = 'ready', + Skipped = 'skipped', + Error = 'error', +} diff --git a/src/index.ts b/src/index.ts index b935c63..b47ea77 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,7 @@ export { Storage } from './services/storage'; export { TablesDB } from './services/tables-db'; export { Teams } from './services/teams'; export { VectorsDB } from './services/vectors-db'; +export { Videos } from './services/videos'; export { Realtime } from './services/realtime'; export { Push } from './services/push'; export { Tracking } from './services/analytics-tracking'; @@ -74,6 +75,11 @@ export { BrowserPermission } from './enums/browser-permission'; export { ImageFormat } from './enums/image-format'; export { ExecutionMethod } from './enums/execution-method'; export { ImageGravity } from './enums/image-gravity'; +export { VideoOutput } from './enums/video-output'; export { ExecutionResourceType } from './enums/execution-resource-type'; export { ExecutionTrigger } from './enums/execution-trigger'; export { ExecutionStatus } from './enums/execution-status'; +export { VideoTimelineStatus } from './enums/video-timeline-status'; +export { VideoRenditionStatus } from './enums/video-rendition-status'; +export { VideoCodecId } from './enums/video-codec-id'; +export { VideoCaptionStatus } from './enums/video-caption-status'; diff --git a/src/models.ts b/src/models.ts index 7ec61b5..12d94ee 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1,6 +1,11 @@ import { ExecutionResourceType } from './enums/execution-resource-type'; import { ExecutionTrigger } from './enums/execution-trigger'; import { ExecutionStatus } from './enums/execution-status'; +import { VideoTimelineStatus } from './enums/video-timeline-status'; +import { VideoOutput } from './enums/video-output'; +import { VideoRenditionStatus } from './enums/video-rendition-status'; +import { VideoCodecId } from './enums/video-codec-id'; +import { VideoCaptionStatus } from './enums/video-caption-status'; /** * Appwrite Models @@ -94,6 +99,62 @@ export namespace Models { files: File[]; }; + /** + * Videos List + */ + export type VideoList = { + /** + * Total number of videos that matched your query. + */ + total: number; + /** + * List of videos. + */ + videos: Video[]; + }; + + /** + * Video Codecs List + */ + export type VideoCodecList = { + /** + * Total number of codecs that matched your query. + */ + total: number; + /** + * List of codecs. + */ + codecs: VideoCodec[]; + }; + + /** + * Video Renditions List + */ + export type VideoRenditionList = { + /** + * Total number of renditions that matched your query. + */ + total: number; + /** + * List of renditions. + */ + renditions: VideoRendition[]; + }; + + /** + * Video Captions List + */ + export type VideoCaptionList = { + /** + * Total number of captions that matched your query. + */ + total: number; + /** + * List of captions. + */ + captions: VideoCaption[]; + }; + /** * Teams List */ @@ -1682,6 +1743,274 @@ export namespace Models { expired: boolean; }; + /** + * Video + */ + export type Video = { + /** + * Video ID. + */ + $id: string; + /** + * Video creation time in ISO 8601 format. + */ + $createdAt: string; + /** + * Video update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Video permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + */ + $permissions: string[]; + /** + * Storage bucket ID holding the source file. + */ + bucketId: string; + /** + * Source file ID. + */ + fileId: string; + /** + * Video name. + */ + name: string; + /** + * Source file size in bytes. + */ + size: number; + /** + * Container format. + */ + format: string; + /** + * Video duration in milliseconds. + */ + duration: number; + /** + * Video width in pixels. + */ + width: number; + /** + * Video height in pixels. + */ + height: number; + /** + * Video aspect ratio. + */ + aspectRatio: string; + /** + * Video codec. + */ + videoCodec: string; + /** + * Video format. + */ + videoFormat: string; + /** + * Video format profile. + */ + videoFormatProfile: string; + /** + * Video bitrate in bits per second. + */ + videoBitRate: number; + /** + * Video frame rate in frames per second. + */ + videoFrameRate: number; + /** + * Video frame rate mode. + */ + videoFrameRateMode: string; + /** + * Audio codec. + */ + audioCodec: string; + /** + * Audio format. + */ + audioFormat: string; + /** + * Audio bitrate in bits per second. + */ + audioBitRate: number; + /** + * Audio sample rate in hertz. + */ + audioSampleRate: number; + /** + * Thumbnail timeline job status: one of `pending`, `started`, `ready`, `skipped` (source has no video track) or `error`. + */ + timelineStatus: VideoTimelineStatus; + /** + * Why the timeline job failed. Empty unless `timelineStatus` is `error`. + */ + timelineError: string; + }; + + /** + * Video codec + */ + export type VideoCodec = { + /** + * Codec ID. + */ + $id: string; + /** + * Codec display name. + */ + name: string; + /** + * Streaming output formats this codec may be packaged into. + */ + outputs: VideoOutput[]; + }; + + /** + * Video rendition + */ + export type VideoRendition = { + /** + * Rendition ID. + */ + $id: string; + /** + * Rendition creation time in ISO 8601 format. + */ + $createdAt: string; + /** + * Rendition update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Video ID. + */ + videoId: string; + /** + * Video profile ID this rendition was encoded against. + */ + profileId: string; + /** + * Rendition name, derived from its dimensions and bitrate. + */ + name: string; + /** + * Transcoding start time in ISO 8601 format. + */ + startedAt: string; + /** + * Transcoding end time in ISO 8601 format. + */ + endedAt: string; + /** + * Rendition width in pixels. + */ + width: number; + /** + * Rendition height in pixels. + */ + height: number; + /** + * Video bitrate in bits per second. + */ + videoBitRate: number; + /** + * Audio bitrate in bits per second. + */ + audioBitRate: number; + /** + * Longest segment duration in seconds. + */ + targetDuration: number; + /** + * Transcoding status: one of `pending`, `started`, `ended`, `ready`, `error` or `aborted`. + */ + status: VideoRenditionStatus; + /** + * Why the rendition failed or was aborted. Empty unless `status` is `error` or `aborted`. + */ + error: string; + /** + * Transcoding progress as a percentage, from 0 to 100. + */ + progress: number; + /** + * Streaming output format: `hls`, `dash`, or `cmaf`. + */ + output: VideoOutput; + /** + * Video encode codec snapshotted from the profile at create time: one of `h264`, `hevc`, or `vp9`. + */ + codec: VideoCodecId; + /** + * Stored rendition size in bytes. + */ + size: number; + }; + + /** + * Video caption + */ + export type VideoCaption = { + /** + * Caption ID. + */ + $id: string; + /** + * Caption creation time in ISO 8601 format. + */ + $createdAt: string; + /** + * Caption update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Video ID. + */ + videoId: string; + /** + * Storage bucket ID holding the caption file. + */ + bucketId: string; + /** + * Caption file ID. + */ + fileId: string; + /** + * Caption display name. + */ + name: string; + /** + * Caption ISO 639-2 language code. + */ + language: string; + /** + * Is this the default caption track? + */ + default: boolean; + /** + * Was this track auto-extracted from the source container? Extracted tracks have no backing file; extraction runs once per video, so a deleted extracted track is not re-created. + */ + embedded: boolean; + /** + * Longest segment duration in seconds. + */ + targetDuration: number; + /** + * Packaging status: one of `pending`, `started`, `ready`, `error` or `aborted`. + */ + status: VideoCaptionStatus; + /** + * Why the caption failed or was aborted. Empty unless `status` is `error` or `aborted`. + */ + error: string; + /** + * Stored caption size in bytes. + */ + size: number; + }; + /** * App */ diff --git a/src/services/videos.ts b/src/services/videos.ts new file mode 100644 index 0000000..27ab61e --- /dev/null +++ b/src/services/videos.ts @@ -0,0 +1,2033 @@ +import { + AppwriteException, + Client, + type Payload, + applyDefaults, + encodePath, +} from '../client'; +import type { Models } from '../models'; + +import { VideoOutput } from '../enums/video-output'; +import { ImageFormat } from '../enums/image-format'; +export class Videos { + client: Client; + + constructor(client: Client) { + this.client = client; + } + + /** + * Get a list of videos in the current project. Sessions receive only videos they can read according to each video's `$permissions`. API keys and admins receive the full project catalog. Playback uses the same document read ACL plus the `videos.play` (or `videos.read`) scope: a guest can stream a video that grants `read("any")` or `read("guests")` even though guests lack `videos.read` and will not see it in this list. + * + * + * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: bucketId, fileId, name, size, format, duration, width, height, videoCodec, videoBitRate, audioCodec, audioBitRate, search + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + */ + list(params?: { + queries?: string[]; + total?: boolean; + }): Promise; + /** + * Get a list of videos in the current project. Sessions receive only videos they can read according to each video's `$permissions`. API keys and admins receive the full project catalog. Playback uses the same document read ACL plus the `videos.play` (or `videos.read`) scope: a guest can stream a video that grants `read("any")` or `read("guests")` even though guests lack `videos.read` and will not see it in this list. + * + * + * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: bucketId, fileId, name, size, format, duration, width, height, videoCodec, videoBitRate, audioCodec, audioBitRate, search + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + list(queries?: string[], total?: boolean): Promise; + list( + paramsOrFirst?: { queries?: string[]; total?: boolean } | string[], + ...rest: [boolean?] + ): Promise { + let params: { queries?: string[]; total?: boolean }; + + if ( + (typeof paramsOrFirst === 'undefined' && rest.length === 0) || + (paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst)) + ) { + params = (paramsOrFirst || {}) as { + queries?: string[]; + total?: boolean; + }; + } else { + params = { + queries: paramsOrFirst as string[], + total: rest[0] as boolean, + }; + } + + const queries = params.queries; + const total = params.total; + + const apiPath = '/videos'; + const apiPayload: Payload = {}; + if (typeof queries !== 'undefined') { + apiPayload['queries'] = queries; + } + if (typeof total !== 'undefined') { + apiPayload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + accept: 'application/json', + }; + + const request = this.client.call('get', uri, apiHeaders, apiPayload); + const defaults = { + root: 'videoList', + models: { + videoList: { + defaults: { + total: 0, + videos: [], + }, + properties: { + videos: { + items: 'video', + }, + }, + }, + video: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + $permissions: [], + bucketId: '', + fileId: '', + name: '', + size: 0, + format: '', + duration: 0, + width: 0, + height: 0, + aspectRatio: '', + videoCodec: '', + videoFormat: '', + videoFormatProfile: '', + videoBitRate: 0, + videoFrameRate: 0, + videoFrameRateMode: '', + audioCodec: '', + audioFormat: '', + audioBitRate: 0, + audioSampleRate: 0, + timelineStatus: 'pending', + timelineError: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Create a video resource from an existing file in a storage bucket. The source file must be a video or audio file, and the caller must be able to read that file. Creating a video stores the document and queues timeline generation. The worker downloads the source, probes metadata, extracts embedded captions once, and deletes its working copy when finished. Sources with a video track also get a thumbnail timeline. Call create-rendition to package a streaming output. + * + * An optional `name` defaults to the source file name. An optional `permissions` array sets the video document ACL (list, get, update, delete, manage child resources, and playback). By default, only the current user is granted all permissions; API keys and admins create with empty permissions when omitted. Guests with `videos.play` can stream when the video grants them read (`read("any")` or `read("guests")`). + * + * Uploaded caption files stay listed alongside auto-extracted tracks for the same language; when the current default is an auto-extracted track with that code, the upload takes the default flag. + * + * + * @param {string} params.videoId - Video ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param {string} params.bucketId - Storage bucket unique ID holding the source file. + * @param {string} params.fileId - Source file unique ID. + * @param {string} params.name - Video name. Defaults to the source file name. Max length: 2048 chars. + * @param {string[] | null} params.permissions - An array of permission strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @throws {AppwriteException} + * @returns {Promise} + */ + create(params: { + videoId: string; + bucketId: string; + fileId: string; + name?: string; + permissions?: string[] | null; + }): Promise; + /** + * Create a video resource from an existing file in a storage bucket. The source file must be a video or audio file, and the caller must be able to read that file. Creating a video stores the document and queues timeline generation. The worker downloads the source, probes metadata, extracts embedded captions once, and deletes its working copy when finished. Sources with a video track also get a thumbnail timeline. Call create-rendition to package a streaming output. + * + * An optional `name` defaults to the source file name. An optional `permissions` array sets the video document ACL (list, get, update, delete, manage child resources, and playback). By default, only the current user is granted all permissions; API keys and admins create with empty permissions when omitted. Guests with `videos.play` can stream when the video grants them read (`read("any")` or `read("guests")`). + * + * Uploaded caption files stay listed alongside auto-extracted tracks for the same language; when the current default is an auto-extracted track with that code, the upload takes the default flag. + * + * + * @param {string} videoId - Video ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param {string} bucketId - Storage bucket unique ID holding the source file. + * @param {string} fileId - Source file unique ID. + * @param {string} name - Video name. Defaults to the source file name. Max length: 2048 chars. + * @param {string[] | null} permissions - An array of permission strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + create( + videoId: string, + bucketId: string, + fileId: string, + name?: string, + permissions?: string[] | null, + ): Promise; + create( + paramsOrFirst: + | { + videoId: string; + bucketId: string; + fileId: string; + name?: string; + permissions?: string[] | null; + } + | string, + ...rest: [string?, string?, string?, (string[] | null)?] + ): Promise { + let params: { + videoId: string; + bucketId: string; + fileId: string; + name?: string; + permissions?: string[] | null; + }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + bucketId: string; + fileId: string; + name?: string; + permissions?: string[] | null; + }; + } else { + params = { + videoId: paramsOrFirst as string, + bucketId: rest[0] as string, + fileId: rest[1] as string, + name: rest[2] as string, + permissions: rest[3] as string[] | null, + }; + } + + const videoId = params.videoId; + const bucketId = params.bucketId; + const fileId = params.fileId; + const name = params.name; + const permissions = params.permissions; + + if (typeof videoId === 'undefined') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + if (typeof bucketId === 'undefined') { + throw new AppwriteException( + 'Missing required parameter: "bucketId"', + ); + } + if (typeof fileId === 'undefined') { + throw new AppwriteException('Missing required parameter: "fileId"'); + } + const apiPath = '/videos'; + const apiPayload: Payload = {}; + if (typeof videoId !== 'undefined') { + apiPayload['videoId'] = videoId; + } + if (typeof bucketId !== 'undefined') { + apiPayload['bucketId'] = bucketId; + } + if (typeof fileId !== 'undefined') { + apiPayload['fileId'] = fileId; + } + if (typeof name !== 'undefined') { + apiPayload['name'] = name; + } + if (typeof permissions !== 'undefined') { + apiPayload['permissions'] = permissions; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }; + + const request = this.client.call('post', uri, apiHeaders, apiPayload); + const defaults = { + root: 'video', + models: { + video: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + $permissions: [], + bucketId: '', + fileId: '', + name: '', + size: 0, + format: '', + duration: 0, + width: 0, + height: 0, + aspectRatio: '', + videoCodec: '', + videoFormat: '', + videoFormatProfile: '', + videoBitRate: 0, + videoFrameRate: 0, + videoFrameRateMode: '', + audioCodec: '', + audioFormat: '', + audioBitRate: 0, + audioSampleRate: 0, + timelineStatus: 'pending', + timelineError: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Get a list of video encode codecs enabled on this instance. Each codec includes the output formats it may be packaged into. + * + * + * @throws {AppwriteException} + * @returns {Promise} + */ + listCodecs(): Promise { + const apiPath = '/videos/codecs'; + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + accept: 'application/json', + }; + + const request = this.client.call('get', uri, apiHeaders, apiPayload); + const defaults = { + root: 'videoCodecList', + models: { + videoCodecList: { + defaults: { + total: 0, + codecs: [], + }, + properties: { + codecs: { + items: 'videoCodec', + }, + }, + }, + videoCodec: { + defaults: { + $id: '', + name: '', + outputs: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Get a video by its unique ID. This endpoint response returns a JSON object with the video metadata. + * + * + * @param {string} params.videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {Promise} + */ + get(params: { videoId: string }): Promise; + /** + * Get a video by its unique ID. This endpoint response returns a JSON object with the video metadata. + * + * + * @param {string} videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + get(videoId: string): Promise; + get(paramsOrFirst: { videoId: string } | string): Promise { + let params: { videoId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { videoId: string }; + } else { + params = { + videoId: paramsOrFirst as string, + }; + } + + const videoId = params.videoId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + const apiPath = '/videos/{videoId}'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + accept: 'application/json', + }; + + const request = this.client.call('get', uri, apiHeaders, apiPayload); + const defaults = { + root: 'video', + models: { + video: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + $permissions: [], + bucketId: '', + fileId: '', + name: '', + size: 0, + format: '', + duration: 0, + width: 0, + height: 0, + aspectRatio: '', + videoCodec: '', + videoFormat: '', + videoFormatProfile: '', + videoBitRate: 0, + videoFrameRate: 0, + videoFrameRateMode: '', + audioCodec: '', + audioFormat: '', + audioBitRate: 0, + audioSampleRate: 0, + timelineStatus: 'pending', + timelineError: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Update a video's name, permissions, or both. Only the fields you pass are changed: omit `name` to keep the current name and `permissions` to keep the current ACL. The caller must hold update permission on the video document. The source file cannot be replaced; delete the video and create a new one to point at a different file. + * + * + * @param {string} params.videoId - Video unique ID. + * @param {string | null} params.name - Video name. Max length: 2048 chars. + * @param {string[] | null} params.permissions - An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @throws {AppwriteException} + * @returns {Promise} + */ + update(params: { + videoId: string; + name?: string | null; + permissions?: string[] | null; + }): Promise; + /** + * Update a video's name, permissions, or both. Only the fields you pass are changed: omit `name` to keep the current name and `permissions` to keep the current ACL. The caller must hold update permission on the video document. The source file cannot be replaced; delete the video and create a new one to point at a different file. + * + * + * @param {string} videoId - Video unique ID. + * @param {string | null} name - Video name. Max length: 2048 chars. + * @param {string[] | null} permissions - An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + update( + videoId: string, + name?: string | null, + permissions?: string[] | null, + ): Promise; + update( + paramsOrFirst: + | { + videoId: string; + name?: string | null; + permissions?: string[] | null; + } + | string, + ...rest: [(string | null)?, (string[] | null)?] + ): Promise { + let params: { + videoId: string; + name?: string | null; + permissions?: string[] | null; + }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + name?: string | null; + permissions?: string[] | null; + }; + } else { + params = { + videoId: paramsOrFirst as string, + name: rest[0] as string | null, + permissions: rest[1] as string[] | null, + }; + } + + const videoId = params.videoId; + const name = params.name; + const permissions = params.permissions; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + const apiPath = '/videos/{videoId}'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + if (typeof name !== 'undefined') { + apiPayload['name'] = name; + } + if (typeof permissions !== 'undefined') { + apiPayload['permissions'] = permissions; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }; + + const request = this.client.call('patch', uri, apiHeaders, apiPayload); + const defaults = { + root: 'video', + models: { + video: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + $permissions: [], + bucketId: '', + fileId: '', + name: '', + size: 0, + format: '', + duration: 0, + width: 0, + height: 0, + aspectRatio: '', + videoCodec: '', + videoFormat: '', + videoFormatProfile: '', + videoBitRate: 0, + videoFrameRate: 0, + videoFrameRateMode: '', + audioCodec: '', + audioFormat: '', + audioBitRate: 0, + audioSampleRate: 0, + timelineStatus: 'pending', + timelineError: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Delete a video by its unique ID. This also removes every rendition, caption, preview and transcoded artifact derived from it. Fails with `video_rendition_in_progress` while a rendition is started or ended, unless that rendition has not been updated within the rendition retention window. Fails with `video_timeline_in_progress` while the video's timeline is being generated, unless the video has not been updated within the same window. + * + * + * @param {string} params.videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + */ + delete(params: { videoId: string }): Promise<{}>; + /** + * Delete a video by its unique ID. This also removes every rendition, caption, preview and transcoded artifact derived from it. Fails with `video_rendition_in_progress` while a rendition is started or ended, unless that rendition has not been updated within the rendition retention window. Fails with `video_timeline_in_progress` while the video's timeline is being generated, unless the video has not been updated within the same window. + * + * + * @param {string} videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + * @deprecated Use the object parameter style method for a better developer experience. + */ + delete(videoId: string): Promise<{}>; + delete(paramsOrFirst: { videoId: string } | string): Promise<{}> { + let params: { videoId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { videoId: string }; + } else { + params = { + videoId: paramsOrFirst as string, + }; + } + + const videoId = params.videoId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + const apiPath = '/videos/{videoId}'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }; + + return this.client.call('delete', uri, apiHeaders, apiPayload); + } + + /** + * Get a list of all the caption tracks attached to a video. You can use the query params to filter your results. + * + * + * @param {string} params.videoId - Video unique ID. + * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, language, default, status, size, bucketId, fileId + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + */ + listCaptions(params: { + videoId: string; + queries?: string[]; + total?: boolean; + }): Promise; + /** + * Get a list of all the caption tracks attached to a video. You can use the query params to filter your results. + * + * + * @param {string} videoId - Video unique ID. + * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, language, default, status, size, bucketId, fileId + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + listCaptions( + videoId: string, + queries?: string[], + total?: boolean, + ): Promise; + listCaptions( + paramsOrFirst: + { videoId: string; queries?: string[]; total?: boolean } | string, + ...rest: [string[]?, boolean?] + ): Promise { + let params: { videoId: string; queries?: string[]; total?: boolean }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + queries?: string[]; + total?: boolean; + }; + } else { + params = { + videoId: paramsOrFirst as string, + queries: rest[0] as string[], + total: rest[1] as boolean, + }; + } + + const videoId = params.videoId; + const queries = params.queries; + const total = params.total; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + const apiPath = '/videos/{videoId}/captions'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + if (typeof queries !== 'undefined') { + apiPayload['queries'] = queries; + } + if (typeof total !== 'undefined') { + apiPayload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + accept: 'application/json', + }; + + const request = this.client.call('get', uri, apiHeaders, apiPayload); + const defaults = { + root: 'videoCaptionList', + models: { + videoCaptionList: { + defaults: { + total: 0, + captions: [], + }, + properties: { + captions: { + items: 'videoCaption', + }, + }, + }, + videoCaption: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + videoId: '', + bucketId: '', + fileId: '', + name: '', + language: '', + default: false, + embedded: false, + targetDuration: 0, + status: 'pending', + error: '', + size: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Add a caption track to a video from a WebVTT or SubRip file in a storage bucket. The file is normalised to WebVTT and segmented in the background. Subscribe to `videos.[videoId].captions.[captionId].update` for `started`, `ready`, and `error` status changes instead of only polling the caption document. + * + * Uploaded tracks are listed alongside auto-extracted embedded tracks (`embedded: true`). When the current default is an auto-extracted track for the same language code, the upload takes the default flag so players pick the authored file first. Auto-extracted tracks are never removed automatically — delete a track explicitly to remove it. Extraction runs once per video, so a deleted extracted track is not re-created. + * + * + * @param {string} params.videoId - Video unique ID. + * @param {string} params.bucketId - Storage bucket unique ID holding the caption file. + * @param {string} params.fileId - Caption file unique ID. + * @param {string} params.name - Caption display name. Allowed characters: a-z, A-Z, 0-9, space, and - . , ( ) _ ' + * @param {string} params.language - Caption ISO 639-2 three-letter language code. + * @param {boolean} params.xdefault - Make this the default caption track for the video. + * @throws {AppwriteException} + * @returns {Promise} + */ + createCaption(params: { + videoId: string; + bucketId: string; + fileId: string; + name: string; + language: string; + xdefault?: boolean; + }): Promise; + /** + * Add a caption track to a video from a WebVTT or SubRip file in a storage bucket. The file is normalised to WebVTT and segmented in the background. Subscribe to `videos.[videoId].captions.[captionId].update` for `started`, `ready`, and `error` status changes instead of only polling the caption document. + * + * Uploaded tracks are listed alongside auto-extracted embedded tracks (`embedded: true`). When the current default is an auto-extracted track for the same language code, the upload takes the default flag so players pick the authored file first. Auto-extracted tracks are never removed automatically — delete a track explicitly to remove it. Extraction runs once per video, so a deleted extracted track is not re-created. + * + * + * @param {string} videoId - Video unique ID. + * @param {string} bucketId - Storage bucket unique ID holding the caption file. + * @param {string} fileId - Caption file unique ID. + * @param {string} name - Caption display name. Allowed characters: a-z, A-Z, 0-9, space, and - . , ( ) _ ' + * @param {string} language - Caption ISO 639-2 three-letter language code. + * @param {boolean} xdefault - Make this the default caption track for the video. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + createCaption( + videoId: string, + bucketId: string, + fileId: string, + name: string, + language: string, + xdefault?: boolean, + ): Promise; + createCaption( + paramsOrFirst: + | { + videoId: string; + bucketId: string; + fileId: string; + name: string; + language: string; + xdefault?: boolean; + } + | string, + ...rest: [string?, string?, string?, string?, boolean?] + ): Promise { + let params: { + videoId: string; + bucketId: string; + fileId: string; + name: string; + language: string; + xdefault?: boolean; + }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + bucketId: string; + fileId: string; + name: string; + language: string; + xdefault?: boolean; + }; + } else { + params = { + videoId: paramsOrFirst as string, + bucketId: rest[0] as string, + fileId: rest[1] as string, + name: rest[2] as string, + language: rest[3] as string, + xdefault: rest[4] as boolean, + }; + } + + const videoId = params.videoId; + const bucketId = params.bucketId; + const fileId = params.fileId; + const name = params.name; + const language = params.language; + const xdefault = params.xdefault; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + if (typeof bucketId === 'undefined') { + throw new AppwriteException( + 'Missing required parameter: "bucketId"', + ); + } + if (typeof fileId === 'undefined') { + throw new AppwriteException('Missing required parameter: "fileId"'); + } + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + if (typeof language === 'undefined') { + throw new AppwriteException( + 'Missing required parameter: "language"', + ); + } + const apiPath = '/videos/{videoId}/captions'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + if (typeof bucketId !== 'undefined') { + apiPayload['bucketId'] = bucketId; + } + if (typeof fileId !== 'undefined') { + apiPayload['fileId'] = fileId; + } + if (typeof name !== 'undefined') { + apiPayload['name'] = name; + } + if (typeof language !== 'undefined') { + apiPayload['language'] = language; + } + if (typeof xdefault !== 'undefined') { + apiPayload['default'] = xdefault; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }; + + const request = this.client.call('post', uri, apiHeaders, apiPayload); + const defaults = { + root: 'videoCaption', + models: { + videoCaption: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + videoId: '', + bucketId: '', + fileId: '', + name: '', + language: '', + default: false, + embedded: false, + targetDuration: 0, + status: 'pending', + error: '', + size: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Update a caption track by its unique ID. Pass only `name`, `language`, and/or `default` to retag an extracted track (for example `und` → `heb` for Hebrew) without replacing the file. Changing `bucketId`/`fileId` re-packages the track in the background. + * + * + * @param {string} params.videoId - Video unique ID. + * @param {string} params.captionId - Caption unique ID. + * @param {string} params.bucketId - Storage bucket unique ID holding the caption file. Omit together with fileId to only update name, language, or default. + * @param {string} params.fileId - Caption file unique ID. Omit together with bucketId to only update name, language, or default. + * @param {string} params.name - Caption display name. Allowed characters: a-z, A-Z, 0-9, space, and - . , ( ) _ ' + * @param {string} params.language - Caption ISO 639-2 three-letter language code (for example `heb` for Hebrew). + * @param {boolean | null} params.xdefault - Make this the default caption track for the video. Omit to leave unchanged. + * @throws {AppwriteException} + * @returns {Promise} + */ + updateCaption(params: { + videoId: string; + captionId: string; + bucketId?: string; + fileId?: string; + name?: string; + language?: string; + xdefault?: boolean | null; + }): Promise; + /** + * Update a caption track by its unique ID. Pass only `name`, `language`, and/or `default` to retag an extracted track (for example `und` → `heb` for Hebrew) without replacing the file. Changing `bucketId`/`fileId` re-packages the track in the background. + * + * + * @param {string} videoId - Video unique ID. + * @param {string} captionId - Caption unique ID. + * @param {string} bucketId - Storage bucket unique ID holding the caption file. Omit together with fileId to only update name, language, or default. + * @param {string} fileId - Caption file unique ID. Omit together with bucketId to only update name, language, or default. + * @param {string} name - Caption display name. Allowed characters: a-z, A-Z, 0-9, space, and - . , ( ) _ ' + * @param {string} language - Caption ISO 639-2 three-letter language code (for example `heb` for Hebrew). + * @param {boolean | null} xdefault - Make this the default caption track for the video. Omit to leave unchanged. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + updateCaption( + videoId: string, + captionId: string, + bucketId?: string, + fileId?: string, + name?: string, + language?: string, + xdefault?: boolean | null, + ): Promise; + updateCaption( + paramsOrFirst: + | { + videoId: string; + captionId: string; + bucketId?: string; + fileId?: string; + name?: string; + language?: string; + xdefault?: boolean | null; + } + | string, + ...rest: [ + string?, + string?, + string?, + string?, + string?, + (boolean | null)?, + ] + ): Promise { + let params: { + videoId: string; + captionId: string; + bucketId?: string; + fileId?: string; + name?: string; + language?: string; + xdefault?: boolean | null; + }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + captionId: string; + bucketId?: string; + fileId?: string; + name?: string; + language?: string; + xdefault?: boolean | null; + }; + } else { + params = { + videoId: paramsOrFirst as string, + captionId: rest[0] as string, + bucketId: rest[1] as string, + fileId: rest[2] as string, + name: rest[3] as string, + language: rest[4] as string, + xdefault: rest[5] as boolean | null, + }; + } + + const videoId = params.videoId; + const captionId = params.captionId; + const bucketId = params.bucketId; + const fileId = params.fileId; + const name = params.name; + const language = params.language; + const xdefault = params.xdefault; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + if (typeof captionId === 'undefined' || captionId === '') { + throw new AppwriteException( + 'Missing required parameter: "captionId"', + ); + } + const apiPath = '/videos/{videoId}/captions/{captionId}' + .replace('{videoId}', encodePath(videoId)) + .replace('{captionId}', encodePath(captionId)); + const apiPayload: Payload = {}; + if (typeof bucketId !== 'undefined') { + apiPayload['bucketId'] = bucketId; + } + if (typeof fileId !== 'undefined') { + apiPayload['fileId'] = fileId; + } + if (typeof name !== 'undefined') { + apiPayload['name'] = name; + } + if (typeof language !== 'undefined') { + apiPayload['language'] = language; + } + if (typeof xdefault !== 'undefined') { + apiPayload['default'] = xdefault; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }; + + const request = this.client.call('patch', uri, apiHeaders, apiPayload); + const defaults = { + root: 'videoCaption', + models: { + videoCaption: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + videoId: '', + bucketId: '', + fileId: '', + name: '', + language: '', + default: false, + embedded: false, + targetDuration: 0, + status: 'pending', + error: '', + size: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Delete a caption track by its unique ID, along with its packaged segments. + * + * + * @param {string} params.videoId - Video unique ID. + * @param {string} params.captionId - Caption unique ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + */ + deleteCaption(params: { videoId: string; captionId: string }): Promise<{}>; + /** + * Delete a caption track by its unique ID, along with its packaged segments. + * + * + * @param {string} videoId - Video unique ID. + * @param {string} captionId - Caption unique ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + * @deprecated Use the object parameter style method for a better developer experience. + */ + deleteCaption(videoId: string, captionId: string): Promise<{}>; + deleteCaption( + paramsOrFirst: { videoId: string; captionId: string } | string, + ...rest: [string?] + ): Promise<{}> { + let params: { videoId: string; captionId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + captionId: string; + }; + } else { + params = { + videoId: paramsOrFirst as string, + captionId: rest[0] as string, + }; + } + + const videoId = params.videoId; + const captionId = params.captionId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + if (typeof captionId === 'undefined' || captionId === '') { + throw new AppwriteException( + 'Missing required parameter: "captionId"', + ); + } + const apiPath = '/videos/{videoId}/captions/{captionId}' + .replace('{videoId}', encodePath(videoId)) + .replace('{captionId}', encodePath(captionId)); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }; + + return this.client.call('delete', uri, apiHeaders, apiPayload); + } + + /** + * Get the top-level streaming manifest for a video output: an HLS master playlist (`master.m3u8`) or a DASH MPD (`master.mpd`). Hand this URL to a player to begin adaptive playback. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. A video with `read("any")` or `read("guests")` is playable without a session. + * + * For CMAF renditions, use `getCmafHlsManifest` or `getCmafDashManifest`. Both masters point at the same fMP4 segment set. + * + * + * @param {string} params.videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {string} + */ + getCmafHlsManifest(params: { videoId: string }): string; + /** + * Get the top-level streaming manifest for a video output: an HLS master playlist (`master.m3u8`) or a DASH MPD (`master.mpd`). Hand this URL to a player to begin adaptive playback. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. A video with `read("any")` or `read("guests")` is playable without a session. + * + * For CMAF renditions, use `getCmafHlsManifest` or `getCmafDashManifest`. Both masters point at the same fMP4 segment set. + * + * + * @param {string} videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {string} + * @deprecated Use the object parameter style method for a better developer experience. + */ + getCmafHlsManifest(videoId: string): string; + getCmafHlsManifest(paramsOrFirst: { videoId: string } | string): string { + let params: { videoId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { videoId: string }; + } else { + params = { + videoId: paramsOrFirst as string, + }; + } + + const videoId = params.videoId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + const apiPath = '/videos/{videoId}/outputs/cmaf/master.m3u8'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + apiPayload['project'] = this.client.config.project; + apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; + + for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { + uri.searchParams.append(key, value); + } + + return uri.toString(); + } + + /** + * Get the top-level streaming manifest for a video output: an HLS master playlist (`master.m3u8`) or a DASH MPD (`master.mpd`). Hand this URL to a player to begin adaptive playback. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. A video with `read("any")` or `read("guests")` is playable without a session. + * + * For CMAF renditions, use `getCmafHlsManifest` or `getCmafDashManifest`. Both masters point at the same fMP4 segment set. + * + * + * @param {string} params.videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {string} + */ + getCmafDashManifest(params: { videoId: string }): string; + /** + * Get the top-level streaming manifest for a video output: an HLS master playlist (`master.m3u8`) or a DASH MPD (`master.mpd`). Hand this URL to a player to begin adaptive playback. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. A video with `read("any")` or `read("guests")` is playable without a session. + * + * For CMAF renditions, use `getCmafHlsManifest` or `getCmafDashManifest`. Both masters point at the same fMP4 segment set. + * + * + * @param {string} videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {string} + * @deprecated Use the object parameter style method for a better developer experience. + */ + getCmafDashManifest(videoId: string): string; + getCmafDashManifest(paramsOrFirst: { videoId: string } | string): string { + let params: { videoId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { videoId: string }; + } else { + params = { + videoId: paramsOrFirst as string, + }; + } + + const videoId = params.videoId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + const apiPath = '/videos/{videoId}/outputs/cmaf/master.mpd'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + apiPayload['project'] = this.client.config.project; + apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; + + for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { + uri.searchParams.append(key, value); + } + + return uri.toString(); + } + + /** + * Get the top-level streaming manifest for a video output: an HLS master playlist (`master.m3u8`) or a DASH MPD (`master.mpd`). Hand this URL to a player to begin adaptive playback. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. A video with `read("any")` or `read("guests")` is playable without a session. + * + * For CMAF renditions, use `getCmafHlsManifest` or `getCmafDashManifest`. Both masters point at the same fMP4 segment set. + * + * + * @param {string} params.videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {string} + */ + getDashManifest(params: { videoId: string }): string; + /** + * Get the top-level streaming manifest for a video output: an HLS master playlist (`master.m3u8`) or a DASH MPD (`master.mpd`). Hand this URL to a player to begin adaptive playback. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. A video with `read("any")` or `read("guests")` is playable without a session. + * + * For CMAF renditions, use `getCmafHlsManifest` or `getCmafDashManifest`. Both masters point at the same fMP4 segment set. + * + * + * @param {string} videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {string} + * @deprecated Use the object parameter style method for a better developer experience. + */ + getDashManifest(videoId: string): string; + getDashManifest(paramsOrFirst: { videoId: string } | string): string { + let params: { videoId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { videoId: string }; + } else { + params = { + videoId: paramsOrFirst as string, + }; + } + + const videoId = params.videoId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + const apiPath = '/videos/{videoId}/outputs/dash/master.mpd'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + apiPayload['project'] = this.client.config.project; + apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; + + for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { + uri.searchParams.append(key, value); + } + + return uri.toString(); + } + + /** + * Get the top-level streaming manifest for a video output: an HLS master playlist (`master.m3u8`) or a DASH MPD (`master.mpd`). Hand this URL to a player to begin adaptive playback. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. A video with `read("any")` or `read("guests")` is playable without a session. + * + * For CMAF renditions, use `getCmafHlsManifest` or `getCmafDashManifest`. Both masters point at the same fMP4 segment set. + * + * + * @param {string} params.videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {string} + */ + getHlsManifest(params: { videoId: string }): string; + /** + * Get the top-level streaming manifest for a video output: an HLS master playlist (`master.m3u8`) or a DASH MPD (`master.mpd`). Hand this URL to a player to begin adaptive playback. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. A video with `read("any")` or `read("guests")` is playable without a session. + * + * For CMAF renditions, use `getCmafHlsManifest` or `getCmafDashManifest`. Both masters point at the same fMP4 segment set. + * + * + * @param {string} videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {string} + * @deprecated Use the object parameter style method for a better developer experience. + */ + getHlsManifest(videoId: string): string; + getHlsManifest(paramsOrFirst: { videoId: string } | string): string { + let params: { videoId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { videoId: string }; + } else { + params = { + videoId: paramsOrFirst as string, + }; + } + + const videoId = params.videoId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + const apiPath = '/videos/{videoId}/outputs/hls/master.m3u8'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + apiPayload['project'] = this.client.config.project; + apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; + + for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { + uri.searchParams.append(key, value); + } + + return uri.toString(); + } + + /** + * Get the playable caption resource for a video output: an HLS captions playlist, or the WebVTT file itself for DASH. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. + * + * + * @param {string} params.videoId - Video unique ID. + * @param {VideoOutput} params.output - Streaming output format. + * @param {string} params.captionId - Caption unique ID. + * @throws {AppwriteException} + * @returns {string} + */ + getCaptionManifest(params: { + videoId: string; + output: VideoOutput; + captionId: string; + }): string; + /** + * Get the playable caption resource for a video output: an HLS captions playlist, or the WebVTT file itself for DASH. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. + * + * + * @param {string} videoId - Video unique ID. + * @param {VideoOutput} output - Streaming output format. + * @param {string} captionId - Caption unique ID. + * @throws {AppwriteException} + * @returns {string} + * @deprecated Use the object parameter style method for a better developer experience. + */ + getCaptionManifest( + videoId: string, + output: VideoOutput, + captionId: string, + ): string; + getCaptionManifest( + paramsOrFirst: + | { videoId: string; output: VideoOutput; captionId: string } + | string, + ...rest: [VideoOutput?, string?] + ): string { + let params: { videoId: string; output: VideoOutput; captionId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + output: VideoOutput; + captionId: string; + }; + } else { + params = { + videoId: paramsOrFirst as string, + output: rest[0] as VideoOutput, + captionId: rest[1] as string, + }; + } + + const videoId = params.videoId; + const output = params.output; + const captionId = params.captionId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + if (typeof output === 'undefined') { + throw new AppwriteException('Missing required parameter: "output"'); + } + if (typeof captionId === 'undefined' || captionId === '') { + throw new AppwriteException( + 'Missing required parameter: "captionId"', + ); + } + const apiPath = + '/videos/{videoId}/outputs/{output}/captions/{captionId}/manifest' + .replace('{videoId}', encodePath(videoId)) + .replace('{output}', encodePath(output)) + .replace('{captionId}', encodePath(captionId)); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + apiPayload['project'] = this.client.config.project; + apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; + + for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { + uri.searchParams.append(key, value); + } + + return uri.toString(); + } + + /** + * Get a list of all the renditions of a video. You can use the query params to filter your results. + * + * + * @param {string} params.videoId - Video unique ID. + * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: profileId, name, status, output, codec, width, height, videoBitRate, audioBitRate, size, startedAt, endedAt + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + */ + listRenditions(params: { + videoId: string; + queries?: string[]; + total?: boolean; + }): Promise; + /** + * Get a list of all the renditions of a video. You can use the query params to filter your results. + * + * + * @param {string} videoId - Video unique ID. + * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: profileId, name, status, output, codec, width, height, videoBitRate, audioBitRate, size, startedAt, endedAt + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + listRenditions( + videoId: string, + queries?: string[], + total?: boolean, + ): Promise; + listRenditions( + paramsOrFirst: + { videoId: string; queries?: string[]; total?: boolean } | string, + ...rest: [string[]?, boolean?] + ): Promise { + let params: { videoId: string; queries?: string[]; total?: boolean }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + queries?: string[]; + total?: boolean; + }; + } else { + params = { + videoId: paramsOrFirst as string, + queries: rest[0] as string[], + total: rest[1] as boolean, + }; + } + + const videoId = params.videoId; + const queries = params.queries; + const total = params.total; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + const apiPath = '/videos/{videoId}/renditions'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + if (typeof queries !== 'undefined') { + apiPayload['queries'] = queries; + } + if (typeof total !== 'undefined') { + apiPayload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + accept: 'application/json', + }; + + const request = this.client.call('get', uri, apiHeaders, apiPayload); + const defaults = { + root: 'videoRenditionList', + models: { + videoRenditionList: { + defaults: { + total: 0, + renditions: [], + }, + properties: { + renditions: { + items: 'videoRendition', + }, + }, + }, + videoRendition: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + videoId: '', + profileId: '', + name: '', + startedAt: '', + endedAt: '', + width: 0, + height: 0, + videoBitRate: 0, + audioBitRate: 0, + targetDuration: 0, + status: 'pending', + error: '', + progress: 0, + output: 'hls', + codec: 'h264', + size: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Get a rendition by its unique ID, including its current transcoding status and progress. + * + * + * @param {string} params.videoId - Video unique ID. + * @param {string} params.renditionId - Rendition unique ID. + * @throws {AppwriteException} + * @returns {Promise} + */ + getRendition(params: { + videoId: string; + renditionId: string; + }): Promise; + /** + * Get a rendition by its unique ID, including its current transcoding status and progress. + * + * + * @param {string} videoId - Video unique ID. + * @param {string} renditionId - Rendition unique ID. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + getRendition( + videoId: string, + renditionId: string, + ): Promise; + getRendition( + paramsOrFirst: { videoId: string; renditionId: string } | string, + ...rest: [string?] + ): Promise { + let params: { videoId: string; renditionId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + renditionId: string; + }; + } else { + params = { + videoId: paramsOrFirst as string, + renditionId: rest[0] as string, + }; + } + + const videoId = params.videoId; + const renditionId = params.renditionId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + if (typeof renditionId === 'undefined' || renditionId === '') { + throw new AppwriteException( + 'Missing required parameter: "renditionId"', + ); + } + const apiPath = '/videos/{videoId}/renditions/{renditionId}' + .replace('{videoId}', encodePath(videoId)) + .replace('{renditionId}', encodePath(renditionId)); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + accept: 'application/json', + }; + + const request = this.client.call('get', uri, apiHeaders, apiPayload); + const defaults = { + root: 'videoRendition', + models: { + videoRendition: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + videoId: '', + profileId: '', + name: '', + startedAt: '', + endedAt: '', + width: 0, + height: 0, + videoBitRate: 0, + audioBitRate: 0, + targetDuration: 0, + status: 'pending', + error: '', + progress: 0, + output: 'hls', + codec: 'h264', + size: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Delete a rendition by its unique ID, along with its packaged segments and transcoded output. Fails with `video_rendition_in_progress` while the rendition is started or ended, unless it has not been updated within the rendition retention window. + * + * + * @param {string} params.videoId - Video unique ID. + * @param {string} params.renditionId - Rendition unique ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + */ + deleteRendition(params: { + videoId: string; + renditionId: string; + }): Promise<{}>; + /** + * Delete a rendition by its unique ID, along with its packaged segments and transcoded output. Fails with `video_rendition_in_progress` while the rendition is started or ended, unless it has not been updated within the rendition retention window. + * + * + * @param {string} videoId - Video unique ID. + * @param {string} renditionId - Rendition unique ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + * @deprecated Use the object parameter style method for a better developer experience. + */ + deleteRendition(videoId: string, renditionId: string): Promise<{}>; + deleteRendition( + paramsOrFirst: { videoId: string; renditionId: string } | string, + ...rest: [string?] + ): Promise<{}> { + let params: { videoId: string; renditionId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + renditionId: string; + }; + } else { + params = { + videoId: paramsOrFirst as string, + renditionId: rest[0] as string, + }; + } + + const videoId = params.videoId; + const renditionId = params.renditionId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + if (typeof renditionId === 'undefined' || renditionId === '') { + throw new AppwriteException( + 'Missing required parameter: "renditionId"', + ); + } + const apiPath = '/videos/{videoId}/renditions/{renditionId}' + .replace('{videoId}', encodePath(videoId)) + .replace('{renditionId}', encodePath(renditionId)); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }; + + return this.client.call('delete', uri, apiHeaders, apiPayload); + } + + /** + * Get a single thumbnail sheet from a video's timeline as an image. You can resize the returned image and choose its output format. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. + * + * + * @param {string} params.videoId - Video unique ID. + * @param {string} params.thumbnailId - Thumbnail unique ID. + * @param {number} params.width - Resize thumbnail image width, in pixels. + * @param {number} params.height - Resize thumbnail image height, in pixels. + * @param {ImageFormat} params.output - Output format type (jpeg, jpg, png, gif and webp). + * @throws {AppwriteException} + * @returns {string} + */ + getThumbnail(params: { + videoId: string; + thumbnailId: string; + width?: number; + height?: number; + output?: ImageFormat; + }): string; + /** + * Get a single thumbnail sheet from a video's timeline as an image. You can resize the returned image and choose its output format. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. + * + * + * @param {string} videoId - Video unique ID. + * @param {string} thumbnailId - Thumbnail unique ID. + * @param {number} width - Resize thumbnail image width, in pixels. + * @param {number} height - Resize thumbnail image height, in pixels. + * @param {ImageFormat} output - Output format type (jpeg, jpg, png, gif and webp). + * @throws {AppwriteException} + * @returns {string} + * @deprecated Use the object parameter style method for a better developer experience. + */ + getThumbnail( + videoId: string, + thumbnailId: string, + width?: number, + height?: number, + output?: ImageFormat, + ): string; + getThumbnail( + paramsOrFirst: + | { + videoId: string; + thumbnailId: string; + width?: number; + height?: number; + output?: ImageFormat; + } + | string, + ...rest: [string?, number?, number?, ImageFormat?] + ): string { + let params: { + videoId: string; + thumbnailId: string; + width?: number; + height?: number; + output?: ImageFormat; + }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + videoId: string; + thumbnailId: string; + width?: number; + height?: number; + output?: ImageFormat; + }; + } else { + params = { + videoId: paramsOrFirst as string, + thumbnailId: rest[0] as string, + width: rest[1] as number, + height: rest[2] as number, + output: rest[3] as ImageFormat, + }; + } + + const videoId = params.videoId; + const thumbnailId = params.thumbnailId; + const width = params.width; + const height = params.height; + const output = params.output; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + if (typeof thumbnailId === 'undefined' || thumbnailId === '') { + throw new AppwriteException( + 'Missing required parameter: "thumbnailId"', + ); + } + const apiPath = '/videos/{videoId}/thumbnails/{thumbnailId}' + .replace('{videoId}', encodePath(videoId)) + .replace('{thumbnailId}', encodePath(thumbnailId)); + const apiPayload: Payload = {}; + if (typeof width !== 'undefined') { + apiPayload['width'] = width; + } + if (typeof height !== 'undefined') { + apiPayload['height'] = height; + } + if (typeof output !== 'undefined') { + apiPayload['output'] = output; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + apiPayload['project'] = this.client.config.project; + apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; + + for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { + uri.searchParams.append(key, value); + } + + return uri.toString(); + } + + /** + * Get the WebVTT thumbnail timeline for a video, used to render scrubbing thumbnails in a player. Timeline generation is queued when the video is created. Subscribe to `videos.[videoId].timelines.update` for probe and terminal updates, or poll this endpoint until it returns a WebVTT document. Audio-only sources produce no timeline and this endpoint returns `video_timelines_not_found`. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. A video with `read("any")` or `read("guests")` is playable without a session. + * + * + * @param {string} params.videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {string} + */ + getTimeline(params: { videoId: string }): string; + /** + * Get the WebVTT thumbnail timeline for a video, used to render scrubbing thumbnails in a player. Timeline generation is queued when the video is created. Subscribe to `videos.[videoId].timelines.update` for probe and terminal updates, or poll this endpoint until it returns a WebVTT document. Audio-only sources produce no timeline and this endpoint returns `video_timelines_not_found`. + * + * Guests can request this URL when they hold `videos.play` (or `videos.read`) **and** the video document grants them read. A video with `read("any")` or `read("guests")` is playable without a session. + * + * + * @param {string} videoId - Video unique ID. + * @throws {AppwriteException} + * @returns {string} + * @deprecated Use the object parameter style method for a better developer experience. + */ + getTimeline(videoId: string): string; + getTimeline(paramsOrFirst: { videoId: string } | string): string { + let params: { videoId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { videoId: string }; + } else { + params = { + videoId: paramsOrFirst as string, + }; + } + + const videoId = params.videoId; + + if (typeof videoId === 'undefined' || videoId === '') { + throw new AppwriteException( + 'Missing required parameter: "videoId"', + ); + } + const apiPath = '/videos/{videoId}/timeline'.replace( + '{videoId}', + encodePath(videoId), + ); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + apiPayload['project'] = this.client.config.project; + apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; + + for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { + uri.searchParams.append(key, value); + } + + return uri.toString(); + } +} From 9581f4a92b2660e6e21152551c0e36fce1fd0775 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 26 Nov 2026 20:32:08 +0000 Subject: [PATCH 2/2] fix: send the selected environment on Videos playback URLs --- src/services/videos.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/services/videos.ts b/src/services/videos.ts index 27ab61e..7289daf 100644 --- a/src/services/videos.ts +++ b/src/services/videos.ts @@ -1233,6 +1233,7 @@ export class Videos { const uri = new URL(this.client.config.endpoint + apiPath); apiPayload['project'] = this.client.config.project; + apiPayload['environment'] = this.client.config.environment; apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { @@ -1299,6 +1300,7 @@ export class Videos { const uri = new URL(this.client.config.endpoint + apiPath); apiPayload['project'] = this.client.config.project; + apiPayload['environment'] = this.client.config.environment; apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { @@ -1365,6 +1367,7 @@ export class Videos { const uri = new URL(this.client.config.endpoint + apiPath); apiPayload['project'] = this.client.config.project; + apiPayload['environment'] = this.client.config.environment; apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { @@ -1431,6 +1434,7 @@ export class Videos { const uri = new URL(this.client.config.endpoint + apiPath); apiPayload['project'] = this.client.config.project; + apiPayload['environment'] = this.client.config.environment; apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { @@ -1527,6 +1531,7 @@ export class Videos { const uri = new URL(this.client.config.endpoint + apiPath); apiPayload['project'] = this.client.config.project; + apiPayload['environment'] = this.client.config.environment; apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { @@ -1960,6 +1965,7 @@ export class Videos { const uri = new URL(this.client.config.endpoint + apiPath); apiPayload['project'] = this.client.config.project; + apiPayload['environment'] = this.client.config.environment; apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Client.flatten(apiPayload))) { @@ -2022,6 +2028,7 @@ export class Videos { const uri = new URL(this.client.config.endpoint + apiPath); apiPayload['project'] = this.client.config.project; + apiPayload['environment'] = this.client.config.environment; apiPayload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Client.flatten(apiPayload))) {