Typed TypeScript client package for the TheIntroDB API (v4).
Detailed documentation can be found at: https://theintrodb.github.io/theintrodb-npm/
npm install theintrodbIf you are using an AI coding agent (Claude Code, opencode, Codex, Cursor, Copilot, etc.), the package bundles version-matched agent docs. Paste the following prompt and let the agent handle the setup:
Install
theintrodbin this project withpnpm add theintrodb(do not usepnpm install theintrodb). Then readnode_modules/theintrodb/AGENTS.mdandnode_modules/theintrodb/docs/getting-started.mdand set up a typed TheIntroDB client in this codebase according to those docs.
The bundled AGENTS.md and docs/ folder always match the installed version,
so the agent never works from stale or generic knowledge. Types are declared in
node_modules/theintrodb/lib/index.d.ts and
node_modules/theintrodb/lib/types.d.ts.
- Centralized request, parsing, and validation logic
- Runtime validation of request payloads and API responses
GET /mediaworks without auth and can optionally use a current user API keyPOST /submitandPOST /maprequire the current user's API key so requests act on that account- TVDB-primary identity: address a media with
tvdbId(preferred),tmdbIdorimdbId - Episode-order
mappingsupport (default,official,dvd,alternate,absolute,regional, plus Jellyfin aliases) - Normalized timestamp handling keeps
nullend times as "end of media" and convertsnullstarts to0 - Reusable client or standalone function usage
- Optional logging hooks for auth-sensitive request flows
- Jest-based unit coverage for transport, parsing, and edge cases
import { createIntroDbClient } from 'theintrodb';
const client = createIntroDbClient({
// Optional: pass a logger if you want TIDB request/auth messages.
// `console` is fine for quick debugging; omit this entirely if you do not want logs.
logger: console,
});
// Public movie lookup: no API key required. TVDB is the identity.
const publicMedia = await client.getMedia({
tvdbId: 169,
});
// Public TV lookup: include `season` and `episode` for a specific episode.
const publicEpisodeMedia = await client.getMedia({
tvdbId: 71663,
season: 1,
episode: 1,
});
// `getMedia()` returns a discriminated union; narrow it with `kind`.
if (publicEpisodeMedia.kind === 'media') {
console.log(publicEpisodeMedia.intro[0]?.startMs);
}
// Optional current-user API key:
// this can include that user's still-pending submissions in the response.
const mediaWithMyPendingSubmissions = await client.getMedia(
{
tvdbId: 169,
},
{
apiKey: currentUserApiKey,
}
);
// Submissions always require the current user's API key.
// The key should belong to the end user so the submission is attached to their account.
const submission = await client.submitMediaTimestamp(
{
tvdbId: 169,
type: 'movie',
segment: 'intro',
startSec: 0,
endSec: 90,
},
{
apiKey: currentUserApiKey,
}
);
// Preview where a submission would land before storing it.
const mapping = await client.mapSubmission(
{
tvdbId: 71663,
type: 'tv',
mapping: 'dvd',
season: '1',
episode: '1',
},
{
apiKey: currentUserApiKey,
}
);getMedia()does not require authenticationgetMedia()optionally accepts the current user's API key; when provided, the API may include that user's pending submissions in the weighted resultsubmitMediaTimestamp()andmapSubmission()always require the current user's API key- Do not ship a shared application API key; this package is designed for end-user keys
- TVDB is the identity in v4: prefer
tvdbId tmdbIdandimdbIdare accepted as alternate ways to address a media and are resolved server-side (slower)- Provide at least one identity per request; the API resolves them in the priority order
tvdbId->tmdbId->imdbId
- Returns one of three shapes, discriminated by
kind:'media': the grouped skip timestamps (MediaRecord)'versions': the release-version list, whenlistVersions: true'episodes': a per-episode submission-count fallback
- Use
tvdbIdfor movies - Use
tvdbId,season, andepisodefor TV episodes mappingstates the episode order yourseason/episodeare given in; omitted meansdefaultdetails: trueaddsconfidence/submissionCountper segment andgroupDurationMsto the body- Segment arrays are omitted by the API when no submissions exist for that segment type
- Segment arrays can contain multiple entries for the same segment type (for example, some episodes have multiple recaps); this is expected and should be handled by using all available segments
- Submit one segment at a time to
submitMediaTimestamp() - Use either
startSec/endSecorstartMs/endMs, never both introandrecapallownullstartscreditsandpreviewallownullends, which mean "to the end of media"- For TV,
season/episodemay be a single value or a list/range string ('1,2','1-3','1,3-4,6')
introandrecap:nullor0start values are normalized to0creditsandpreview:nullend values remainnull- Normalized responses include
startsAtBeginningandendsAtMediaEndflags
TheIntroDB returns media timestamps from GET /media in arrays of objects shaped like:
{
"start_ms": 30000,
"end_ms": 90000
}Important details:
- The API returns response times in milliseconds, using the raw fields
start_msandend_ms - Each segment type such as
intro,recap,credits, andpreviewis returned as an array - A segment array may contain multiple entries for the same segment type; this is not an error
start_ms: nullmeans the segment starts at the beginning of the mediaend_ms: nullmeans the segment continues to the end of the media- A segment array may be omitted entirely if no submissions exist for that segment type
This package normalizes those raw values into:
startMsendMsdurationMsstartsAtBeginningendsAtMediaEnd
Example raw API response fragment:
{
"tvdb_id": 169,
"type": "movie",
"intro": [
{
"start_ms": null,
"end_ms": 90000
}
],
"credits": [
{
"start_ms": 1800000,
"end_ms": null
}
]
}Normalized package result:
{
kind: 'media',
tvdbId: 169,
type: 'movie',
groupDurationMs: null,
intro: [
{
startMs: 0,
endMs: 90000,
durationMs: 90000,
startsAtBeginning: true,
endsAtMediaEnd: false,
},
],
credits: [
{
startMs: 1800000,
endMs: null,
durationMs: null,
startsAtBeginning: false,
endsAtMediaEnd: true,
},
],
}For submissions, the API accepts either:
startSecandendSecin seconds with decimal precisionstartMsandendMsin integer milliseconds
The package converts second-based inputs into millisecond request values before sending them to TheIntroDB.
await client.submitMediaTimestamp(
{
tvdbId: 71663,
type: 'tv',
season: 1,
episode: 1,
segment: 'credits',
startSec: 5400,
endSec: null,
},
{
apiKey: currentUserApiKey,
}
);- User API keys are optional for reads and required for submissions and mapping
- When a user supplies their API key to
getMedia(), they can see pending submissions tied to their own account - This package validates payloads locally before making requests and validates JSON responses after receiving them
npm run build
npm testMIT License (MIT) — see LICENSE for the full text. Every source file carries SPDX-License-Identifier: MIT.
--
TheIntroDB · community-submitted intro, recap, credits and preview timestamps for your media server
theintrodb.org · GitHub · Discord
