@charliehess/tmdb
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -156,5 +156,5 @@ "use strict"; | ||
}).then((r) => r.json()); | ||
const providers = utils_1.processWatchProviders((results === null || results === void 0 ? void 0 : results[locale]) || {}); | ||
providers.forEach((provider) => (provider.logo_path = this.tmdbPathPrefix(provider.logo_path, 200))); | ||
return providers; | ||
const result = utils_1.processWatchProviders((results === null || results === void 0 ? void 0 : results[locale]) || {}); | ||
result.providers.forEach((provider) => (provider.logo_path = this.tmdbPathPrefix(provider.logo_path, 200))); | ||
return result; | ||
} | ||
@@ -161,0 +161,0 @@ /** |
@@ -42,3 +42,3 @@ export interface TMDb { | ||
credits: TMDbCredits; | ||
watchProviders: Array<TMDbWatchProvider>; | ||
watchProviders: WatchProviders; | ||
} | ||
@@ -123,6 +123,10 @@ export declare type Movie = TMDbMovie & MediaExtras; | ||
} | ||
export interface WatchProviders { | ||
link: string; | ||
providers: Array<TMDbWatchProvider>; | ||
} | ||
export interface TMDbWatchProviderResult { | ||
id: number; | ||
results: Record<string, { | ||
link?: string; | ||
link: string; | ||
buy?: Array<TMDbWatchProvider>; | ||
@@ -129,0 +133,0 @@ rent?: Array<TMDbWatchProvider>; |
@@ -1,2 +0,2 @@ | ||
import { TMDbCrewMember, TMDbMovie, TMDbTvShow, TMDbWatchProvider, TMDbWatchProviderResult } from './interfaces'; | ||
import { TMDbCrewMember, TMDbMovie, TMDbTvShow, TMDbWatchProviderResult, WatchProviders } from './interfaces'; | ||
export declare type Duration = { | ||
@@ -24,3 +24,3 @@ years?: number | undefined; | ||
export declare function processCrewMembers(crew: Array<TMDbCrewMember>): Array<TMDbCrewMember>; | ||
export declare function processWatchProviders({ buy, rent, flatrate, }: TMDbWatchProviderResult['results']['US']): Array<TMDbWatchProvider>; | ||
export declare function processWatchProviders({ link, buy, rent, flatrate, }: TMDbWatchProviderResult['results']['US']): WatchProviders; | ||
export declare function formattedFutureDate(duration: Duration, pattern?: string): string; |
@@ -101,4 +101,8 @@ "use strict"; | ||
exports.processCrewMembers = processCrewMembers; | ||
function processWatchProviders({ buy, rent, flatrate, }) { | ||
return orderBy_1.default(lodash_1.uniqBy([...(buy || []), ...(rent || []), ...(flatrate || [])], ({ provider_id }) => provider_id), ({ display_priority }) => display_priority).slice(0, 4); | ||
function processWatchProviders({ link, buy, rent, flatrate, }) { | ||
const providers = orderBy_1.default(lodash_1.uniqBy([...(buy || []), ...(rent || []), ...(flatrate || [])], ({ provider_id }) => provider_id), ({ display_priority }) => display_priority).slice(0, 4); | ||
return { | ||
link, | ||
providers, | ||
}; | ||
} | ||
@@ -105,0 +109,0 @@ exports.processWatchProviders = processWatchProviders; |
@@ -159,6 +159,10 @@ "use strict"; | ||
it('handles an empty object', () => { | ||
expect(utils_1.processWatchProviders({})).toEqual([]); | ||
expect(utils_1.processWatchProviders({})).toEqual({ | ||
link: undefined, | ||
providers: [], | ||
}); | ||
}); | ||
it('consolidates watch providers into a single, sorted list', () => { | ||
expect(utils_1.processWatchProviders({ | ||
link: 'https://www.themoviedb.org/movie/400617-phantom-thread/watch?locale=US', | ||
buy: [ | ||
@@ -212,30 +216,33 @@ { | ||
], | ||
})).toEqual([ | ||
{ | ||
display_priority: 2, | ||
logo_path: '/q6tl6Ib6X5FT80RMlcDbexIo4St.jpg', | ||
provider_id: 2, | ||
provider_name: 'Apple iTunes', | ||
}, | ||
{ | ||
display_priority: 3, | ||
logo_path: '/p3Z12gKq2qvJaUOMeKNU2mzKVI9.jpg', | ||
provider_id: 3, | ||
provider_name: 'Google Play Movies', | ||
}, | ||
{ | ||
display_priority: 7, | ||
logo_path: '/aS2zvJWn9mwiCOeaaCkIh4wleZS.jpg', | ||
provider_id: 384, | ||
provider_name: 'HBO Max', | ||
}, | ||
{ | ||
display_priority: 15, | ||
logo_path: '/pCmBqVbaYTpTactRXXDw5O8N1VZ.jpg', | ||
provider_id: 27, | ||
provider_name: 'HBO Now', | ||
}, | ||
]); | ||
})).toEqual({ | ||
link: 'https://www.themoviedb.org/movie/400617-phantom-thread/watch?locale=US', | ||
providers: [ | ||
{ | ||
display_priority: 2, | ||
logo_path: '/q6tl6Ib6X5FT80RMlcDbexIo4St.jpg', | ||
provider_id: 2, | ||
provider_name: 'Apple iTunes', | ||
}, | ||
{ | ||
display_priority: 3, | ||
logo_path: '/p3Z12gKq2qvJaUOMeKNU2mzKVI9.jpg', | ||
provider_id: 3, | ||
provider_name: 'Google Play Movies', | ||
}, | ||
{ | ||
display_priority: 7, | ||
logo_path: '/aS2zvJWn9mwiCOeaaCkIh4wleZS.jpg', | ||
provider_id: 384, | ||
provider_name: 'HBO Max', | ||
}, | ||
{ | ||
display_priority: 15, | ||
logo_path: '/pCmBqVbaYTpTactRXXDw5O8N1VZ.jpg', | ||
provider_id: 27, | ||
provider_name: 'HBO Now', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=utils.spec.js.map |
{ | ||
"name": "@charliehess/tmdb", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "Helpers for TheMovieDB", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
46295
828