Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@api.video/media-descriptor

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@api.video/media-descriptor

TypeScript library for managing api.video assets urls, supporting both live and vod, including private content. It enables the generation of manifest URLs, retrieval of metadata, and is usable in both front-end and back-end environments.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Media Descriptor Module

npm version build status license

This module provides a robust way to handle video media descriptions for both VOD (Video on Demand) and Live streams. It consists of two main components: a factory to create media descriptors and a descriptor class to access media information.

Installation

npm install media-descriptor
# or
yarn add media-descriptor

MediaDescriptorFactory

The factory provides two methods to create a MediaDescriptor instance:

fromManifestUrl(url: string, options?: Options): Promise<MediaDescriptor>

Creates a MediaDescriptor from a manifest URL (m3u8).

const descriptor = await MediaDescriptorFactory.fromManifestUrl(
  "https://vod.api.video/vod/vi123456789/hls/manifest.m3u8"
);

Supported URL patterns:

  • VOD public: domain.com/vod/videoId/hls/manifest.m3u8
  • VOD private: domain.com/vod/videoId/token/tokenValue/hls/manifest.m3u8
  • Live public: domain.com/videoId.m3u8
  • Live private: domain.com/private/token/videoId.m3u8

Optional parameters:

  • options.collectorDomain: Override the default analytics collector domain

fromVideoDescription(videoDescription: VideoDescription): Promise<MediaDescriptor>

Creates a MediaDescriptor from a video description object.

const descriptor = await MediaDescriptorFactory.fromVideoDescription({
  mediaId: "vi123456789",
  type: "vod",
  deliveryDomain: "vod.api.video",
  privateToken: "optional-token",
});

MediaDescriptor

The MediaDescriptor class provides access to all video-related information:

Basic Properties

  • title: Video title
  • mediaId: Unique video identifier
  • mediaType: Either 'vod' or 'live'
  • manifestUrl: HLS manifest URL
  • mp4Url: Progressive download URL (VOD only)
  • posterUrl: Thumbnail URL (VOD only)

Domains Information

const domains = descriptor.domains;
// {
//   delivery: "vod.api.video",
//   collector: "collector.api.video"
// }

Chapters Support

// List available chapter languages
const chapters = descriptor.chaptersEntries;
// Get chapter URL for a specific language
const chapterUrl = descriptor.getChapterUrl("en");

Summaries Support

// List available summaries
const summaries = descriptor.summaryEntries;
// [{ lang: 'en', generated: false }, { lang: 'fr', generated: true }]

// Get summary content
const summary = await descriptor.getSummary({ lang: "en", generated: false });
// {
//   title: string;
//   abstract: string;
//   takeaways: string[];
// }

Error Handling

The factory methods may throw:

  • InvalidUrlError: When the manifest URL format is invalid
  • VideoNotFoundError: When the video doesn't exist
  • MetadataFetchError: When metadata cannot be retrieved

Example Usage

try {
  const descriptor = await MediaDescriptorFactory.fromManifestUrl(manifestUrl);

  // Access basic information
  console.log(descriptor.title);
  console.log(descriptor.manifestUrl);

  // Get available chapters
  const chapters = descriptor.chaptersEntries;

  // Get summary if available
  if (descriptor.summaryEntries.length > 0) {
    const summary = await descriptor.getSummary(descriptor.summaryEntries[0]);
    console.log(summary.abstract);
  }
} catch (error) {
  if (error instanceof VideoNotFoundError) {
    console.error("Video not found");
  }
}

Contributing

Contributions are welcome! Please read the contributing guidelines first.

License

This project is licensed under the MIT License - see the LICENSE file for details.

FAQs

Package last updated on 15 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc