@api.video/nodejs-sdk

中文文档
1.10.4发布于 2021/12/09Apache-2.0CommonJS近 30 天下载 2109

Nodejs SDK for api.video

原始使用文档
文档目录17 节
  1. DEPRECATION WARNING: this SDK will soon be deprecated and w…
  2. Installation
  3. Usage
  4. Full API
  5. Full API Details Implementation
  6. Videos
  7. Players
  8. Captions
  9. Chapters
  10. Lives
  11. AnalyticsVideo
  12. AnalyticsLive
  13. AnalyticsSessionEvent
  14. Tokens
  15. Account
  16. More on api.video
  17. Test

badge

badge

badge

api.video is an API that encodes on the go to facilitate immediate playback, enhancing viewer streaming experiences across multiple devices and platforms. You can stream live or on-demand online videos within minutes.

api.video NodeJS SDK

DEPRECATION WARNING: this SDK will soon be deprecated and will no longer be maintained. It has been replaced by the NodeJS API client. Please use it instead.

Scrutinizer Code Quality Build Status

The api.video web-service helps you put video on the web without the hassle. This documentation helps you use the corresponding NodeJS client.

Installation

npm install @api.video/nodejs-sdk

Usage

const apiVideo = require('@api.video/nodejs-sdk');

(async () => {
  try {
    // Create client for Production and authenticate
    const client = new apiVideo.Client({ apiKey: 'xxx' });

    // Create and upload a video ressource
    const video = await client.videos.upload('test/data/small.webm', { title: 'Course #4 - Part B' });
    console.log(video);
  } catch (e) {
    console.error(e);
  }
})();

See sandbox.spec.js for more usage examples.

Full API

/**
 * VIDEO
 */
const client = new apiVideo.Client({ apiKey: 'xxx' });

// Show a video
client.videos.get(videoId);

// Show a video status
client.videos.getStatus(videoId);

// List or search videos
client.videos.search(parameters = {});

// Create video properties
client.videos.create(title, properties = {});

// Upload a video media file
// Create a video, if videoId is null
client.videos.upload(source, properties = {}, videoId = null);

// Create a video by downloading it from a third party
client.videos.download(source, title, properties = {});

// Update video properties
client.videos.update(videoId, properties);

// Set video public
client.videos.makePublic(videoId);

// Set video private
client.videos.makePrivate(videoId);

// Delete video (file and data)
client.videos.delete(videoId);

// Delegated upload (generate a token for someone to upload a video into your account)
result = client.tokens.generate(); // string(3): "xyz"
result.then(function(token) {
  // ...then upload from anywhere without authentication:
  //  curl https://ws.api.video/upload?token=xyz -F [email protected]
});

/**
 * VIDEO THUMBNAIL
 */
// Upload a thumbnail for video
client.videos.uploadThumbnail(source, videoId);

// Update video's thumbnail by picking timecode
client.videos.updateThumbnailWithTimecode(videoId, timecode);

/**
 * VIDEO CAPTIONS
 */
// Get caption for a video
client.videos.captions.get(videoId, language);

// Get all captions for a video
client.videos.captions.getAll(videoId);

// Upload a caption file for a video (.vtt)
client.videos.captions.upload(source, properties);


// Set default caption for a video
client.videos.captions.updateDefault(videoId, language, isDefault);

// Delete video's caption
client.videos.captions.delete(videoId, language);

/**
 * VIDEO CHAPTERS
 */
// Get caption for a video
client.videos.chapters.get(videoId, language);

// Get all chapters for a video
client.videos.chapters.getAll(videoId);

// Upload a chapter file for a video (.vtt)
client.videos.chapters.upload(source, properties);

// Delete video's chapter
client.videos.chapters.delete(videoId, language);

/**
 * PLAYERS
 */
// Get a player
client.players.get(playerId);

// List players
client.players.search(parameters = {});

// Create a player
client.players.create(properties = {});

// Update player's properties
client.players.uploadLogo(source, playerId, link);

// Update player's properties
client.players.update(playerId, properties);

// Delete a player logo
client.players.deleteLogo(playerId);

// Delete a player
client.players.delete(playerId);

/**
 * LIVE
 */
// Show a live
client.lives.get(liveStreamId);

// List or search lives
client.lives.search(parameters = {});

// Create live properties
client.lives.create(name, properties = {});

// Update live properties
client.lives.update(liveStreamId, properties);

// Delete live (file and data)
client.lives.delete(liveStreamId);

/**
 * LIVE THUMBNAIL
 */
// Upload a thumbnail for live
client.lives.uploadThumbnail(source, liveStreamId);

/**
 * ANALYTICS
 */
// Get video analytics between period
client.analyticsVideo.get(videoId, period);

// Get live analytics between period
client.analyticsLive.get(liveStreamId, period);

// Get analytics session events
client.analyticsLive.get(sessionId, parameters);

Full API Details Implementation

Videos

| Function | Parameters | Description | Required | Allowed Values |
| :---------------------------------: | :-------------------: | :------------------------: | :--------------------: | :--------------------- | | get | videoId(string) | Video identifier | :heavy_check_mark: | - | | getStatus | videoId(string) | Video identifier | :heavy_check_mark: | - | | search | - | - | - | - | | - | parameters(object) | Search parameters | :x: |

  • currentPage(int)
  • pageSize(int)
  • sortBy(string)
  • sortOrder(string)
  • keyword(string)
  • tags(string|array(string))
  • metadata(array(string))
| | create | - | - | - | - | | - | title(string) | Video title | :heavy_check_mark: | - | | - | properties(object) | Video properties | :x: |
  • description(string)
  • tags(array(string))
  • playerId(string)
  • metadata(array(
    array(
    'key' => 'Key1',
    'value' => 'value1'
    ),
    array(
    'key' => 'Key2',
    'value' => 'value2'
    )
    )
  • panoramic(bool)
  • public(bool)
  • mp4Support(bool)
| | upload | - | - | - | - | | - | source(string) | Video media file | :heavy_check_mark: | - | | - | properties(object) | Video properties | :x: |
  • title(string)
  • description(string)
  • tags(array(string))
  • playerId(string)
  • metadata(array(
    array(
    'key' => 'Key1',
    'value' => 'value1'
    ),
    array(
    'key' => 'Key2',
    'value' => 'value2'
    )
    )
| | - | videoId(string) | Video identifier | :x: | - | | uploadThumbnail | - | - | - | - | | - | source(string) | Image media file | :heavy_check_mark: | - | | - | videoId(string) | Video identifier | :heavy_check_mark: | - | | updateThumbnailWithTimeCode | - | - | - | - | | - | videoId(string) | Video identifier | :heavy_check_mark: | - | | - | timecode(string) | Video timecode | :heavy_check_mark: | 00:00:00.00
(hours:minutes:seconds.frames) | | update | - | - | - | - | | - | videoId()string | Video identifier | :heavy_check_mark: | - | | - | properties(object) | Video properties | :heavy_check_mark: |
  • title(string)
  • description(string)
  • tags(array(string))
  • playerId(string)
  • metadata(array(
    array(
    'key' => 'Key1',
    'value' => 'value1'
    ),
    array(
    'key' => 'Key2',
    'value' => 'value2'
    )
    )
  • panoramic(bool)
  • public(bool)
  • mp4Support(bool)
| | makePublic | videoId(string) | Video identifier | :heavy_check_mark: | - | | makePrivate | videoId(string) | Video identifier | :heavy_check_mark: | - | | delete | videoId(string) | Video identifier | :heavy_check_mark: | - |

Players

FunctionParametersDescriptionRequiredAllowed Values
getplayerId(string)Player identifier:heavy_check_mark:-
createproperties(object)Player properties:x:
  • shapeMargin(int)
  • shapeRadius(int)
  • shapeAspect(string)
  • shapeBackgroundTop(string)
  • shapeBackgroundBottom(string)
  • text(string)
  • link(string)
  • linkHover(string)
  • linkActive(string)
  • trackPlayed(string)
  • trackUnplayed(string)
  • trackBackground(string)
  • backgroundTop(string)
  • backgroundBottom(string)
  • backgroundText(string)
  • enableApi(bool)
  • enableControls(bool)
  • forceAutoplay(bool)
  • hideTitle(bool)
uploadLogo----
-source(string)Logo file:heavy_check_mark:-
-playerId(string)Player identifier:heavy_check_mark:-
-link(string)Logo link:heavy_check_mark:-
search----
-parameters(object)Search parameters:x:
  • currentPage(int)
  • pageSize(int)
  • sortBy(string)
  • sortOrder(string)
update----
-playerId(string)Player identifier:heavy_check_mark:-
-properties(object)Player properties:heavy_check_mark:
  • shapeMargin(int)
  • shapeRadius(int)
  • shapeAspect(string)
  • shapeBackgroundTop(string)
  • shapeBackgroundBottom(string)
  • text(string)
  • link(string)
  • linkHover(string)
  • linkActive(string)
  • trackPlayed(string)
  • trackUnplayed(string)
  • trackBackground(string)
  • backgroundTop(string)
  • backgroundBottom(string)
  • backgroundText(string)
  • enableApi(bool)
  • enableControls(bool)
  • forceAutoplay(bool)
  • hideTitle(bool)
deleteLogoplayerId(string)Player identifier:heavy_check_mark:-
deleteplayerId(string)Player identifier:heavy_check_mark:-

Captions

FunctionParametersDescriptionRequiredAllowed Values
get----
-videoId(string)Video identifier:heavy_check_mark:-
-language(string)Language identifier:heavy_check_mark:2 letters (ex: en, fr)
getAllvideoId(string)Video identifier:heavy_check_mark:-
upload----
-source(string)Caption file:heavy_check_mark:-
-properties(string)Caption properties:heavy_check_mark:
  • videoId(string)
  • language(string - 2 letters)
updateDefault- (object)---
-videoIdVideo identifier:heavy_check_mark:-
-language (string)Language identifier:heavy_check_mark:2 letters (ex: en, fr)
-isDefault (string)Set default language:heavy_check_mark:true/false
delete----
-videoIdVideo identifier:heavy_check_mark:-
-language (string)Language identifier:heavy_check_mark:2 letters (ex: en, fr)

Chapters

FunctionParametersDescriptionRequiredAllowed Values
get----
-videoId(string)Video identifier:heavy_check_mark:-
-language(string)Language identifier:heavy_check_mark:2 letters (ex: en, fr)
getAllvideoId(string)Video identifier:heavy_check_mark:-
upload----
-source(string)Chapter file:heavy_check_mark:-
-properties(string)Chapter properties:heavy_check_mark:
  • videoId(string)
  • language(string - 2 letters)
delete----
-videoIdVideo identifier:heavy_check_mark:-
-language (string)Language identifier:heavy_check_mark:2 letters (ex: en, fr)

Lives

| Function | Parameters | Description | Required | Allowed Values |
| :---------------------------------: | :-------------------: | :------------------------: | :--------------------: | :--------------------- | | get | liveStreamId(string) | Live identifier | :heavy_check_mark: | - | | search | - | - | - | - | | - | parameters(object) | Search parameters | :x: |

  • currentPage(int)
  • pageSize(int)
  • sortBy(string)
  • sortOrder(string)
| | create | - | - | - | - | | - | name(string) | Live name | :heavy_check_mark: | - | | - | properties(object) | Live properties | :x: |
  • record(boolean)
  • playerId(string)
| | uploadThumbnail | - | - | - | - | | - | source(string) | Image media file | :heavy_check_mark: | - | | - | liveStreamId(string) | Live identifier | :heavy_check_mark: | - | | update | - | - | - | - | | - | liveStreamId()string | Live identifier | :heavy_check_mark: | - | | - | properties(object) | Live properties | :heavy_check_mark: |
  • name(string)
  • record(boolean)
  • playerId(string)
| | delete | liveStreamId(string) | Live identifier | :heavy_check_mark: | - |

AnalyticsVideo

| Function | Parameters | Description | Required | Allowed Values/Format |
| :---------------------------------: | :-------------------: | :------------------------: | :--------------------: | :--------------------- | | get | - | - | - | - | | - | videoId(string) | Video identifier | :heavy_check_mark: | - | | - | period (string) | Period research | :x: |

  • For a day : 2018-01-01
  • For a week: 2018-W01
  • For a month: 2018-01
  • For a year: 2018
  • Date range: 2018-01-01/2018-01-15
  • |

    AnalyticsLive

    | Function | Parameters | Description | Required | Allowed Values/Format |
    | :---------------------------------: | :-------------------: | :------------------------: | :--------------------: | :--------------------- | | get | - | - | - | - | | - | liveStreamId(string) | Live identifier | :heavy_check_mark: | - | | - | period (string) | Period research | :x: |

    • For a day : 2018-01-01
    • For a week: 2018-W01
    • For a month: 2018-01
    • For a year: 2018
    • Date range: 2018-01-01/2018-01-15
    |

    AnalyticsSessionEvent

    | Function | Parameters | Description | Required | Allowed Values/Format |
    | :---------------------------------: | :-------------------: | :------------------------: | :--------------------: | :--------------------- | | get | - | - | - | - | | - | sessionId(string) | Session identifier | :heavy_check_mark: | - | | - | parameters(array) | Search parameters | :x: |

    • currentPage(int)
    • pageSize(int)
    |

    Tokens

    | Function | Parameters | Description | Required | Allowed Values |
    | :---------------------------------: | :-------------------: | :------------------------: | :--------------------: | :--------------------- | | generate | - | Token for delegated upload | - | - |

    Account

    | Function | Parameters | Description | Required | Allowed Values |
    | :---------------------------------: | :-------------------: | :------------------------: | :--------------------: | :--------------------- | | get | - | Get account informations (quota, features) | - | - |

    More on api.video

    A full technical documentation is available on https://docs.api.video/

    Test

    npm run test
    

    You can also run a bunch of commands against your actual sandbox:

    API_KEY=xxx npm run test:sandbox
    

    Use the Sandbox API Key and not your production key.

版本与发布记录

@api.video/nodejs-sdk 共发布 28 个版本,首次发布于 2019/01/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.10.4latest2021/12/094 年前
1.10.32021/04/225 年前
1.10.22021/02/195 年前
1.10.12021/02/195 年前
1.10.02021/02/195 年前
1.9.82021/02/095 年前

关于 @api.video/nodejs-sdk 的常见问题

@api.video/nodejs-sdk 是什么?

Nodejs SDK for api.video

如何安装 @api.video/nodejs-sdk?

在项目目录运行 npm install @api.video/nodejs-sdk,或使用 pnpm add / yarn add / bun add。

@api.video/nodejs-sdk 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/api.video__nodejs-sdk 是否存在。

@api.video/nodejs-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@api.video/nodejs-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=8。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@api.video/nodejs-sdk 可以商用吗?

@api.video/nodejs-sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@api.video/nodejs-sdk 的下载量有多少?

根据 npm 官方下载统计,@api.video/nodejs-sdk 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,109 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@api.video/nodejs-sdk 还在维护吗?

最新版本 1.10.4 发布于 2021/12/09(4 年前);至今共发布 28 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/01/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。