|
|
@ -37,54 +37,15 @@ export const createTmdbWithRegionLanguage = (user?: User): TheMovieDb => {
|
|
|
|
|
|
|
|
|
|
|
|
const discoverRoutes = Router();
|
|
|
|
const discoverRoutes = Router();
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get('/movies', async (req, res) => {
|
|
|
|
discoverRoutes.get('/movies', async (req, res, next) => {
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverMovies({
|
|
|
|
try {
|
|
|
|
page: Number(req.query.page),
|
|
|
|
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
genre: req.query.genre ? Number(req.query.genre) : undefined,
|
|
|
|
|
|
|
|
studio: req.query.studio ? Number(req.query.studio) : undefined,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
page: data.page,
|
|
|
|
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
|
|
|
|
totalResults: data.total_results,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
|
|
|
|
mapMovieResult(
|
|
|
|
|
|
|
|
result,
|
|
|
|
|
|
|
|
media.find(
|
|
|
|
|
|
|
|
(req) => req.tmdbId === result.id && req.mediaType === MediaType.MOVIE
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get<{ language: string }>(
|
|
|
|
|
|
|
|
'/movies/language/:language',
|
|
|
|
|
|
|
|
async (req, res, next) => {
|
|
|
|
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const languages = await tmdb.getLanguages();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const language = languages.find(
|
|
|
|
|
|
|
|
(lang) => lang.iso_639_1 === req.params.language
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!language) {
|
|
|
|
|
|
|
|
return next({ status: 404, message: 'Unable to retrieve language' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverMovies({
|
|
|
|
const data = await tmdb.getDiscoverMovies({
|
|
|
|
page: Number(req.query.page),
|
|
|
|
page: Number(req.query.page),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
originalLanguage: req.params.language,
|
|
|
|
genre: req.query.genre ? Number(req.query.genre) : undefined,
|
|
|
|
|
|
|
|
studio: req.query.studio ? Number(req.query.studio) : undefined,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
@ -95,7 +56,6 @@ discoverRoutes.get<{ language: string }>(
|
|
|
|
page: data.page,
|
|
|
|
page: data.page,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
language,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
mapMovieResult(
|
|
|
|
mapMovieResult(
|
|
|
|
result,
|
|
|
|
result,
|
|
|
@ -106,6 +66,70 @@ discoverRoutes.get<{ language: string }>(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving popular movies', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve popular movies.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get<{ language: string }>(
|
|
|
|
|
|
|
|
'/movies/language/:language',
|
|
|
|
|
|
|
|
async (req, res, next) => {
|
|
|
|
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const languages = await tmdb.getLanguages();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const language = languages.find(
|
|
|
|
|
|
|
|
(lang) => lang.iso_639_1 === req.params.language
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!language) {
|
|
|
|
|
|
|
|
return next({ status: 404, message: 'Language not found.' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverMovies({
|
|
|
|
|
|
|
|
page: Number(req.query.page),
|
|
|
|
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
originalLanguage: req.params.language,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
page: data.page,
|
|
|
|
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
|
|
|
|
totalResults: data.total_results,
|
|
|
|
|
|
|
|
language,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
|
|
|
|
mapMovieResult(
|
|
|
|
|
|
|
|
result,
|
|
|
|
|
|
|
|
media.find(
|
|
|
|
|
|
|
|
(req) =>
|
|
|
|
|
|
|
|
req.tmdbId === result.id && req.mediaType === MediaType.MOVIE
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving movies by language', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
language: req.params.language,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve movies by language.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -114,43 +138,55 @@ discoverRoutes.get<{ genreId: string }>(
|
|
|
|
async (req, res, next) => {
|
|
|
|
async (req, res, next) => {
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
const genres = await tmdb.getMovieGenres({
|
|
|
|
try {
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
const genres = await tmdb.getMovieGenres({
|
|
|
|
});
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const genre = genres.find(
|
|
|
|
const genre = genres.find(
|
|
|
|
(genre) => genre.id === Number(req.params.genreId)
|
|
|
|
(genre) => genre.id === Number(req.params.genreId)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!genre) {
|
|
|
|
if (!genre) {
|
|
|
|
return next({ status: 404, message: 'Unable to retrieve genre' });
|
|
|
|
return next({ status: 404, message: 'Genre not found.' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverMovies({
|
|
|
|
const data = await tmdb.getDiscoverMovies({
|
|
|
|
page: Number(req.query.page),
|
|
|
|
page: Number(req.query.page),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
genre: Number(req.params.genreId),
|
|
|
|
genre: Number(req.params.genreId),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
return res.status(200).json({
|
|
|
|
page: data.page,
|
|
|
|
page: data.page,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
genre,
|
|
|
|
genre,
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
mapMovieResult(
|
|
|
|
mapMovieResult(
|
|
|
|
result,
|
|
|
|
result,
|
|
|
|
media.find(
|
|
|
|
media.find(
|
|
|
|
(req) =>
|
|
|
|
(req) =>
|
|
|
|
req.tmdbId === result.id && req.mediaType === MediaType.MOVIE
|
|
|
|
req.tmdbId === result.id && req.mediaType === MediaType.MOVIE
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving movies by genre', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
genreId: req.params.genreId,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve movies by genre.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -188,12 +224,20 @@ discoverRoutes.get<{ studioId: string }>(
|
|
|
|
),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
return next({ status: 404, message: 'Unable to retrieve studio' });
|
|
|
|
logger.debug('Something went wrong retrieving movies by studio', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
studioId: req.params.studioId,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve movies by studio.',
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get('/movies/upcoming', async (req, res) => {
|
|
|
|
discoverRoutes.get('/movies/upcoming', async (req, res, next) => {
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
const now = new Date();
|
|
|
|
const now = new Date();
|
|
|
@ -202,79 +246,11 @@ discoverRoutes.get('/movies/upcoming', async (req, res) => {
|
|
|
|
.toISOString()
|
|
|
|
.toISOString()
|
|
|
|
.split('T')[0];
|
|
|
|
.split('T')[0];
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverMovies({
|
|
|
|
try {
|
|
|
|
page: Number(req.query.page),
|
|
|
|
const data = await tmdb.getDiscoverMovies({
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
primaryReleaseDateGte: date,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
page: data.page,
|
|
|
|
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
|
|
|
|
totalResults: data.total_results,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
|
|
|
|
mapMovieResult(
|
|
|
|
|
|
|
|
result,
|
|
|
|
|
|
|
|
media.find(
|
|
|
|
|
|
|
|
(med) => med.tmdbId === result.id && med.mediaType === MediaType.MOVIE
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get('/tv', async (req, res) => {
|
|
|
|
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverTv({
|
|
|
|
|
|
|
|
page: Number(req.query.page),
|
|
|
|
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
genre: req.query.genre ? Number(req.query.genre) : undefined,
|
|
|
|
|
|
|
|
network: req.query.network ? Number(req.query.network) : undefined,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
page: data.page,
|
|
|
|
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
|
|
|
|
totalResults: data.total_results,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
|
|
|
|
mapTvResult(
|
|
|
|
|
|
|
|
result,
|
|
|
|
|
|
|
|
media.find(
|
|
|
|
|
|
|
|
(med) => med.tmdbId === result.id && med.mediaType === MediaType.TV
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get<{ language: string }>(
|
|
|
|
|
|
|
|
'/tv/language/:language',
|
|
|
|
|
|
|
|
async (req, res, next) => {
|
|
|
|
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const languages = await tmdb.getLanguages();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const language = languages.find(
|
|
|
|
|
|
|
|
(lang) => lang.iso_639_1 === req.params.language
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!language) {
|
|
|
|
|
|
|
|
return next({ status: 404, message: 'Unable to retrieve language' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverTv({
|
|
|
|
|
|
|
|
page: Number(req.query.page),
|
|
|
|
page: Number(req.query.page),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
originalLanguage: req.params.language,
|
|
|
|
primaryReleaseDateGte: date,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
@ -285,40 +261,37 @@ discoverRoutes.get<{ language: string }>(
|
|
|
|
page: data.page,
|
|
|
|
page: data.page,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
language,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
mapTvResult(
|
|
|
|
mapMovieResult(
|
|
|
|
result,
|
|
|
|
result,
|
|
|
|
media.find(
|
|
|
|
media.find(
|
|
|
|
(med) => med.tmdbId === result.id && med.mediaType === MediaType.TV
|
|
|
|
(med) =>
|
|
|
|
|
|
|
|
med.tmdbId === result.id && med.mediaType === MediaType.MOVIE
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
);
|
|
|
|
logger.debug('Something went wrong retrieving upcoming movies', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
discoverRoutes.get<{ genreId: string }>(
|
|
|
|
errorMessage: e.message,
|
|
|
|
'/tv/genre/:genreId',
|
|
|
|
|
|
|
|
async (req, res, next) => {
|
|
|
|
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const genres = await tmdb.getTvGenres({
|
|
|
|
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve upcoming movies.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const genre = genres.find(
|
|
|
|
discoverRoutes.get('/tv', async (req, res, next) => {
|
|
|
|
(genre) => genre.id === Number(req.params.genreId)
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!genre) {
|
|
|
|
|
|
|
|
return next({ status: 404, message: 'Unable to retrieve genre' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
const data = await tmdb.getDiscoverTv({
|
|
|
|
const data = await tmdb.getDiscoverTv({
|
|
|
|
page: Number(req.query.page),
|
|
|
|
page: Number(req.query.page),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
genre: Number(req.params.genreId),
|
|
|
|
genre: req.query.genre ? Number(req.query.genre) : undefined,
|
|
|
|
|
|
|
|
network: req.query.network ? Number(req.query.network) : undefined,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
@ -329,7 +302,6 @@ discoverRoutes.get<{ genreId: string }>(
|
|
|
|
page: data.page,
|
|
|
|
page: data.page,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
genre,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
mapTvResult(
|
|
|
|
mapTvResult(
|
|
|
|
result,
|
|
|
|
result,
|
|
|
@ -339,21 +311,38 @@ discoverRoutes.get<{ genreId: string }>(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving popular series', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve popular series.',
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get<{ networkId: string }>(
|
|
|
|
discoverRoutes.get<{ language: string }>(
|
|
|
|
'/tv/network/:networkId',
|
|
|
|
'/tv/language/:language',
|
|
|
|
async (req, res, next) => {
|
|
|
|
async (req, res, next) => {
|
|
|
|
const tmdb = new TheMovieDb();
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const network = await tmdb.getNetwork(Number(req.params.networkId));
|
|
|
|
const languages = await tmdb.getLanguages();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const language = languages.find(
|
|
|
|
|
|
|
|
(lang) => lang.iso_639_1 === req.params.language
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!language) {
|
|
|
|
|
|
|
|
return next({ status: 404, message: 'Language not found.' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverTv({
|
|
|
|
const data = await tmdb.getDiscoverTv({
|
|
|
|
page: Number(req.query.page),
|
|
|
|
page: Number(req.query.page),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
network: Number(req.params.networkId),
|
|
|
|
originalLanguage: req.params.language,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
@ -364,7 +353,7 @@ discoverRoutes.get<{ networkId: string }>(
|
|
|
|
page: data.page,
|
|
|
|
page: data.page,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
network: mapNetwork(network),
|
|
|
|
language,
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
mapTvResult(
|
|
|
|
mapTvResult(
|
|
|
|
result,
|
|
|
|
result,
|
|
|
@ -376,92 +365,137 @@ discoverRoutes.get<{ networkId: string }>(
|
|
|
|
),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
return next({ status: 404, message: 'Unable to retrieve network' });
|
|
|
|
logger.debug('Something went wrong retrieving series by language', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
language: req.params.language,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve series by language.',
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get('/tv/upcoming', async (req, res) => {
|
|
|
|
discoverRoutes.get<{ genreId: string }>(
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
'/tv/genre/:genreId',
|
|
|
|
|
|
|
|
async (req, res, next) => {
|
|
|
|
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
const now = new Date();
|
|
|
|
try {
|
|
|
|
const offset = now.getTimezoneOffset();
|
|
|
|
const genres = await tmdb.getTvGenres({
|
|
|
|
const date = new Date(now.getTime() - offset * 60 * 1000)
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
.toISOString()
|
|
|
|
});
|
|
|
|
.split('T')[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverTv({
|
|
|
|
const genre = genres.find(
|
|
|
|
page: Number(req.query.page),
|
|
|
|
(genre) => genre.id === Number(req.params.genreId)
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
);
|
|
|
|
firstAirDateGte: date,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
if (!genre) {
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
return next({ status: 404, message: 'Genre not found.' });
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
page: data.page,
|
|
|
|
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
|
|
|
|
totalResults: data.total_results,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
|
|
|
|
mapTvResult(
|
|
|
|
|
|
|
|
result,
|
|
|
|
|
|
|
|
media.find(
|
|
|
|
|
|
|
|
(med) => med.tmdbId === result.id && med.mediaType === MediaType.TV
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get('/trending', async (req, res) => {
|
|
|
|
const data = await tmdb.getDiscoverTv({
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
page: Number(req.query.page),
|
|
|
|
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
genre: Number(req.params.genreId),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getAllTrending({
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
page: Number(req.query.page),
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
return res.status(200).json({
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
page: data.page,
|
|
|
|
);
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
|
|
|
|
totalResults: data.total_results,
|
|
|
|
return res.status(200).json({
|
|
|
|
genre,
|
|
|
|
page: data.page,
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
mapTvResult(
|
|
|
|
totalResults: data.total_results,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
|
|
|
|
isMovie(result)
|
|
|
|
|
|
|
|
? mapMovieResult(
|
|
|
|
|
|
|
|
result,
|
|
|
|
result,
|
|
|
|
media.find(
|
|
|
|
media.find(
|
|
|
|
(med) =>
|
|
|
|
(med) =>
|
|
|
|
med.tmdbId === result.id && med.mediaType === MediaType.MOVIE
|
|
|
|
med.tmdbId === result.id && med.mediaType === MediaType.TV
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: isPerson(result)
|
|
|
|
),
|
|
|
|
? mapPersonResult(result)
|
|
|
|
});
|
|
|
|
: mapTvResult(
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving series by genre', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
genreId: req.params.genreId,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve series by genre.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get<{ networkId: string }>(
|
|
|
|
|
|
|
|
'/tv/network/:networkId',
|
|
|
|
|
|
|
|
async (req, res, next) => {
|
|
|
|
|
|
|
|
const tmdb = new TheMovieDb();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const network = await tmdb.getNetwork(Number(req.params.networkId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverTv({
|
|
|
|
|
|
|
|
page: Number(req.query.page),
|
|
|
|
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
network: Number(req.params.networkId),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
page: data.page,
|
|
|
|
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
|
|
|
|
totalResults: data.total_results,
|
|
|
|
|
|
|
|
network: mapNetwork(network),
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
|
|
|
|
mapTvResult(
|
|
|
|
result,
|
|
|
|
result,
|
|
|
|
media.find(
|
|
|
|
media.find(
|
|
|
|
(med) =>
|
|
|
|
(med) =>
|
|
|
|
med.tmdbId === result.id && med.mediaType === MediaType.TV
|
|
|
|
med.tmdbId === result.id && med.mediaType === MediaType.TV
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving series by network', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
networkId: req.params.networkId,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve series by network.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get<{ keywordId: string }>(
|
|
|
|
discoverRoutes.get('/tv/upcoming', async (req, res, next) => {
|
|
|
|
'/keyword/:keywordId/movies',
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
async (req, res) => {
|
|
|
|
|
|
|
|
const tmdb = new TheMovieDb();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = await tmdb.getMoviesByKeyword({
|
|
|
|
const now = new Date();
|
|
|
|
keywordId: Number(req.params.keywordId),
|
|
|
|
const offset = now.getTimezoneOffset();
|
|
|
|
|
|
|
|
const date = new Date(now.getTime() - offset * 60 * 1000)
|
|
|
|
|
|
|
|
.toISOString()
|
|
|
|
|
|
|
|
.split('T')[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const data = await tmdb.getDiscoverTv({
|
|
|
|
page: Number(req.query.page),
|
|
|
|
page: Number(req.query.page),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
firstAirDateGte: date,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
@ -473,15 +507,116 @@ discoverRoutes.get<{ keywordId: string }>(
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
totalResults: data.total_results,
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
mapMovieResult(
|
|
|
|
mapTvResult(
|
|
|
|
result,
|
|
|
|
result,
|
|
|
|
media.find(
|
|
|
|
media.find(
|
|
|
|
(med) =>
|
|
|
|
(med) => med.tmdbId === result.id && med.mediaType === MediaType.TV
|
|
|
|
med.tmdbId === result.id && med.mediaType === MediaType.MOVIE
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving upcoming series', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve upcoming series.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get('/trending', async (req, res, next) => {
|
|
|
|
|
|
|
|
const tmdb = createTmdbWithRegionLanguage(req.user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const data = await tmdb.getAllTrending({
|
|
|
|
|
|
|
|
page: Number(req.query.page),
|
|
|
|
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
page: data.page,
|
|
|
|
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
|
|
|
|
totalResults: data.total_results,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
|
|
|
|
isMovie(result)
|
|
|
|
|
|
|
|
? mapMovieResult(
|
|
|
|
|
|
|
|
result,
|
|
|
|
|
|
|
|
media.find(
|
|
|
|
|
|
|
|
(med) =>
|
|
|
|
|
|
|
|
med.tmdbId === result.id && med.mediaType === MediaType.MOVIE
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
: isPerson(result)
|
|
|
|
|
|
|
|
? mapPersonResult(result)
|
|
|
|
|
|
|
|
: mapTvResult(
|
|
|
|
|
|
|
|
result,
|
|
|
|
|
|
|
|
media.find(
|
|
|
|
|
|
|
|
(med) =>
|
|
|
|
|
|
|
|
med.tmdbId === result.id && med.mediaType === MediaType.TV
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving trending items', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve trending items.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
discoverRoutes.get<{ keywordId: string }>(
|
|
|
|
|
|
|
|
'/keyword/:keywordId/movies',
|
|
|
|
|
|
|
|
async (req, res, next) => {
|
|
|
|
|
|
|
|
const tmdb = new TheMovieDb();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const data = await tmdb.getMoviesByKeyword({
|
|
|
|
|
|
|
|
keywordId: Number(req.params.keywordId),
|
|
|
|
|
|
|
|
page: Number(req.query.page),
|
|
|
|
|
|
|
|
language: req.locale ?? (req.query.language as string),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const media = await Media.getRelatedMedia(
|
|
|
|
|
|
|
|
data.results.map((result) => result.id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
page: data.page,
|
|
|
|
|
|
|
|
totalPages: data.total_pages,
|
|
|
|
|
|
|
|
totalResults: data.total_results,
|
|
|
|
|
|
|
|
results: data.results.map((result) =>
|
|
|
|
|
|
|
|
mapMovieResult(
|
|
|
|
|
|
|
|
result,
|
|
|
|
|
|
|
|
media.find(
|
|
|
|
|
|
|
|
(med) =>
|
|
|
|
|
|
|
|
med.tmdbId === result.id && med.mediaType === MediaType.MOVIE
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.debug('Something went wrong retrieving movies by keyword', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
|
|
|
|
errorMessage: e.message,
|
|
|
|
|
|
|
|
keywordId: req.params.keywordId,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return next({
|
|
|
|
|
|
|
|
status: 500,
|
|
|
|
|
|
|
|
message: 'Unable to retrieve movies by keyword.',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -515,7 +650,8 @@ discoverRoutes.get<{ language: string }, GenreSliderItem[]>(
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json(sortedData);
|
|
|
|
return res.status(200).json(sortedData);
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
logger.error('Something went wrong retrieving the movie genre slider', {
|
|
|
|
logger.debug('Something went wrong retrieving the movie genre slider', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
errorMessage: e.message,
|
|
|
|
errorMessage: e.message,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return next({
|
|
|
|
return next({
|
|
|
@ -556,12 +692,13 @@ discoverRoutes.get<{ language: string }, GenreSliderItem[]>(
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json(sortedData);
|
|
|
|
return res.status(200).json(sortedData);
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
logger.error('Something went wrong retrieving the tv genre slider', {
|
|
|
|
logger.debug('Something went wrong retrieving the series genre slider', {
|
|
|
|
|
|
|
|
label: 'API',
|
|
|
|
errorMessage: e.message,
|
|
|
|
errorMessage: e.message,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return next({
|
|
|
|
return next({
|
|
|
|
status: 500,
|
|
|
|
status: 500,
|
|
|
|
message: 'Unable to retrieve tv genre slider.',
|
|
|
|
message: 'Unable to retrieve series genre slider.',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|