Now our convert scripts use our new plex and tmdb classes. Also compacted and abstracted a lot of the code here.
This commit is contained in:
@@ -1,57 +1,39 @@
|
||||
const Movie = require('src/media_classes/movie');
|
||||
const Show = require('src/media_classes/show');
|
||||
|
||||
function convertTmdbToSeasoned(tmdbObject, strictType=undefined) {
|
||||
// TODO create a default fallback class to set the when falls to else as both are undefined
|
||||
if (tmdbObject.media_type !== undefined)
|
||||
var mediaType = tmdbObject.media_type;
|
||||
else if (strictType !== undefined)
|
||||
var mediaType = strictType;
|
||||
else
|
||||
var mediaType = 'movie';
|
||||
const TMDB = require('src/media_classes/tmdb');
|
||||
|
||||
// There are many diff types of content, we only want to look at movies and tv shows
|
||||
if (mediaType === 'movie') {
|
||||
const year = new Date(tmdbObject.release_date).getFullYear();
|
||||
function translateYear(tmdbReleaseDate) {
|
||||
return new Date(tmdbReleaseDate).getFullYear();
|
||||
}
|
||||
|
||||
if (tmdbObject.title !== undefined) {
|
||||
var title = tmdbObject.title;
|
||||
} else if (tmdbObject.name !== undefined) {
|
||||
var title = tmdbObject.name;
|
||||
}
|
||||
function translateGenre(tmdbGenres) {
|
||||
return tmdbGenres.map(genre => genre.name);
|
||||
}
|
||||
|
||||
const movie = new Movie(title, year, mediaType);
|
||||
function convertTmdbToSeasoned(tmdb, manualType = undefined) {
|
||||
const title = tmdb.title || tmdb.name;
|
||||
const year = translateYear(tmdb.release_date || tmdb.first_air_date);
|
||||
const type = tmdb.media_type || manualType;
|
||||
|
||||
movie.id = tmdbObject.id;
|
||||
movie.summary = tmdbObject.overview;
|
||||
movie.rating = tmdbObject.vote_average;
|
||||
movie.poster_path = tmdbObject.poster_path;
|
||||
movie.background_path = tmdbObject.backdrop_path;
|
||||
movie.genre = tmdbObject.genre_ids;
|
||||
const id = tmdb.id;
|
||||
const summary = tmdb.overview;
|
||||
const poster_path = tmdb.poster_path;
|
||||
const background_path = tmdb.backdrop_path;
|
||||
const popularity = tmdb.popularity;
|
||||
const score = tmdb.vote_average;
|
||||
// const genres = translateGenre(tmdb.genres);
|
||||
const release_status = tmdb.status;
|
||||
const tagline = tmdb.tagline;
|
||||
|
||||
movie.popularity = tmdbObject.popularity;
|
||||
movie.vote_count = tmdbObject.vote_count;
|
||||
const seasons = tmdb.number_of_seasons;
|
||||
const episodes = tmdb.episodes;
|
||||
|
||||
return movie;
|
||||
}
|
||||
else if (mediaType === 'tv' || mediaType === 'show') {
|
||||
const year = new Date(tmdbObject.first_air_date).getFullYear();
|
||||
const seasoned = new TMDB(
|
||||
title, year, type, id, summary, poster_path, background_path,
|
||||
popularity, score, release_status, tagline, seasons, episodes,
|
||||
);
|
||||
|
||||
const show = new Show(tmdbObject.name, year, 'show');
|
||||
|
||||
show.id = tmdbObject.id;
|
||||
show.summary = tmdbObject.overview;
|
||||
show.rating = tmdbObject.vote_average;
|
||||
show.poster_path = tmdbObject.poster_path;
|
||||
show.background_path = tmdbObject.backdrop_path;
|
||||
show.genre = tmdbObject.genre_ids;
|
||||
|
||||
show.popularity = tmdbObject.popularity;
|
||||
show.vote_count = tmdbObject.vote_count;
|
||||
|
||||
return show;
|
||||
}
|
||||
// seasoned.print()
|
||||
return seasoned;
|
||||
}
|
||||
|
||||
module.exports = convertTmdbToSeasoned;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user