TheIntroDB Package Docs

Documentation for the theintrodb NPM package

View on GitHub

Functions

createIntroDbClient(options?)

Creates a reusable TIDB client.

Signature

createIntroDbClient(options?: TIDBClientOptions): TIDBClient

Use This When

getMedia(params, transportOptions?)

Fetches timestamps for a movie or TV episode, its release versions, or a per-episode submission-count fallback.

Signature

getMedia(
  params: GetMediaParams,
  transportOptions?: TIDBTransportOptions
): Promise<MediaResponse>

Auth

Params

Returns

A MediaResponse, one of:

Raw API Time Shape

The API returns media timestamps in milliseconds using raw snake_case fields:

{
  "start_ms": 30000,
  "end_ms": 90000
}

Special cases:

submitMediaTimestamp(input, transportOptions?)

Submits a single segment timestamp payload.

Signature

submitMediaTimestamp(
  input: SubmitMediaTimestampInput,
  transportOptions?: TIDBTransportOptions
): Promise<SubmissionResponse>

Auth

Input Rules

mapSubmission(input, transportOptions?)

Resolves a submission to its TVDB mapping without storing it. A dry run of POST /submit: a request that would be rejected on submit is rejected here with the same error.

Signature

mapSubmission(
  input: MapSubmissionInput,
  transportOptions?: TIDBTransportOptions
): Promise<MapResult>

Auth

Input Rules

Returns

A MapResult with the resolved tvdbId, type, canonical mapping, and (for TV) season, episode, tvdbEpisodeId, episodeTitle and mediaTitle when available.

buildMediaQuery(params)

Builds the query string used for /media.

Signature

buildMediaQuery(params: GetMediaParams): URLSearchParams

Use This When

serializeSubmissionRequest(input)

Validates and converts a high-level submission input into the raw /submit request body.

Signature

serializeSubmissionRequest(
  input: SubmitMediaTimestampInput
): SubmissionRequestPayload

Normalization Rules

serializeMapRequest(input)

Validates and converts a high-level map input into the raw /map request body. It carries no timestamps.

Signature

serializeMapRequest(input: MapSubmissionInput): Record<string, unknown>

parseMediaResponse(body)

Validates raw JSON against the /media schemas and returns the matching normalized shape, choosing between the media, versions and episode-list bodies.

Signature

parseMediaResponse(body: unknown): MediaResponse

What It Normalizes

parseMediaRecord(body)

Validates and normalizes the grouped-timestamps /media body (the default shape).

Signature

parseMediaRecord(body: unknown): MediaRecord

parseMediaVersions(body)

Validates and normalizes the list_versions /media body.

Signature

parseMediaVersions(body: unknown): MediaVersions

parseMediaEpisodes(body)

Validates and normalizes the episode-list fallback /media body.

Signature

parseMediaEpisodes(body: unknown): MediaEpisodeList

parseSubmissionResponse(body)

Validates raw JSON against the expected /submit schema and returns a normalized SubmissionResponse.

Signature

parseSubmissionResponse(body: unknown): SubmissionResponse

parseMapResponse(body)

Validates raw JSON against the expected /map schema and returns a normalized MapResult.

Signature

parseMapResponse(body: unknown): MapResult

normalizeSegmentTimestamp(timestamp)

Normalizes a raw segment timestamp into the package’s runtime format.

Signature

normalizeSegmentTimestamp(
  timestamp: SegmentTimestampRaw
): NormalizedSegmentTimestamp

Output Behavior

normalizeEpisodeOrder(name)

Resolves a mapping spelling to its canonical TVDB episode order, or undefined when the spelling is unknown.

Signature

normalizeEpisodeOrder(name: string): EpisodeOrder | undefined

Behavior

normalizeEpisodeOrder('Aired-Order'); // 'official'
normalizeEpisodeOrder('altdvd'); // 'dvd'
normalizeEpisodeOrder('streaming'); // 'alternate'
normalizeEpisodeOrder('nope'); // undefined