TheIntroDB Package Docs

Documentation for the theintrodb NPM package

View on GitHub

Getting Started

Install

npm install theintrodb

Import

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

Create A Client

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

Client Options

Identity

TVDB is the identity in v4. Address a media with at least one of tvdbId, tmdbId or imdbId, preferring tvdbId: the other two are resolved server-side and are slower. Supplying more than one is allowed; the API applies the priority order tvdbId -> tmdbId -> imdbId.

Read Media Data

Movie Example

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

TV Episode Example

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

The Three Response Shapes

getMedia() returns one of three shapes, discriminated by kind:

const result = await client.getMedia({ tvdbId: 169 });

if (result.kind === 'media') {
  console.log(result.intro, result.credits);
} else if (result.kind === 'versions') {
  console.log(result.versions);
} else {
  console.log(result.episodes);
}

Episode Order (mapping)

Every submission is stored in TVDB’s default order. If your season/episode numbers come from a different order, pass mapping and the API converts them. Omitted means default.

Canonical orders: default, official, dvd, alternate, absolute, regional. The Jellyfin spellings are accepted too (aired, altdvd, alttwo, streaming, …) and are canonicalised before the request is sent.

const episode = await client.getMedia({
  tvdbId: 71663,
  mapping: 'dvd',
  season: 1,
  episode: 1,
});

Extra Detail

details: true adds confidence and submissionCount to each returned segment and groupDurationMs to the body.

const episode = await client.getMedia({
  tvdbId: 71663,
  season: 1,
  episode: 1,
  details: true,
});

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(
  {
    tvdbId: 169,
  },
  {
    apiKey: currentUserApiKey,
  }
);

Submit Timestamps

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

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

const { ok, submissions } = submissionResult;

Preview A Submission With mapSubmission()

mapSubmission() is a dry run of /submit. It resolves exactly as a real submission would and returns the resolved TVDB coordinates without storing anything. It requires the current user’s API key.

const resolved = await client.mapSubmission(
  {
    tvdbId: 71663,
    type: 'tv',
    mapping: 'dvd',
    season: '1',
    episode: '1',
  },
  {
    apiKey: currentUserApiKey,
  }
);

console.log(resolved.season, resolved.episode, resolved.episodeTitle);

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:

{
  "tvdb_id": 169,
  "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:

{
  kind: 'media',
  tvdbId: 169,
  type: 'movie',
  groupDurationMs: null,
  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: