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