@tdanks2000/tmdb-wrapper 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +137 -0
  2. package/dist/@types/endpoints/account.d.ts +16 -0
  3. package/dist/@types/endpoints/account.d.ts.map +1 -0
  4. package/dist/@types/endpoints/account.js +2 -0
  5. package/dist/@types/endpoints/certification.d.ts +19 -0
  6. package/dist/@types/endpoints/certification.d.ts.map +1 -0
  7. package/dist/@types/endpoints/certification.js +2 -0
  8. package/dist/@types/endpoints/changes.d.ts +26 -0
  9. package/dist/@types/endpoints/changes.d.ts.map +1 -0
  10. package/dist/@types/endpoints/changes.js +2 -0
  11. package/dist/@types/endpoints/collection.d.ts +21 -0
  12. package/dist/@types/endpoints/collection.d.ts.map +1 -0
  13. package/dist/@types/endpoints/collection.js +2 -0
  14. package/dist/@types/endpoints/companies.d.ts +29 -0
  15. package/dist/@types/endpoints/companies.d.ts.map +1 -0
  16. package/dist/@types/endpoints/companies.js +2 -0
  17. package/dist/@types/endpoints/configuration.d.ts +105 -0
  18. package/dist/@types/endpoints/configuration.d.ts.map +1 -0
  19. package/dist/@types/endpoints/configuration.js +2 -0
  20. package/dist/@types/endpoints/credits.d.ts +135 -0
  21. package/dist/@types/endpoints/credits.d.ts.map +1 -0
  22. package/dist/@types/endpoints/credits.js +2 -0
  23. package/dist/@types/endpoints/discover.d.ts +15 -0
  24. package/dist/@types/endpoints/discover.d.ts.map +1 -0
  25. package/dist/@types/endpoints/discover.js +2 -0
  26. package/dist/@types/endpoints/find.d.ts +20 -0
  27. package/dist/@types/endpoints/find.d.ts.map +1 -0
  28. package/dist/@types/endpoints/find.js +2 -0
  29. package/dist/@types/endpoints/index.d.ts +22 -0
  30. package/dist/@types/endpoints/index.d.ts.map +1 -0
  31. package/dist/@types/endpoints/index.js +37 -0
  32. package/dist/@types/endpoints/keywords.d.ts +21 -0
  33. package/dist/@types/endpoints/keywords.d.ts.map +1 -0
  34. package/dist/@types/endpoints/keywords.js +2 -0
  35. package/dist/@types/endpoints/movies.d.ts +144 -0
  36. package/dist/@types/endpoints/movies.d.ts.map +1 -0
  37. package/dist/@types/endpoints/movies.js +12 -0
  38. package/dist/@types/endpoints/networks.d.ts +14 -0
  39. package/dist/@types/endpoints/networks.d.ts.map +1 -0
  40. package/dist/@types/endpoints/networks.js +2 -0
  41. package/dist/@types/endpoints/options.d.ts +73 -0
  42. package/dist/@types/endpoints/options.d.ts.map +1 -0
  43. package/dist/@types/endpoints/options.js +2 -0
  44. package/dist/@types/endpoints/people.d.ts +135 -0
  45. package/dist/@types/endpoints/people.d.ts.map +1 -0
  46. package/dist/@types/endpoints/people.js +2 -0
  47. package/dist/@types/endpoints/review.d.ts +8 -0
  48. package/dist/@types/endpoints/review.d.ts.map +1 -0
  49. package/dist/@types/endpoints/review.js +2 -0
  50. package/dist/@types/endpoints/search.d.ts +9 -0
  51. package/dist/@types/endpoints/search.d.ts.map +1 -0
  52. package/dist/@types/endpoints/search.js +2 -0
  53. package/dist/@types/endpoints/trending.d.ts +12 -0
  54. package/dist/@types/endpoints/trending.d.ts.map +1 -0
  55. package/dist/@types/endpoints/trending.js +2 -0
  56. package/dist/@types/endpoints/tvEpisode.d.ts +53 -0
  57. package/dist/@types/endpoints/tvEpisode.d.ts.map +1 -0
  58. package/dist/@types/endpoints/tvEpisode.js +2 -0
  59. package/dist/@types/endpoints/tvSeasons.d.ts +19 -0
  60. package/dist/@types/endpoints/tvSeasons.d.ts.map +1 -0
  61. package/dist/@types/endpoints/tvSeasons.js +2 -0
  62. package/dist/@types/endpoints/tvShows.d.ts +260 -0
  63. package/dist/@types/endpoints/tvShows.d.ts.map +1 -0
  64. package/dist/@types/endpoints/tvShows.js +2 -0
  65. package/dist/@types/endpoints/watchProviders.d.ts +295 -0
  66. package/dist/@types/endpoints/watchProviders.d.ts.map +1 -0
  67. package/dist/@types/endpoints/watchProviders.js +2 -0
  68. package/dist/@types/index.d.ts +4 -0
  69. package/dist/@types/index.d.ts.map +1 -0
  70. package/dist/@types/index.js +19 -0
  71. package/dist/@types/models/baseEndpoint.d.ts +7 -0
  72. package/dist/@types/models/baseEndpoint.d.ts.map +1 -0
  73. package/dist/@types/models/baseEndpoint.js +11 -0
  74. package/dist/@types/models/index.d.ts +2 -0
  75. package/dist/@types/models/index.d.ts.map +1 -0
  76. package/dist/@types/models/index.js +17 -0
  77. package/dist/@types/types.d.ts +174 -0
  78. package/dist/@types/types.d.ts.map +1 -0
  79. package/dist/@types/types.js +2 -0
  80. package/dist/endpoints/account.d.ts +6 -0
  81. package/dist/endpoints/account.d.ts.map +1 -0
  82. package/dist/endpoints/account.js +24 -0
  83. package/dist/endpoints/certification.d.ts +8 -0
  84. package/dist/endpoints/certification.d.ts.map +1 -0
  85. package/dist/endpoints/certification.js +30 -0
  86. package/dist/endpoints/changes.d.ts +9 -0
  87. package/dist/endpoints/changes.d.ts.map +1 -0
  88. package/dist/endpoints/changes.js +35 -0
  89. package/dist/endpoints/collections.d.ts +9 -0
  90. package/dist/endpoints/collections.d.ts.map +1 -0
  91. package/dist/endpoints/collections.js +41 -0
  92. package/dist/endpoints/companies.d.ts +9 -0
  93. package/dist/endpoints/companies.d.ts.map +1 -0
  94. package/dist/endpoints/companies.js +35 -0
  95. package/dist/endpoints/configuration.d.ts +7 -0
  96. package/dist/endpoints/configuration.d.ts.map +1 -0
  97. package/dist/endpoints/configuration.js +25 -0
  98. package/dist/endpoints/credits.d.ts +7 -0
  99. package/dist/endpoints/credits.d.ts.map +1 -0
  100. package/dist/endpoints/credits.js +25 -0
  101. package/dist/endpoints/discover.d.ts +61 -0
  102. package/dist/endpoints/discover.d.ts.map +1 -0
  103. package/dist/endpoints/discover.js +30 -0
  104. package/dist/endpoints/find.d.ts +6 -0
  105. package/dist/endpoints/find.d.ts.map +1 -0
  106. package/dist/endpoints/find.js +24 -0
  107. package/dist/endpoints/genre.d.ts +14 -0
  108. package/dist/endpoints/genre.d.ts.map +1 -0
  109. package/dist/endpoints/genre.js +30 -0
  110. package/dist/endpoints/index.d.ts +19 -0
  111. package/dist/endpoints/index.d.ts.map +1 -0
  112. package/dist/endpoints/index.js +34 -0
  113. package/dist/endpoints/keywords.d.ts +7 -0
  114. package/dist/endpoints/keywords.d.ts.map +1 -0
  115. package/dist/endpoints/keywords.js +30 -0
  116. package/dist/endpoints/movies.d.ts +36 -0
  117. package/dist/endpoints/movies.d.ts.map +1 -0
  118. package/dist/endpoints/movies.js +134 -0
  119. package/dist/endpoints/networks.d.ts +9 -0
  120. package/dist/endpoints/networks.d.ts.map +1 -0
  121. package/dist/endpoints/networks.js +35 -0
  122. package/dist/endpoints/people.d.ts +16 -0
  123. package/dist/endpoints/people.d.ts.map +1 -0
  124. package/dist/endpoints/people.js +79 -0
  125. package/dist/endpoints/review.d.ts +6 -0
  126. package/dist/endpoints/review.d.ts.map +1 -0
  127. package/dist/endpoints/review.js +24 -0
  128. package/dist/endpoints/search.d.ts +39 -0
  129. package/dist/endpoints/search.d.ts.map +1 -0
  130. package/dist/endpoints/search.js +56 -0
  131. package/dist/endpoints/trending.d.ts +6 -0
  132. package/dist/endpoints/trending.d.ts.map +1 -0
  133. package/dist/endpoints/trending.js +24 -0
  134. package/dist/endpoints/tvEpisodes.d.ts +24 -0
  135. package/dist/endpoints/tvEpisodes.d.ts.map +1 -0
  136. package/dist/endpoints/tvEpisodes.js +68 -0
  137. package/dist/endpoints/tvSeasons.d.ts +25 -0
  138. package/dist/endpoints/tvSeasons.d.ts.map +1 -0
  139. package/dist/endpoints/tvSeasons.js +73 -0
  140. package/dist/endpoints/tvShows.d.ts +33 -0
  141. package/dist/endpoints/tvShows.d.ts.map +1 -0
  142. package/dist/endpoints/tvShows.js +154 -0
  143. package/dist/index.d.ts +26 -0
  144. package/dist/index.d.ts.map +1 -0
  145. package/dist/index.js +43 -0
  146. package/dist/utils/api.d.ts +7 -0
  147. package/dist/utils/api.d.ts.map +1 -0
  148. package/dist/utils/api.js +39 -0
  149. package/dist/utils/getimagePath.d.ts +12 -0
  150. package/dist/utils/getimagePath.d.ts.map +1 -0
  151. package/dist/utils/getimagePath.js +19 -0
  152. package/dist/utils/index.d.ts +3 -0
  153. package/dist/utils/index.d.ts.map +1 -0
  154. package/dist/utils/index.js +18 -0
  155. package/package.json +40 -0
  156. package/src/@types/endpoints/account.ts +17 -0
  157. package/src/@types/endpoints/certification.ts +19 -0
  158. package/src/@types/endpoints/changes.ts +29 -0
  159. package/src/@types/endpoints/collection.ts +23 -0
  160. package/src/@types/endpoints/companies.ts +33 -0
  161. package/src/@types/endpoints/configuration.ts +111 -0
  162. package/src/@types/endpoints/credits.ts +149 -0
  163. package/src/@types/endpoints/discover.ts +31 -0
  164. package/src/@types/endpoints/find.ts +28 -0
  165. package/src/@types/endpoints/index.ts +21 -0
  166. package/src/@types/endpoints/keywords.ts +24 -0
  167. package/src/@types/endpoints/movies.ts +162 -0
  168. package/src/@types/endpoints/networks.ts +15 -0
  169. package/src/@types/endpoints/options.ts +189 -0
  170. package/src/@types/endpoints/people.ts +151 -0
  171. package/src/@types/endpoints/review.ts +8 -0
  172. package/src/@types/endpoints/search.ts +10 -0
  173. package/src/@types/endpoints/trending.ts +20 -0
  174. package/src/@types/endpoints/tvEpisode.ts +58 -0
  175. package/src/@types/endpoints/tvSeasons.ts +23 -0
  176. package/src/@types/endpoints/tvShows.ts +284 -0
  177. package/src/@types/endpoints/watchProviders.ts +298 -0
  178. package/src/@types/index.ts +3 -0
  179. package/src/@types/models/baseEndpoint.ts +9 -0
  180. package/src/@types/models/index.ts +1 -0
  181. package/src/@types/types.ts +199 -0
  182. package/src/endpoints/account.ts +11 -0
  183. package/src/endpoints/certification.ts +15 -0
  184. package/src/endpoints/changes.ts +19 -0
  185. package/src/endpoints/collections.ts +32 -0
  186. package/src/endpoints/companies.ts +19 -0
  187. package/src/endpoints/configuration.ts +11 -0
  188. package/src/endpoints/credits.ts +11 -0
  189. package/src/endpoints/discover.ts +73 -0
  190. package/src/endpoints/find.ts +11 -0
  191. package/src/endpoints/genre.ts +19 -0
  192. package/src/endpoints/index.ts +18 -0
  193. package/src/endpoints/keywords.ts +17 -0
  194. package/src/endpoints/movies.ts +138 -0
  195. package/src/endpoints/networks.ts +19 -0
  196. package/src/endpoints/people.ts +79 -0
  197. package/src/endpoints/review.ts +11 -0
  198. package/src/endpoints/search.ts +78 -0
  199. package/src/endpoints/trending.ts +15 -0
  200. package/src/endpoints/tvEpisodes.ts +88 -0
  201. package/src/endpoints/tvSeasons.ts +93 -0
  202. package/src/endpoints/tvShows.ts +151 -0
  203. package/src/index.ts +66 -0
  204. package/src/utils/api.ts +31 -0
  205. package/src/utils/getimagePath.ts +16 -0
  206. package/src/utils/index.ts +2 -0
  207. package/tsconfig.json +108 -0
