Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/downloads-numeric-category-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
type: fix
area: downloads
issues: [2223]
---

Adding Xtream series episodes to Downloads works again for providers that send the category id as a number. The download used to fail with "t?.trim is not a function".
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ describe('download metadata snapshot factories', () => {
});
});

it('stores a numeric provider category id as a string', () => {
const episode = {
seasonNumber: 1,
episodeNumber: 1,
};

expect(
createSeriesEpisodeDownloadSnapshot({
language: 'en',
title: 'Signal House',
providerCategoryId: 617,
episode,
}).providerCategoryId
).toBe('617');
expect(
createMovieDownloadSnapshot({
language: 'en',
title: 'Night Ferry',
providerCategoryId: 617,
}).providerCategoryId
).toBe('617');
expect(
createMovieDownloadSnapshot({
language: 'en',
title: 'Night Ferry',
providerCategoryId: Number.NaN,
})
).not.toHaveProperty('providerCategoryId');
});

it('bounds people to 30 and genres to 20 in deterministic input order', () => {
const snapshot = createMovieDownloadSnapshot({
language: 'en',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ interface DownloadSnapshotFields {
posterUrl?: string;
backdropUrl?: string;
tmdbId?: number;
providerCategoryId?: string;
/** Xtream and Stalker portals send category ids as strings or numbers. */
providerCategoryId?: string | number;
cast?: readonly DownloadMetadataPerson[];
creators?: readonly DownloadMetadataPerson[];
enrichedAt?: string;
Expand All @@ -101,6 +102,13 @@ function text(value: string | undefined): string | undefined {
return normalized ? normalized : undefined;
}

function identifier(value: string | number | undefined): string | undefined {
if (typeof value === 'number') {
return Number.isFinite(value) ? String(value) : undefined;
}
return typeof value === 'string' ? text(value) : undefined;
}

function finite(value: number | undefined): number | undefined {
return value !== undefined && Number.isFinite(value) ? value : undefined;
}
Expand Down Expand Up @@ -277,7 +285,7 @@ function snapshotFields(input: DownloadSnapshotFields) {
const posterUrl = artworkUrl(input.posterUrl);
const backdropUrl = artworkUrl(input.backdropUrl);
const tmdbId = integer(input.tmdbId);
const providerCategoryId = text(input.providerCategoryId);
const providerCategoryId = identifier(input.providerCategoryId);
const cast = people(input.cast);
const creators = people(input.creators);

Expand Down
Loading