// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../core/resource'; import { APIPromise } from '../core/api-promise'; import { PagePromise, PaginatedResults, type PaginatedResultsParams } from '../core/pagination'; import { buildHeaders } from '../internal/headers'; import { RequestOptions } from '../internal/request-options'; import { path } from '../internal/utils/path'; export class Sources extends APIResource { /** * Create a new source from a media URL. The source will be analyzed to extract * metadata and generate a thumbnail. The source will be automatically deleted * after the data retention period. * * @example * ```ts * const source = await client.sources.create(); * ``` */ create(body: SourceCreateParams, options?: RequestOptions): APIPromise { return ( this._client.post('/api/sources', { body, ...options, __security: { projectAccessTokenAuth: true }, }) as APIPromise<{ data: Source }> )._thenUnwrap((obj) => obj.data); } /** * Retrieve details of a specific source by its ID, including metadata, media * properties, and associated jobs. * * @example * ```ts * const source = await client.sources.retrieve('sourceId'); * ``` */ retrieve(sourceID: string, options?: RequestOptions): APIPromise { return ( this._client.get(path`/api/sources/${sourceID}`, { ...options, __security: { projectAccessTokenAuth: true }, }) as APIPromise<{ data: Source }> )._thenUnwrap((obj) => obj.data); } /** * Retrieve a list of all sources with optional filtering and pagination. Supports * filtering by various media properties like duration, dimensions, codecs, etc. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const source of client.sources.list()) { * // ... * } * ``` */ list( query: SourceListParams | null | undefined = {}, options?: RequestOptions, ): PagePromise { return this._client.getAPIList('/api/sources', PaginatedResults, { query, ...options, __security: { projectAccessTokenAuth: true }, }); } /** * Delete a source. It will fail if there are processing jobs using this source. * * @example * ```ts * await client.sources.delete('sourceId'); * ``` */ delete(sourceID: string, options?: RequestOptions): APIPromise { return this._client.delete(path`/api/sources/${sourceID}`, { ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), __security: { projectAccessTokenAuth: true }, }); } } export type SourcesPaginatedResults = PaginatedResults; export interface Source { /** * Unique identifier of the source */ id: string; /** * Audio bitrate in bits per second */ audio_bitrate: number; /** * Audio codec used */ audio_codec: string; /** * Timestamp when the source was created */ created_at: string; /** * Device used to record the video */ device: string; /** * Duration of the video in seconds */ duration: number; /** * Height of the video in pixels */ height: number; /** * Additional metadata for the source */ metadata: { [key: string]: string }; /** * Size of the source file in bytes */ size: number; /** * Video bitrate in bits per second */ video_bitrate: number; /** * Video codec used */ video_codec: string; /** * Video framerate in frames per second */ video_framerate: number; /** * Width of the video in pixels */ width: number; /** * Exact object key in the configured bucket, 1 to 1024 UTF-8 bytes. The output * base_prefix is not added. */ path?: string; /** * Connected Storage belonging to this Project. */ storage_id?: string; /** * URL where the source video can be accessed */ url?: string; } export interface SourceCreateParams { /** * Metadata allows for additional information to be attached to the source, with a * maximum size of 2048 bytes. */ metadata?: { [key: string]: string }; /** * Storage input configuration. Provide this or url, never both. */ storage?: SourceCreateParams.Storage; /** * Url is the URL of the source, which must be a valid HTTP URL. */ url?: string; } export namespace SourceCreateParams { /** * Storage input configuration. Provide this or url, never both. */ export interface Storage { /** * Exact object key in the configured bucket, 1 to 1024 UTF-8 bytes. The output * base_prefix is not added. */ path: string; /** * Connected external storage belonging to this project. If omitted, uses the * project default storage, which must be external. The resolved storage ID is * saved on the source. */ id?: string; } } export interface SourceListParams extends PaginatedResultsParams { /** * Filter by source ID */ id?: string; /** * Filter by audio codec */ audio_codec?: string; created?: SourceListParams.Created; /** * Filter by device (apple/android) */ device?: 'apple' | 'android' | 'unknown'; duration?: SourceListParams.Duration; height?: SourceListParams.Height; /** * Filter by metadata */ metadata?: Array>; size?: SourceListParams.Size; /** * Filter by video codec */ video_codec?: string; width?: SourceListParams.Width; } export namespace SourceListParams { export interface Created { /** * Filter by creation date greater than or equal (UNIX epoch time) */ gte?: number; /** * Filter by creation date less than or equal (UNIX epoch time) */ lte?: number; /** * Sort by creation date (asc/desc) */ sort?: 'asc' | 'desc'; } export interface Duration { /** * Filter by exact duration */ eq?: number; /** * Filter by duration greater than */ gt?: number; /** * Filter by duration greater than or equal */ gte?: number; /** * Filter by duration less than */ lt?: number; /** * Filter by duration less than or equal */ lte?: number; } export interface Height { /** * Filter by exact height */ eq?: number; /** * Filter by height greater than */ gt?: number; /** * Filter by height greater than or equal */ gte?: number; /** * Filter by height less than */ lt?: number; /** * Filter by height less than or equal */ lte?: number; } export interface Size { /** * Filter by exact file size */ eq?: number; /** * Filter by file size greater than */ gt?: number; /** * Filter by file size greater than or equal */ gte?: number; /** * Filter by file size less than */ lt?: number; /** * Filter by file size less than or equal */ lte?: number; } export interface Width { /** * Filter by exact width */ eq?: number; /** * Filter by width greater than */ gt?: number; /** * Filter by width greater than or equal */ gte?: number; /** * Filter by width less than */ lt?: number; /** * Filter by width less than or equal */ lte?: number; } } export declare namespace Sources { export { type Source as Source, type SourcesPaginatedResults as SourcesPaginatedResults, type SourceCreateParams as SourceCreateParams, type SourceListParams as SourceListParams, }; }