@@ -0,0 +1,79 @@
1
+ import {
2
+ AppendToResponse,
3
+ AppendToResponsePersonKey,
4
+ BaseEndpoint,
5
+ ChangeOption,
6
+ Changes,
7
+ ExternalIds,
8
+ LanguageOption,
9
+ PageOption,
10
+ PeopleImages,
11
+ PersonChangeValue,
12
+ PersonCombinedCredits,
13
+ PersonDetails,
14
+ PersonMovieCredit,
15
+ PersonTranslations,
16
+ PersonTvShowCredit,
17
+ PopularPersons,
18
+ TaggedImages,
19
+ } from '@/@types';
20
+
21
+ const BASE_PERSON = '/person';
22
+
23
+ export class PeopleEndpoint extends BaseEndpoint {
24
+ constructor(access_token: string) {
25
+ super(access_token);
26
+ }
27
+
28
+ async details<T extends AppendToResponsePersonKey[] | undefined>(
29
+ id: number,
30
+ appendToResponse?: T,
31
+ language?: string,
32
+ ) {
33
+ const options = {
34
+ append_to_response: appendToResponse ? appendToResponse.join(',') : undefined,
35
+ language: language,
36
+ };
37
+ return await this.api.get<AppendToResponse<PersonDetails, T, 'person'>>(`${BASE_PERSON}/${id}`, options);
38
+ }
39
+
40
+ async changes(id: number, options?: ChangeOption): Promise<Changes<PersonChangeValue>> {
41
+ return await this.api.get<Changes<PersonChangeValue>>(`${BASE_PERSON}/${id}/changes`, options);
42
+ }
43
+
44
+ async movieCredits(id: number, options?: LanguageOption): Promise<PersonMovieCredit> {
45
+ return await this.api.get<PersonMovieCredit>(`${BASE_PERSON}/${id}/movie_credits`, options);
46
+ }
47
+
48
+ async tvShowCredits(id: number, options?: LanguageOption): Promise<PersonTvShowCredit> {
49
+ return await this.api.get<PersonTvShowCredit>(`${BASE_PERSON}/${id}/tv_credits`, options);
50
+ }
51
+
52
+ async combinedCredits(id: number, options?: LanguageOption): Promise<PersonCombinedCredits> {
53
+ return await this.api.get<PersonCombinedCredits>(`${BASE_PERSON}/${id}/combined_credits`, options);
54
+ }
55
+
56
+ async externalId(id: number): Promise<ExternalIds> {
57
+ return await this.api.get<ExternalIds>(`${BASE_PERSON}/${id}/external_ids`);
58
+ }
59
+
60
+ async images(id: number): Promise<PeopleImages> {
61
+ return await this.api.get<PeopleImages>(`${BASE_PERSON}/${id}/images`);
62
+ }
63
+
64
+ async taggedImages(id: number, options?: PageOption): Promise<TaggedImages> {
65
+ return await this.api.get<TaggedImages>(`${BASE_PERSON}/${id}/tagged_images`, options);
66
+ }
67
+
68
+ async translation(id: number): Promise<PersonTranslations> {
69
+ return await this.api.get<PersonTranslations>(`${BASE_PERSON}/${id}/translations`);
70
+ }
71
+
72
+ async latest(): Promise<PersonDetails> {
73
+ return await this.api.get<PersonDetails>(`${BASE_PERSON}/latest`);
74
+ }
75
+
76
+ async popular(options?: LanguageOption & PageOption): Promise<PopularPersons> {
77
+ return await this.api.get<PopularPersons>(`${BASE_PERSON}/popular`, options);
78
+ }
79
+ }
@@ -0,0 +1,11 @@
1
+ import { BaseEndpoint, ReviewDetails } from '@/@types';
2
+
3
+ export class ReviewEndpoint extends BaseEndpoint {
4
+ constructor(access_token: string) {
5
+ super(access_token);
6
+ }
7
+
8
+ async details(id: string): Promise<ReviewDetails> {
9
+ return await this.api.get<ReviewDetails>(`/review/${id}`);
10
+ }
11
+ }
@@ -0,0 +1,78 @@
1
+ import {
2
+ BaseEndpoint,
3
+ Collection,
4
+ Company,
5
+ LanguageOption,
6
+ Movie,
7
+ MultiSearchResult,
8
+ PageOption,
9
+ Person,
10
+ RegionOption,
11
+ Search,
12
+ TV,
13
+ } from '@/@types';
14
+
15
+ const BASE_SEARCH = '/search';
16
+
17
+ export interface SearchOptions {
18
+ query: string;
19
+ page?: number;
20
+ }
21
+
22
+ export interface MovieSearchOptions extends SearchOptions, LanguageOption, PageOption, RegionOption {
23
+ include_adult?: boolean;
24
+ year?: number;
25
+ primary_release_year?: number;
26
+ }
27
+
28
+ export interface CollectionSearchOptions extends SearchOptions, LanguageOption, PageOption, RegionOption {
29
+ include_adult?: boolean;
30
+ }
31
+
32
+ export interface TvSearchOptions extends SearchOptions, LanguageOption, PageOption {
33
+ include_adult?: boolean;
34
+ year?: number;
35
+ first_air_date_year?: number;
36
+ }
37
+
38
+ export interface PeopleSearchOptions extends SearchOptions, LanguageOption, PageOption {
39
+ include_adult?: boolean;
40
+ }
41
+
42
+ export interface MultiSearchOptions extends SearchOptions, LanguageOption, PageOption {
43
+ include_adult?: boolean;
44
+ }
45
+
46
+ export class SearchEndpoint extends BaseEndpoint {
47
+ constructor(protected readonly access_token: string) {
48
+ super(access_token);
49
+ }
50
+
51
+ async companies(options: SearchOptions): Promise<Search<Company>> {
52
+ return await this.api.get<Search<Company>>(`${BASE_SEARCH}/company`, options);
53
+ }
54
+
55
+ async collections(options: SearchOptions): Promise<Search<Collection>> {
56
+ return await this.api.get<Search<Collection>>(`${BASE_SEARCH}/collection`, options);
57
+ }
58
+
59
+ async keywords(options: SearchOptions): Promise<Search<{ id: string; name: string }>> {
60
+ return await this.api.get<Search<{ id: string; name: string }>>(`${BASE_SEARCH}/keyword`, options);
61
+ }
62
+
63
+ async movies(options: MovieSearchOptions): Promise<Search<Movie>> {
64
+ return await this.api.get<Search<Movie>>(`${BASE_SEARCH}/movie`, options);
65
+ }
66
+
67
+ async people(options: PeopleSearchOptions): Promise<Search<Person>> {
68
+ return await this.api.get<Search<Person>>(`${BASE_SEARCH}/person`, options);
69
+ }
70
+
71
+ async tv(options: TvSearchOptions): Promise<Search<TV>> {
72
+ return await this.api.get<Search<TV>>(`${BASE_SEARCH}/tv`, options);
73
+ }
74
+
75
+ async multi(options: MultiSearchOptions): Promise<Search<MultiSearchResult>> {
76
+ return await this.api.get<Search<MultiSearchResult>>(`${BASE_SEARCH}/multi`, options);
77
+ }
78
+ }
@@ -0,0 +1,15 @@
1
+ import { BaseEndpoint, LanguageOption, TimeWindow, TrendingMediaType, TrendingResults } from '@/@types';
2
+
3
+ export class TrendingEndpoint extends BaseEndpoint {
4
+ constructor(access_token: string) {
5
+ super(access_token);
6
+ }
7
+
8
+ async trending<T extends TrendingMediaType>(
9
+ mediaType: T,
10
+ timeWindow: TimeWindow,
11
+ options?: LanguageOption,
12
+ ): Promise<TrendingResults<T>> {
13
+ return await this.api.get<TrendingResults<T>>(`/trending/${mediaType}/${timeWindow}`, options);
14
+ }
15
+ }
@@ -0,0 +1,88 @@
1
+ import {
2
+ AppendToResponse,
3
+ AppendToResponseTvEpisodeKey,
4
+ BaseEndpoint,
5
+ ChangeOption,
6
+ Changes,
7
+ Episode,
8
+ EpisodeSelection,
9
+ ExternalIds,
10
+ Images,
11
+ LanguageOption,
12
+ TvEpisodeChangeValue,
13
+ TvEpisodeCredit,
14
+ TvEpisodeTranslations,
15
+ Videos,
16
+ } from '@/@types';
17
+
18
+ const BASE_EPISODE = (episodeSelection: EpisodeSelection): string => {
19
+ return `/tv/${episodeSelection.tvShowID}/season/${episodeSelection.seasonNumber}/episode/${episodeSelection.episodeNumber}`;
20
+ };
21
+
22
+ export interface TvEpisodeImageSearchOptions extends LanguageOption {
23
+ /**
24
+ * a list of ISO-639-1 values to query
25
+ */
26
+ include_image_language?: string[];
27
+ }
28
+
29
+ export interface TvEpisodeVideoSearchOptions extends LanguageOption {
30
+ /**
31
+ * a list of ISO-639-1 values to query
32
+ */
33
+ include_video_language?: string[];
34
+ }
35
+
36
+ export class TvEpisodesEndpoint extends BaseEndpoint {
37
+ constructor(access_token: string) {
38
+ super(access_token);
39
+ }
40
+
41
+ async details<T extends AppendToResponseTvEpisodeKey[] | undefined>(
42
+ episodeSelection: EpisodeSelection,
43
+ appendToResponse?: T,
44
+ options?: LanguageOption,
45
+ ) {
46
+ const combinedOptions = {
47
+ append_to_response: appendToResponse ? appendToResponse.join(',') : undefined,
48
+ ...options,
49
+ };
50
+
51
+ return await this.api.get<AppendToResponse<Omit<Episode, 'show_id'>, T, 'tvEpisode'>>(
52
+ `${BASE_EPISODE(episodeSelection)}`,
53
+ combinedOptions,
54
+ );
55
+ }
56
+
57
+ async changes(episodeID: number, options?: ChangeOption) {
58
+ return await this.api.get<Changes<TvEpisodeChangeValue>>(`/tv/episode/${episodeID}/changes`, options);
59
+ }
60
+
61
+ async credits(episodeSelection: EpisodeSelection, options?: LanguageOption) {
62
+ return await this.api.get<TvEpisodeCredit>(`${BASE_EPISODE(episodeSelection)}/credits`, options);
63
+ }
64
+
65
+ async externalIds(episodeSelection: EpisodeSelection) {
66
+ return await this.api.get<ExternalIds>(`${BASE_EPISODE(episodeSelection)}/external_ids`);
67
+ }
68
+
69
+ async images(episodeSelection: EpisodeSelection, options?: TvEpisodeImageSearchOptions) {
70
+ const computedOptions = {
71
+ include_image_language: options?.include_image_language?.join(','),
72
+ language: options?.language,
73
+ };
74
+ return await this.api.get<Images>(`${BASE_EPISODE(episodeSelection)}/images`, computedOptions);
75
+ }
76
+
77
+ async translations(episodeSelection: EpisodeSelection) {
78
+ return await this.api.get<TvEpisodeTranslations>(`${BASE_EPISODE(episodeSelection)}/translations`);
79
+ }
80
+
81
+ async videos(episodeSelection: EpisodeSelection, options?: TvEpisodeVideoSearchOptions) {
82
+ const computedOptions = {
83
+ include_video_language: options?.include_video_language?.join(','),
84
+ language: options?.language,
85
+ };
86
+ return await this.api.get<Videos>(`${BASE_EPISODE(episodeSelection)}/videos`, computedOptions);
87
+ }
88
+ }
@@ -0,0 +1,93 @@
1
+ import {
2
+ AggregateCredits,
3
+ AppendToResponse,
4
+ AppendToResponseTvSeasonKey,
5
+ BaseEndpoint,
6
+ ChangeOption,
7
+ Changes,
8
+ Credits,
9
+ ExternalIds,
10
+ Images,
11
+ LanguageOption,
12
+ SeasonDetails,
13
+ SeasonSelection,
14
+ Translations,
15
+ TvSeasonChangeValue,
16
+ Videos,
17
+ } from '@/@types';
18
+
19
+ const BASE_SEASON = (seasonSelection: SeasonSelection): string => {
20
+ return `/tv/${seasonSelection.tvShowID}/season/${seasonSelection.seasonNumber}`;
21
+ };
22
+
23
+ export interface TvSeasonImageSearchOptions extends LanguageOption {
24
+ /**
25
+ * a list of ISO-639-1 values to query
26
+ */
27
+ include_image_language?: string[];
28
+ }
29
+
30
+ export interface TvSeasonVideoSearchOptions extends LanguageOption {
31
+ /**
32
+ * a list of ISO-639-1 values to query
33
+ */
34
+ include_video_language?: string[];
35
+ }
36
+
37
+ export class TvSeasonsEndpoint extends BaseEndpoint {
38
+ constructor(access_token: string) {
39
+ super(access_token);
40
+ }
41
+
42
+ async details<T extends AppendToResponseTvSeasonKey[] | undefined>(
43
+ seasonSelection: SeasonSelection,
44
+ appendToResponse?: T,
45
+ options?: LanguageOption,
46
+ ) {
47
+ const combinedOptions = {
48
+ append_to_response: appendToResponse ? appendToResponse.join(',') : undefined,
49
+ ...options,
50
+ };
51
+
52
+ return await this.api.get<AppendToResponse<SeasonDetails, T, 'tvSeason'>>(
53
+ `${BASE_SEASON(seasonSelection)}`,
54
+ combinedOptions,
55
+ );
56
+ }
57
+
58
+ async aggregateCredits(seasonSelection: SeasonSelection, options?: LanguageOption) {
59
+ return await this.api.get<AggregateCredits>(`${BASE_SEASON(seasonSelection)}/aggregate_credits`, options);
60
+ }
61
+
62
+ async changes(seasonId: number, options?: ChangeOption) {
63
+ return await this.api.get<Changes<TvSeasonChangeValue>>(`/tv/season/${seasonId}/changes`, options);
64
+ }
65
+
66
+ async credits(seasonSelection: SeasonSelection, options?: LanguageOption) {
67
+ return await this.api.get<Credits>(`${BASE_SEASON(seasonSelection)}/credits`, options);
68
+ }
69
+
70
+ async externalIds(seasonSelection: SeasonSelection, options?: LanguageOption) {
71
+ return await this.api.get<ExternalIds>(`${BASE_SEASON(seasonSelection)}/external_ids`, options);
72
+ }
73
+
74
+ async images(seasonSelection: SeasonSelection, options?: TvSeasonImageSearchOptions) {
75
+ const computedOptions = {
76
+ include_image_language: options?.include_image_language?.join(','),
77
+ language: options?.language,
78
+ };
79
+ return await this.api.get<Images>(`${BASE_SEASON(seasonSelection)}/images`, computedOptions);
80
+ }
81
+
82
+ async videos(seasonSelection: SeasonSelection, options?: TvSeasonVideoSearchOptions) {
83
+ const computedOptions = {
84
+ include_video_language: options?.include_video_language?.join(','),
85
+ language: options?.language,
86
+ };
87
+ return await this.api.get<Videos>(`${BASE_SEASON(seasonSelection)}/videos`, computedOptions);
88
+ }
89
+
90
+ async translations(seasonSelection: SeasonSelection, options?: LanguageOption) {
91
+ return await this.api.get<Translations>(`${BASE_SEASON(seasonSelection)}/translations`, options);
92
+ }
93
+ }
@@ -0,0 +1,151 @@
1
+ import {
2
+ AggregateCredits,
3
+ AlternativeTitles,
4
+ AppendToResponse,
5
+ AppendToResponseTvKey,
6
+ BaseEndpoint,
7
+ ChangeOption,
8
+ Changes,
9
+ ContentRatings,
10
+ Credits,
11
+ EpisodeGroups,
12
+ ExternalIds,
13
+ Images,
14
+ Keywords,
15
+ LanguageOption,
16
+ Latesttv,
17
+ OnTheAir,
18
+ PageOption,
19
+ Populartv,
20
+ Recommendations,
21
+ Reviews,
22
+ ScreenedTheatrically,
23
+ SeasonDetails,
24
+ Similartv,
25
+ TimezoneOption,
26
+ TopRatedtv,
27
+ Translations,
28
+ TvShowChangeValue,
29
+ TvShowDetails,
30
+ TvShowImageOptions,
31
+ TvShowVideoOptions,
32
+ Videos,
33
+ WatchProviders,
34
+ tvAiringToday,
35
+ } from '@/@types';
36
+
37
+ const BASE_TV = '/tv';
38
+
39
+ export class TvShowsEndpoint extends BaseEndpoint {
40
+ constructor(protected readonly access_token: string) {
41
+ super(access_token);
42
+ }
43
+
44
+ async details<T extends AppendToResponseTvKey[] | undefined>(id: number, appendToResponse?: T, language?: string) {
45
+ const options = {
46
+ append_to_response: appendToResponse ? appendToResponse.join(',') : undefined,
47
+ language: language,
48
+ };
49
+ return await this.api.get<AppendToResponse<TvShowDetails, T, 'tvShow'>>(`${BASE_TV}/${id}`, options);
50
+ }
51
+
52
+ async alternativeTitles(id: number): Promise<AlternativeTitles> {
53
+ return await this.api.get<AlternativeTitles>(`${BASE_TV}/${id}/alternative_titles`);
54
+ }
55
+
56
+ async changes(id: number, options?: ChangeOption): Promise<Changes<TvShowChangeValue>> {
57
+ return await this.api.get<Changes<TvShowChangeValue>>(`${BASE_TV}/${id}/changes`, options);
58
+ }
59
+
60
+ async contentRatings(id: number): Promise<ContentRatings> {
61
+ return await this.api.get<ContentRatings>(`${BASE_TV}/${id}/content_ratings`);
62
+ }
63
+
64
+ async aggregateCredits(id: number, options?: LanguageOption): Promise<AggregateCredits> {
65
+ return await this.api.get<AggregateCredits>(`${BASE_TV}/${id}/aggregate_credits`, options);
66
+ }
67
+
68
+ async credits(id: number, options?: LanguageOption): Promise<Credits> {
69
+ return await this.api.get<Credits>(`${BASE_TV}/${id}/credits`, options);
70
+ }
71
+
72
+ async season(tvId: number, seasonNumber: number): Promise<SeasonDetails> {
73
+ return await this.api.get<SeasonDetails>(`${BASE_TV}/${tvId}/season/${seasonNumber}`);
74
+ }
75
+
76
+ async episodeGroups(id: number): Promise<EpisodeGroups> {
77
+ return await this.api.get<EpisodeGroups>(`${BASE_TV}/${id}/episode_groups`);
78
+ }
79
+
80
+ async externalIds(id: number): Promise<ExternalIds> {
81
+ return await this.api.get<ExternalIds>(`${BASE_TV}/${id}/external_ids`);
82
+ }
83
+
84
+ async images(id: number, options?: TvShowImageOptions): Promise<Images> {
85
+ const computedOptions = {
86
+ include_image_language: options?.include_image_language?.join(','),
87
+ language: options?.language,
88
+ };
89
+ return await this.api.get<Images>(`${BASE_TV}/${id}/images`, computedOptions);
90
+ }
91
+
92
+ async keywords(id: number): Promise<Keywords> {
93
+ return await this.api.get<Keywords>(`${BASE_TV}/${id}/keywords`);
94
+ }
95
+
96
+ async recommendations(id: number, options?: LanguageOption & PageOption): Promise<Recommendations> {
97
+ return await this.api.get<Recommendations>(`${BASE_TV}/${id}/recommendations`, options);
98
+ }
99
+
100
+ async reviews(id: number, options?: LanguageOption & PageOption): Promise<Reviews> {
101
+ return await this.api.get<Reviews>(`${BASE_TV}/${id}/reviews`, options);
102
+ }
103
+
104
+ async screenedTheatrically(id: number): Promise<ScreenedTheatrically> {
105
+ return await this.api.get<ScreenedTheatrically>(`${BASE_TV}/${id}/screened_theatrically`);
106
+ }
107
+
108
+ async similar(id: number, options?: LanguageOption & PageOption): Promise<Similartv> {
109
+ return await this.api.get<Similartv>(`${BASE_TV}/${id}/similar`, options);
110
+ }
111
+
112
+ async translations(id: number): Promise<Translations> {
113
+ return await this.api.get<Translations>(`${BASE_TV}/${id}/translations`);
114
+ }
115
+
116
+ async videos(id: number, options?: TvShowVideoOptions): Promise<Videos> {
117
+ const computedOptions = {
118
+ include_video_language: options?.include_video_language?.join(','),
119
+ language: options?.language,
120
+ };
121
+ return await this.api.get<Videos>(`${BASE_TV}/${id}/videos`, computedOptions);
122
+ }
123
+
124
+ /**
125
+ * Powered by JustWatch
126
+ * @param id
127
+ */
128
+ async watchProviders(id: number): Promise<WatchProviders> {
129
+ return await this.api.get<WatchProviders>(`${BASE_TV}/${id}/watch/providers`);
130
+ }
131
+
132
+ async latest(): Promise<Latesttv> {
133
+ return await this.api.get<Latesttv>(`${BASE_TV}/latest`);
134
+ }
135
+
136
+ async onTheAir(options?: PageOption & LanguageOption & TimezoneOption): Promise<OnTheAir> {
137
+ return await this.api.get<OnTheAir>(`${BASE_TV}/on_the_air`, options);
138
+ }
139
+
140
+ async airingToday(options?: PageOption & LanguageOption & TimezoneOption): Promise<tvAiringToday> {
141
+ return await this.api.get<tvAiringToday>(`${BASE_TV}/airing_today`, options);
142
+ }
143
+
144
+ async popular(options?: PageOption & LanguageOption): Promise<Populartv> {
145
+ return await this.api.get<Populartv>(`${BASE_TV}/popular`, options);
146
+ }
147
+
148
+ async topRated(options?: PageOption & LanguageOption): Promise<TopRatedtv> {
149
+ return await this.api.get<TopRatedtv>(`${BASE_TV}/top_rated`, options);
150
+ }
151
+ }
package/src/index.ts ADDED
@@ -0,0 +1,66 @@
1
+ import {
2
+ AccountEndpoint,
3
+ CertificationEndpoint,
4
+ ChangeEndpoint,
5
+ CollectionsEndpoint,
6
+ ConfigurationEndpoint,
7
+ CreditsEndpoint,
8
+ DiscoverEndpoint,
9
+ FindEndpoint,
10
+ GenreEndpoint,
11
+ KeywordsEndpoint,
12
+ MoviesEndpoint,
13
+ PeopleEndpoint,
14
+ ReviewEndpoint,
15
+ SearchEndpoint,
16
+ TrendingEndpoint,
17
+ TvEpisodesEndpoint,
18
+ TvSeasonsEndpoint,
19
+ TvShowsEndpoint,
20
+ } from '@/endpoints';
21
+
22
+ class TMDB {
23
+ constructor(access_token: string) {
24
+ this.account = new AccountEndpoint(access_token);
25
+ this.certification = new CertificationEndpoint(access_token);
26
+ this.changes = new ChangeEndpoint(access_token);
27
+ this.collections = new CollectionsEndpoint(access_token);
28
+ this.configuration = new ConfigurationEndpoint(access_token);
29
+ this.credits = new CreditsEndpoint(access_token);
30
+ this.discover = new DiscoverEndpoint(access_token);
31
+ this.find = new FindEndpoint(access_token);
32
+ this.genre = new GenreEndpoint(access_token);
33
+ this.keywords = new KeywordsEndpoint(access_token);
34
+ this.movies = new MoviesEndpoint(access_token);
35
+ this.people = new PeopleEndpoint(access_token);
36
+ this.review = new ReviewEndpoint(access_token);
37
+ this.search = new SearchEndpoint(access_token);
38
+ this.trending = new TrendingEndpoint(access_token);
39
+ this.tvEpisodes = new TvEpisodesEndpoint(access_token);
40
+ this.tvSeasons = new TvSeasonsEndpoint(access_token);
41
+ this.tvShows = new TvShowsEndpoint(access_token);
42
+ }
43
+
44
+ account: AccountEndpoint;
45
+ certification: CertificationEndpoint;
46
+ changes: ChangeEndpoint;
47
+ collections: CollectionsEndpoint;
48
+ configuration: ConfigurationEndpoint;
49
+ credits: CreditsEndpoint;
50
+ discover: DiscoverEndpoint;
51
+ find: FindEndpoint;
52
+ genre: GenreEndpoint;
53
+ keywords: KeywordsEndpoint;
54
+ movies: MoviesEndpoint;
55
+ people: PeopleEndpoint;
56
+ review: ReviewEndpoint;
57
+ search: SearchEndpoint;
58
+ trending: TrendingEndpoint;
59
+ tvEpisodes: TvEpisodesEndpoint;
60
+ tvSeasons: TvSeasonsEndpoint;
61
+ tvShows: TvShowsEndpoint;
62
+ }
63
+
64
+ export * from './@types';
65
+ export * from './utils';
66
+ export { TMDB };
@@ -0,0 +1,31 @@
1
+ import { ErrorResponse } from '@/@types';
2
+
3
+ const BASE_URL_V3 = 'https://api.themoviedb.org/3';
4
+
5
+ export class API {
6
+ private access_token: string;
7
+ constructor(access_token: string) {
8
+ this.access_token = access_token;
9
+ }
10
+
11
+ async get<T>(path: string, options?: Record<string, any>): Promise<T> {
12
+ const params = parseOptions(options);
13
+ const response = await fetch(`${BASE_URL_V3}${path}?${params}`, {
14
+ method: 'GET',
15
+ headers: {
16
+ Authorization: `Bearer ${this.access_token}`,
17
+ 'Content-Type': 'application/json;charset=utf-8',
18
+ },
19
+ });
20
+
21
+ if (!response.ok) {
22
+ return Promise.reject((await response.json()) as ErrorResponse);
23
+ }
24
+
25
+ return (await response.json()) as T;
26
+ }
27
+ }
28
+
29
+ export const parseOptions = (options?: Record<string, any>): string => {
30
+ return options ? new URLSearchParams(Object.entries(options)).toString() : '';
31
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Utility method to construct full url for image
3
+ * based on configuration
4
+ *
5
+ * https://developers.themoviedb.org/3/getting-started/images
6
+ * @param {string} baseUrl base image url
7
+ * @param {string} fileSize file size
8
+ * @param {string} imagePath raw image path
9
+ * @param {boolean} svg get svg version if true
10
+ */
11
+ export const getFullImagePath = (baseUrl: string, fileSize: string, imagePath: string, svg = false): string => {
12
+ const imagePathArr = imagePath.split('.');
13
+ const imageFormat = svg ? 'svg' : imagePathArr[1];
14
+
15
+ return `${baseUrl}${fileSize}${imagePathArr[0]}.${imageFormat}`;
16
+ };
@@ -0,0 +1,2 @@
1
+ export * from './api';
2
+ export * from './getimagePath';