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:
2018-02-07 13:39:45 +01:00
parent 6564948af8
commit 7e874bbc9d
2 changed files with 46 additions and 88 deletions

View File

@@ -1,48 +1,24 @@
const Movie = require('src/media_classes/movie');
const Show = require('src/media_classes/show');
const Plex = require('src/media_classes/plex');
function convertPlexToSeasoned(plexObject) {
function translateAdded(date_string) {
return new Date(date_string * 1000);
}
const mediaType = plexObject.type;
// There are many diff types of content, we only want to look at movies and tv shows
if (mediaType === 'movie') {
const movie = new Movie(plexObject.title, plexObject.year, mediaType);
function convertPlexToSeasoned(plex) {
const title = plex.title;
const year = plex.year;
const type = plex.type;
const summary = plex.summary;
const poster_path = plex.thumb;
const background_path = plex.art;
const added = translateAdded(plex.addedAt);
// const genre = plex.genre;
const seasons = plex.childCount;
const episodes = plex.leafCount;
movie.summary = plexObject.summary;
movie.rating = plexObject.rating;
movie.poster = plexObject.thumb;
movie.background = plexObject.art;
movie.genre = plexObject.genre;
movie.added = new Date(plexObject.addedAt * 1000);
movie.mediaInfo = plexObject.Media;
// Don't need a for-loop when we have it in json format
file_sizes = []
for (let movie_info of plexObject.Media) {
for (let file_data of movie_info.Part) {
file_sizes.push(file_data.size)
}
}
movie.size = file_sizes;
return movie;
}
else if (mediaType === 'show') {
const show = new Show(plexObject.title, plexObject.year, mediaType);
show.summary = plexObject.summary;
show.rating = plexObject.rating;
show.poster = plexObject.thumb;
show.background = plexObject.art;
show.genre = plexObject.genre;
show.added = new Date(plexObject.addedAt * 1000);
show.seasons = plexObject.childCount;
show.episodes = plexObject.leafCount;
return show;
}
const seasoned = new Plex(title, year, type, summary, poster_path, background_path, added, seasons, episodes);
// seasoned.print();
return seasoned;
}
module.exports = convertPlexToSeasoned;

View File

@@ -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;