identify-media
Version:
Analyse file path and content to make search criteria for media APIs
71 lines • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSameQuery = exports.mapFindResult = exports.mapSearchResult = exports.mapAnalysedMedia = void 0;
const analyseFilePath_1 = require("../../lib/analyseFilePath");
const types_1 = require("./types");
const mapAnalysedMedia = (media, language, page) => {
if (typeof media === 'string')
return { query: media, language, page };
if ((0, analyseFilePath_1.isAnalysedMovie)(media) || (0, analyseFilePath_1.isAnalysedTVShow)(media))
return { query: media.name, type: media.type, year: media.year, language, page };
throw new Error('media of unknown type: ' + JSON.stringify(media));
};
exports.mapAnalysedMedia = mapAnalysedMedia;
const makeImages = (images) => {
const retval = {};
if (!!images.poster_path) {
retval['tmdb-poster'] = images.poster_path;
}
if (!!images.backdrop_path) {
retval['tmdb-backdrop'] = images.backdrop_path;
}
return retval;
};
const mapMovieResult = (result) => ({
type: 'movie',
tmdbId: result.id,
title: result.title,
release: result.release_date,
mediaInfo: {
plot: result.overview,
images: makeImages(result),
}
});
const mapTvResult = (result) => ({
type: 'tv',
tmdbId: result.id,
name: result.name,
firstAirDate: result.first_air_date,
mediaInfo: {
plot: result.overview,
images: makeImages(result),
}
});
const mapSearchResult = (result) => {
if (result.results.length === 0)
throw new Error('No search result');
return result.results.map((result) => {
if ((0, types_1.isTmdbMovieResult)(result)) {
return mapMovieResult(result);
}
else {
return mapTvResult(result);
}
});
};
exports.mapSearchResult = mapSearchResult;
const mapFindResult = (result) => {
var _a, _b, _c, _d;
if ((((_a = result.tv_results) === null || _a === void 0 ? void 0 : _a.length) || 0) + (((_b = result.movie_results) === null || _b === void 0 ? void 0 : _b.length) || 0) === 0)
throw new Error('No find result');
return (((_c = result.tv_results) === null || _c === void 0 ? void 0 : _c.map(mapTvResult)) || [])
.concat(((_d = result.movie_results) === null || _d === void 0 ? void 0 : _d.map(mapMovieResult)) || []);
};
exports.mapFindResult = mapFindResult;
const isSameQuery = (a, b) => a.query === b.query
&& a.type === b.type
&& a.year === b.year
&& a.page === b.page
&& a.language === b.language;
exports.isSameQuery = isSameQuery;
//# sourceMappingURL=mapper.js.map