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 Plex = require('src/media_classes/plex');
const Show = require('src/media_classes/show');
function convertPlexToSeasoned(plexObject) { function translateAdded(date_string) {
return new Date(date_string * 1000);
}
const mediaType = plexObject.type; function convertPlexToSeasoned(plex) {
// There are many diff types of content, we only want to look at movies and tv shows const title = plex.title;
if (mediaType === 'movie') { const year = plex.year;
const movie = new Movie(plexObject.title, plexObject.year, mediaType); 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; const seasoned = new Plex(title, year, type, summary, poster_path, background_path, added, seasons, episodes);
movie.rating = plexObject.rating; // seasoned.print();
movie.poster = plexObject.thumb; return seasoned;
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;
}
} }
module.exports = convertPlexToSeasoned; 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) { const TMDB = require('src/media_classes/tmdb');
// 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';
// There are many diff types of content, we only want to look at movies and tv shows function translateYear(tmdbReleaseDate) {
if (mediaType === 'movie') { return new Date(tmdbReleaseDate).getFullYear();
const year = new Date(tmdbObject.release_date).getFullYear(); }
if (tmdbObject.title !== undefined) { function translateGenre(tmdbGenres) {
var title = tmdbObject.title; return tmdbGenres.map(genre => genre.name);
} else if (tmdbObject.name !== undefined) { }
var title = tmdbObject.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; const id = tmdb.id;
movie.summary = tmdbObject.overview; const summary = tmdb.overview;
movie.rating = tmdbObject.vote_average; const poster_path = tmdb.poster_path;
movie.poster_path = tmdbObject.poster_path; const background_path = tmdb.backdrop_path;
movie.background_path = tmdbObject.backdrop_path; const popularity = tmdb.popularity;
movie.genre = tmdbObject.genre_ids; const score = tmdb.vote_average;
// const genres = translateGenre(tmdb.genres);
const release_status = tmdb.status;
const tagline = tmdb.tagline;
movie.popularity = tmdbObject.popularity; const seasons = tmdb.number_of_seasons;
movie.vote_count = tmdbObject.vote_count; const episodes = tmdb.episodes;
return movie; const seasoned = new TMDB(
} title, year, type, id, summary, poster_path, background_path,
else if (mediaType === 'tv' || mediaType === 'show') { popularity, score, release_status, tagline, seasons, episodes,
const year = new Date(tmdbObject.first_air_date).getFullYear(); );
const show = new Show(tmdbObject.name, year, 'show'); // seasoned.print()
return seasoned;
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;
}
} }
module.exports = convertTmdbToSeasoned; module.exports = convertTmdbToSeasoned;