Grégoire Delattre b6be9488c9
Some checks failed
continuous-integration/drone/push Build is failing
Add a page to display a movie
2021-08-22 11:33:36 -10:00

52 lines
1.1 KiB
JavaScript

export const formatSubtitles = (subtitles) => {
if (!subtitles || subtitles.length == 0) {
return new Map();
}
let map = new Map();
subtitles.forEach((subtitle) => {
subtitle = formatSubtitle(subtitle);
map.set(subtitle.lang, subtitle);
});
return map;
};
export const formatSubtitle = (subtitle) => {
if (!subtitle) {
return undefined;
}
subtitle.searching = false;
return subtitle;
};
export const formatTorrents = (input) => {
if (!input.torrents || input.torrents.length == 0) {
return undefined;
}
let torrentMap = new Map();
input.torrents.forEach((torrent) => {
if (!torrent.result || !torrent.result.source) {
return;
}
if (!torrentMap.has(torrent.result.source)) {
torrentMap.set(torrent.result.source, new Map());
}
torrentMap.get(torrent.result.source).set(torrent.quality, torrent);
});
return torrentMap;
};
export const formatMovie = (movie) => {
movie.fetchingDetails = false;
movie.fetchingSubtitles = [];
movie.torrents = formatTorrents(movie);
movie.subtitles = formatSubtitles(movie.subtitles);
return movie;
};