Navigation
Functions
createIntroDbClient(options?)
Creates a reusable TIDB client.
Signature
createIntroDbClient(options?: TIDBClientOptions): TIDBClient
Use This When
- You want shared
baseUrl,fetch,headers,logger, orapiKey - You prefer method-based access:
client.getMedia(),client.submitMediaTimestamp()andclient.mapSubmission()
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
- No auth required
- Optional current-user API key supported
- When a current-user key is supplied, the API can include that user’s pending submissions in the response
Params
tvdbId: Preferred identitytmdbId,imdbId: Alternate identities, resolved server-side (slower)season,episode: provide together for a TV episode lookup (0addresses specials)mapping: the episode order your numbers are in; omitted meansdefaulttvdbEpisodeId: pins one exact TVDB episode recordepisodeName/episodeTitle: optional title hint corroborating the resolved episodedurationMs: optional total video duration in milliseconds used by the API to select the closest matching release version (theatrical, extended cut, etc.)listVersions: return the release-version list instead of skip timestampsmergeUnknown: whether no-known-duration submissions join the selected release group (API defaulttrue)details: includeconfidence/submissionCountper segment andgroupDurationMs
Returns
A MediaResponse, one of:
MediaRecord(kind: 'media')MediaVersions(kind: 'versions')MediaEpisodeList(kind: 'episodes')
Raw API Time Shape
The API returns media timestamps in milliseconds using raw snake_case fields:
{
"start_ms": 30000,
"end_ms": 90000
}
Special cases:
start_ms: nullmeans “starts at the beginning”end_ms: nullmeans “runs to the end of the media”- segment properties such as
introorcreditsmay be omitted if no data exists - segment properties are arrays and may contain multiple entries for the same segment type; this is expected for some media and is not an error. Use all segments.
submitMediaTimestamp(input, transportOptions?)
Submits a single segment timestamp payload.
Signature
submitMediaTimestamp(
input: SubmitMediaTimestampInput,
transportOptions?: TIDBTransportOptions
): Promise<SubmissionResponse>
Auth
- Always requires the current user’s API key
- The key should belong to the end user
- The package throws before making the request if the key is missing
Input Rules
- Provide one identity:
tvdbId(preferred),tmdbIdorimdbId - Use either seconds or milliseconds, not both
introandrecapallownullstartscreditsandpreviewallownullends- TV submissions require
seasonandepisode; a string may be a list or range ('1,2','1-3','1,3-4,6') - Movie submissions must omit
season,episode,mappingandtvdbEpisodeId mappingstates the episode order your numbers are in; an unknown order is rejected locallyvideoDurationMsis optional but highly recommended; it helps associate the submission with a release version for matching. It must be0(unknown) or between 5 minutes and 6 hours
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
- Always requires the current user’s API key
Input Rules
- Same identity,
mappingand hint rules assubmitMediaTimestamp(), minus the timestamps - A list or range of seasons/episodes cannot be reported as a single mapping; the API refuses it with
400 - Movie submissions must omit
season,episode,mappingandtvdbEpisodeId
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
- You want to inspect or reuse the generated query parameters
- You want package-level validation before making your own fetch call
serializeSubmissionRequest(input)
Validates and converts a high-level submission input into the raw /submit request body.
Signature
serializeSubmissionRequest(
input: SubmitMediaTimestampInput
): SubmissionRequestPayload
Normalization Rules
introandrecapstarts of0ornullbecomestart_ms: nullcreditsandpreviewnull ends stayend_ms: nullmappingaliases are canonicalised (for example'altdvd'becomes'dvd')videoDurationMsis sent asvideo_duration_mswhen provided- seconds are rounded to milliseconds
- The outgoing API payload always uses millisecond field names:
start_msandend_ms
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
start_msbecomesstartMsend_msbecomesendMsstart_ms: nullbecomesstartMs: 0end_ms: nullstaysendMs: null- derived fields such as
durationMs,startsAtBeginning, andendsAtMediaEndare added - snake_case response fields become camelCase (
tvdb_idbecomestvdbId,group_duration_msbecomesgroupDurationMs, and so on)
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
start_ms: nullbecomesstartMs: 0end_ms: nullstaysendMs: nulldurationMsisnullif the end is unknownstartsAtBeginningandendsAtMediaEndpreserve the meaning of the originalnullvalues
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
- Case, spaces, dashes and underscores are ignored
- TVDB names and Jellyfin
displayorderspellings are both accepted
normalizeEpisodeOrder('Aired-Order'); // 'official'
normalizeEpisodeOrder('altdvd'); // 'dvd'
normalizeEpisodeOrder('streaming'); // 'alternate'
normalizeEpisodeOrder('nope'); // undefined