TheIntroDB Package Docs

Documentation for the theintrodb NPM package

View on GitHub

Getting Started

Install

npm install theintrodb

Import

import {
  createIntroDbClient,
  getMedia,
  submitMediaTimestamp,
  type TIDBClient,
  type TIDBClientOptions,
} from 'theintrodb';

Create A Client

const client = createIntroDbClient({
  logger: console,
});

Client Options

Read Media Data

Movie Example

const movie = await client.getMedia({
  tmdbId: 12345,
  durationMs: 7_200_000,
});

TV Episode Example

const episode = await client.getMedia({
  tmdbId: 67890,
  season: 1,
  episode: 1,
});

Optional Current-User Key

getMedia() is public. If you provide the current user’s API key, the API can include that user’s pending submissions in the weighted result.

const media = await client.getMedia(
  {
    tmdbId: 12345,
  },
  {
    apiKey: currentUserApiKey,
  }
);

Submit Timestamps

submitMediaTimestamp() always requires the current user’s API key.

const submissionResult = await client.submitMediaTimestamp(
  {
    tmdbId: 12345,
    type: 'movie',
    segment: 'intro',
    videoDurationMs: 7_200_000,
    startSec: 30.5,
    endSec: 90.2,
  },
  {
    apiKey: currentUserApiKey,
  }
);

const submissions = submissionResult.submissions;

Time Format Rules

Use exactly one format:

Do not mix seconds and milliseconds in the same submission.

Timestamp Semantics

How TheIntroDB Returns Time Data

For GET /media, TheIntroDB returns raw timestamps in milliseconds using start_ms and end_ms.

Example:

{
  "tmdb_id": 12345,
  "type": "movie",
  "intro": [
    {
      "start_ms": null,
      "end_ms": 90000
    }
  ],
  "credits": [
    {
      "start_ms": 1800000,
      "end_ms": null
    }
  ]
}

Meaning:

This package maps that raw shape into a normalized runtime shape:

{
  intro: [
    {
      startMs: 0,
      endMs: 90000,
      durationMs: 90000,
      startsAtBeginning: true,
      endsAtMediaEnd: false,
    },
  ],
}

For POST /submit, the API accepts either:

The package validates the input format and converts seconds to millisecond request values before sending the request.

Logging

Logging is optional.

You can omit the logger entirely:

const quietClient = createIntroDbClient();

Or pass console:

const debugClient = createIntroDbClient({
  logger: console,
});

The package logs when: