Normalize to double quotes across all files with Prettier
This commit is contained in:
1 parent
73bff72cec
commit
a5659cf4c8
190 files changed
+9523
-8859
No files matched your search
@@ -1,23 +1,23 @@
|
||||
const moment = require('../../utils/moment.js');
|
||||
const moment = require("../../utils/moment.js");
|
||||
|
||||
const { fetchSeasonData, fetchEntryData } = require('../tmdbService.js');
|
||||
const { getEntryMedia, doGeneratePreview } = require('../mediaService.js');
|
||||
const { logToFile } = require('../logService.js');
|
||||
const { fetchSeasonData, fetchEntryData } = require("../tmdbService.js");
|
||||
const { getEntryMedia, doGeneratePreview } = require("../mediaService.js");
|
||||
const { logToFile } = require("../logService.js");
|
||||
|
||||
const NotFoundError = require('../../errors/NotFoundError.js');
|
||||
const InternalServerError = require('../../errors/InternalServerError.js');
|
||||
const NotFoundError = require("../../errors/NotFoundError.js");
|
||||
const InternalServerError = require("../../errors/InternalServerError.js");
|
||||
|
||||
const { ValidationError, Op } = require('sequelize');
|
||||
const Collection = require('../../models/Collection.js');
|
||||
const Entry = require('../../models/Entry.js')
|
||||
const EntryId = require('../../models/EntryId.js')
|
||||
const EntryRating = require('../../models/EntryRating.js');
|
||||
const Season = require('../../models/Season.js');
|
||||
const EntryGenre = require('../../models/EntryGenre.js');
|
||||
const EntrySeen = require('../../models/EntrySeen.js');
|
||||
const Episode = require('../../models/Episode.js');
|
||||
const Media = require('../../models/Media.js');
|
||||
const Genre = require('../../models/Genre.js');
|
||||
const { ValidationError, Op } = require("sequelize");
|
||||
const Collection = require("../../models/Collection.js");
|
||||
const Entry = require("../../models/Entry.js");
|
||||
const EntryId = require("../../models/EntryId.js");
|
||||
const EntryRating = require("../../models/EntryRating.js");
|
||||
const Season = require("../../models/Season.js");
|
||||
const EntryGenre = require("../../models/EntryGenre.js");
|
||||
const EntrySeen = require("../../models/EntrySeen.js");
|
||||
const Episode = require("../../models/Episode.js");
|
||||
const Media = require("../../models/Media.js");
|
||||
const Genre = require("../../models/Genre.js");
|
||||
|
||||
async function saveEntry(data) {
|
||||
try {
|
||||
@@ -35,7 +35,10 @@ async function saveEntry(data) {
|
||||
|
||||
tagline: data.tagline || null,
|
||||
storyline: data.overview,
|
||||
country: data.production_countries.length > 0 ? data.production_countries[0].name : null,
|
||||
country:
|
||||
data.production_countries.length > 0
|
||||
? data.production_countries[0].name
|
||||
: null,
|
||||
|
||||
is_tvseries: is_tvseries,
|
||||
watchlist: true,
|
||||
@@ -46,7 +49,7 @@ async function saveEntry(data) {
|
||||
poster_path: data.poster_path,
|
||||
banner_path: data.backdrop_path,
|
||||
|
||||
last_fetch: new Date()
|
||||
last_fetch: new Date(),
|
||||
});
|
||||
|
||||
const savedEntry = await movie.save();
|
||||
@@ -62,8 +65,8 @@ async function saveEntry(data) {
|
||||
data.genres.forEach(async (genre) => {
|
||||
await EntryGenre.create({
|
||||
genre_id: genre.id,
|
||||
entry_id: savedEntry.id
|
||||
})
|
||||
entry_id: savedEntry.id,
|
||||
});
|
||||
});
|
||||
|
||||
// ? ratings
|
||||
@@ -95,7 +98,7 @@ async function saveEntry(data) {
|
||||
|
||||
poster_path: seasonData.poster_path,
|
||||
banner_path: null,
|
||||
})
|
||||
});
|
||||
|
||||
// * episodes
|
||||
let episodes = [];
|
||||
@@ -122,43 +125,41 @@ async function saveEntry(data) {
|
||||
|
||||
// TODO fetch cast
|
||||
|
||||
savedSeason.setDataValue('episodes', episodes);
|
||||
seasons.push(savedSeason)
|
||||
savedSeason.setDataValue("episodes", episodes);
|
||||
seasons.push(savedSeason);
|
||||
}
|
||||
savedEntry.setDataValue('seasons', seasons);
|
||||
savedEntry.setDataValue("seasons", seasons);
|
||||
}
|
||||
// + end of: seasons & episodes for tv series
|
||||
|
||||
// ? cast
|
||||
|
||||
|
||||
// ? media
|
||||
const downloadedImages = await getEntryMedia(data.id, is_tvseries);
|
||||
// console.log(`entry service, downloaded images: `, downloadedImages)
|
||||
for (const image of downloadedImages) {
|
||||
await Media.create({
|
||||
mediaable: 'entry',
|
||||
mediaable: "entry",
|
||||
mediaableId: savedEntry.id,
|
||||
type: image.type,
|
||||
path: image.path,
|
||||
isLocal: true,
|
||||
isSelected: true
|
||||
isSelected: true,
|
||||
});
|
||||
|
||||
doGeneratePreview('entries', image.type + 's', image.path);
|
||||
doGeneratePreview("entries", image.type + "s", image.path);
|
||||
}
|
||||
|
||||
const currentGenresNames = await data.genres.map((genre) => genre.name);
|
||||
|
||||
const currentGenresNames = await data.genres.map(genre => genre.name);
|
||||
|
||||
savedEntry.setDataValue('entryId', ids);
|
||||
savedEntry.setDataValue('entryRating', ratings);
|
||||
savedEntry.setDataValue('genres', currentGenresNames);
|
||||
savedEntry.setDataValue("entryId", ids);
|
||||
savedEntry.setDataValue("entryRating", ratings);
|
||||
savedEntry.setDataValue("genres", currentGenresNames);
|
||||
|
||||
return savedEntry;
|
||||
} catch (error) {
|
||||
console.log(`Error saving entry (in entry serive): `, error);
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +172,10 @@ async function updateEntry(oldEntry, data) {
|
||||
|
||||
tagline: data.tagline || null,
|
||||
storyline: data.overview,
|
||||
country: data.production_countries.length > 0 ? data.production_countries[0].name : null,
|
||||
country:
|
||||
data.production_countries.length > 0
|
||||
? data.production_countries[0].name
|
||||
: null,
|
||||
|
||||
status: data.status,
|
||||
|
||||
@@ -190,11 +194,11 @@ async function updateEntry(oldEntry, data) {
|
||||
|
||||
// update ratings
|
||||
const ratings = await oldEntry.entryRating.update({
|
||||
tmdb_rating: data.vote_average
|
||||
tmdb_rating: data.vote_average,
|
||||
});
|
||||
|
||||
// update genres
|
||||
const currentGenresIds = oldEntry.genres.map(genre => genre.id);
|
||||
const currentGenresIds = oldEntry.genres.map((genre) => genre.id);
|
||||
let currentGenresNames = [];
|
||||
data.genres.forEach(async (genre) => {
|
||||
// add genres names to an array so it can be returned with the entry object
|
||||
@@ -206,12 +210,14 @@ async function updateEntry(oldEntry, data) {
|
||||
// otherwise assign the genre to the entry
|
||||
await EntryGenre.create({
|
||||
genre_id: genre.id,
|
||||
entry_id: savedEntry.id
|
||||
})
|
||||
entry_id: savedEntry.id,
|
||||
});
|
||||
});
|
||||
|
||||
// fetch entry-seens
|
||||
const entrySeens = await EntrySeen.findAll({ where: { entry_id: oldEntry.id } });
|
||||
const entrySeens = await EntrySeen.findAll({
|
||||
where: { entry_id: oldEntry.id },
|
||||
});
|
||||
|
||||
// TODO: refrech seasons
|
||||
if (oldEntry.is_tvseries) {
|
||||
@@ -224,8 +230,8 @@ async function updateEntry(oldEntry, data) {
|
||||
// Fetch existing season if it exists (using tmdb_id)
|
||||
let existingSeason = await Season.findOne({
|
||||
where: {
|
||||
tmdb_id: season.id
|
||||
}
|
||||
tmdb_id: season.id,
|
||||
},
|
||||
});
|
||||
|
||||
// If the season exists, update it; otherwise, create a new season
|
||||
@@ -269,7 +275,7 @@ async function updateEntry(oldEntry, data) {
|
||||
let existingEpisode = await Episode.findOne({
|
||||
where: {
|
||||
tmdb_id: episode.id,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// If the episode exists, update it; otherwise, create a new episode
|
||||
@@ -309,19 +315,18 @@ async function updateEntry(oldEntry, data) {
|
||||
}
|
||||
|
||||
// Update the episodes of the current season
|
||||
existingSeason.setDataValue('episodes', updatedEpisodes);
|
||||
existingSeason.setDataValue("episodes", updatedEpisodes);
|
||||
updatedSeasons.push(existingSeason);
|
||||
}
|
||||
|
||||
// Update the seasons of the movie
|
||||
savedEntry.setDataValue('seasons', updatedSeasons);
|
||||
savedEntry.setDataValue("seasons", updatedSeasons);
|
||||
}
|
||||
|
||||
|
||||
savedEntry.setDataValue('entryId', ids);
|
||||
savedEntry.setDataValue('entryRating', ratings);
|
||||
savedEntry.setDataValue('genres', currentGenresNames);
|
||||
savedEntry.setDataValue('entrySeen', entrySeens);
|
||||
savedEntry.setDataValue("entryId", ids);
|
||||
savedEntry.setDataValue("entryRating", ratings);
|
||||
savedEntry.setDataValue("genres", currentGenresNames);
|
||||
savedEntry.setDataValue("entrySeen", entrySeens);
|
||||
|
||||
return savedEntry;
|
||||
}
|
||||
@@ -332,25 +337,24 @@ async function refrechEntry(entryId) {
|
||||
// ! note: the includes are required for the update
|
||||
const oldEntry = await Entry.findByPk(entryId, {
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
{ model: EntrySeen, as: 'entrySeen' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{ model: EntryId, as: "entryId" },
|
||||
{ model: EntryRating, as: "entryRating" },
|
||||
{ model: EntrySeen, as: "entrySeen" },
|
||||
{ model: Season, as: "seasons" },
|
||||
{ model: Media, as: "medias" },
|
||||
{
|
||||
model: Collection, as: 'collections',
|
||||
include: [
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
model: Collection,
|
||||
as: "collections",
|
||||
include: [{ model: Media, as: "medias" }],
|
||||
},
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
}
|
||||
as: "genres",
|
||||
},
|
||||
],
|
||||
order: [
|
||||
[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list
|
||||
]
|
||||
[{ model: EntrySeen, as: "entrySeen" }, "date_seen", "DESC"], // Order the entry-seen list
|
||||
],
|
||||
});
|
||||
|
||||
if (!oldEntry) {
|
||||
@@ -358,7 +362,10 @@ async function refrechEntry(entryId) {
|
||||
}
|
||||
|
||||
// ? getting new data from TMDB
|
||||
const entryData = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries);
|
||||
const entryData = await fetchEntryData(
|
||||
oldEntry.entryId.tmdb_id,
|
||||
oldEntry.is_tvseries,
|
||||
);
|
||||
if (entryData == null) {
|
||||
throw new InternalServerError(`Counldn't fetch data from TMDB`);
|
||||
}
|
||||
@@ -373,14 +380,17 @@ async function refrechEntry(entryId) {
|
||||
|
||||
tagline: entryData.tagline || null,
|
||||
storyline: entryData.overview,
|
||||
country: entryData.production_countries.length > 0 ? entryData.production_countries[0].name : null,
|
||||
country:
|
||||
entryData.production_countries.length > 0
|
||||
? entryData.production_countries[0].name
|
||||
: null,
|
||||
|
||||
status: entryData.status,
|
||||
|
||||
poster_path: entryData.poster_path,
|
||||
banner_path: entryData.backdrop_path,
|
||||
|
||||
last_fetch: new Date()
|
||||
last_fetch: new Date(),
|
||||
};
|
||||
|
||||
const savedEntry = await oldEntry.update(newData);
|
||||
@@ -393,11 +403,11 @@ async function refrechEntry(entryId) {
|
||||
|
||||
// * updating ratings
|
||||
await oldEntry.entryRating.update({
|
||||
tmdb_rating: entryData.vote_average
|
||||
tmdb_rating: entryData.vote_average,
|
||||
});
|
||||
|
||||
// * updating genres
|
||||
const currentGenresIds = oldEntry.genres.map(genre => genre.id);
|
||||
const currentGenresIds = oldEntry.genres.map((genre) => genre.id);
|
||||
entryData.genres.forEach(async (genre) => {
|
||||
// if the entry already has this genre then skip
|
||||
if (currentGenresIds.includes(genre.id)) return;
|
||||
@@ -405,26 +415,28 @@ async function refrechEntry(entryId) {
|
||||
// otherwise assign the genre to the entry
|
||||
await EntryGenre.create({
|
||||
genre_id: genre.id,
|
||||
entry_id: savedEntry.id
|
||||
})
|
||||
entry_id: savedEntry.id,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// * For TV-Series (Seasons & Episodes)
|
||||
if (oldEntry.is_tvseries) {
|
||||
// ? Only refrech if the series's status is not 'Ended'
|
||||
// ? and atleast 48 hours has passed
|
||||
// ? and atleast 48 hours has passed
|
||||
|
||||
// * Update or insert seasons for the entry
|
||||
for (const season of entryData.seasons) {
|
||||
// fetch new season data from tmdb
|
||||
let seasonData = await fetchSeasonData(entryData.id, season.season_number);
|
||||
let seasonData = await fetchSeasonData(
|
||||
entryData.id,
|
||||
season.season_number,
|
||||
);
|
||||
|
||||
// Fetch existing season if it exists (using tmdb_id)
|
||||
let existingSeason = await Season.findOne({
|
||||
where: {
|
||||
tmdb_id: season.id
|
||||
}
|
||||
tmdb_id: season.id,
|
||||
},
|
||||
});
|
||||
|
||||
// If the season exists, update it; otherwise, create a new season
|
||||
@@ -464,7 +476,7 @@ async function refrechEntry(entryId) {
|
||||
let existingEpisode = await Episode.findOne({
|
||||
where: {
|
||||
tmdb_id: episode.id,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// If the episode exists, update it; otherwise, create a new episode
|
||||
@@ -512,12 +524,12 @@ async function refrechEntry(entryId) {
|
||||
|
||||
// ? count media by type
|
||||
let availableMedia = {
|
||||
'posters': 0,
|
||||
'logos': 0,
|
||||
'backdrops': 0
|
||||
posters: 0,
|
||||
logos: 0,
|
||||
backdrops: 0,
|
||||
};
|
||||
for (let i = 0; i < oldEntry.medias.length; i++) {
|
||||
availableMedia[oldEntry.medias[i].type + 's'] += 1;
|
||||
availableMedia[oldEntry.medias[i].type + "s"] += 1;
|
||||
}
|
||||
|
||||
// ? if the count of a media type == 0, the add the type to mediaToGet
|
||||
@@ -528,26 +540,32 @@ async function refrechEntry(entryId) {
|
||||
|
||||
let downloadedImages;
|
||||
if (mediaToGet.length != 0) {
|
||||
downloadedImages = await getEntryMedia(entryData.id, oldEntry.is_tvseries, mediaToGet);
|
||||
downloadedImages = await getEntryMedia(
|
||||
entryData.id,
|
||||
oldEntry.is_tvseries,
|
||||
mediaToGet,
|
||||
);
|
||||
}
|
||||
|
||||
if (downloadedImages) {
|
||||
for (const image of downloadedImages) {
|
||||
await Media.create({
|
||||
mediaable: 'entry',
|
||||
mediaable: "entry",
|
||||
mediaableId: oldEntry.id,
|
||||
type: image.type,
|
||||
path: image.path,
|
||||
isLocal: true,
|
||||
isSelected: true
|
||||
isSelected: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ? fetch collection
|
||||
if (entryData.belongs_to_collection) {
|
||||
const collectionService = require('../collectionService.js');
|
||||
await collectionService.createOrUpdateCollection(entryData.belongs_to_collection.id);
|
||||
const collectionService = require("../collectionService.js");
|
||||
await collectionService.createOrUpdateCollection(
|
||||
entryData.belongs_to_collection.id,
|
||||
);
|
||||
}
|
||||
|
||||
// + end of: refrech logic
|
||||
@@ -573,53 +591,49 @@ async function refrechEntry(entryId) {
|
||||
|
||||
const updatedEntry = await Entry.findByPk(entryId, {
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
{ model: EntrySeen, as: 'entrySeen' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{ model: EntryId, as: "entryId" },
|
||||
{ model: EntryRating, as: "entryRating" },
|
||||
{ model: EntrySeen, as: "entrySeen" },
|
||||
{ model: Season, as: "seasons" },
|
||||
{ model: Media, as: "medias" },
|
||||
{
|
||||
model: Collection, as: 'collections',
|
||||
include: [
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
model: Collection,
|
||||
as: "collections",
|
||||
include: [{ model: Media, as: "medias" }],
|
||||
},
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
attributes: ['name'], // Only fetch the genre ID
|
||||
as: "genres",
|
||||
attributes: ["name"], // Only fetch the genre ID
|
||||
through: {
|
||||
attributes: [] // Do not fetch any attributes from the join table
|
||||
}
|
||||
}
|
||||
attributes: [], // Do not fetch any attributes from the join table
|
||||
},
|
||||
},
|
||||
],
|
||||
order: [
|
||||
[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list
|
||||
]
|
||||
[{ model: EntrySeen, as: "entrySeen" }, "date_seen", "DESC"], // Order the entry-seen list
|
||||
],
|
||||
});
|
||||
|
||||
const plainEntry = updatedEntry.get({ plain: true });
|
||||
plainEntry.genres = plainEntry.genres.map(genre => genre.name);
|
||||
plainEntry.genres = plainEntry.genres.map((genre) => genre.name);
|
||||
|
||||
return plainEntry;
|
||||
}
|
||||
|
||||
/** This function will refresh data of series that have the status not 'ended/canceled' and have not been refreshed today
|
||||
*/
|
||||
*/
|
||||
async function SyncSeriesData() {
|
||||
const today = moment().format('YYYY-MM-DD');
|
||||
const today = moment().format("YYYY-MM-DD");
|
||||
const entries = await Entry.findAll({
|
||||
where: {
|
||||
is_tvseries: true,
|
||||
autoSync: true,
|
||||
last_fetch: {
|
||||
[Op.ne]: today
|
||||
[Op.ne]: today,
|
||||
},
|
||||
status: {
|
||||
[Op.notIn]: [
|
||||
'Ended',
|
||||
'Canceled'
|
||||
]
|
||||
[Op.notIn]: ["Ended", "Canceled"],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -627,7 +641,7 @@ async function SyncSeriesData() {
|
||||
logToFile(`Started syncing ${entries.length} Tv-Series`);
|
||||
|
||||
const results = await Promise.all(
|
||||
entries.map(entry => SyncSerieData(entry.id))
|
||||
entries.map((entry) => SyncSerieData(entry.id)),
|
||||
);
|
||||
logToFile(`Syncing Tv-Series Finished`);
|
||||
|
||||
@@ -637,30 +651,31 @@ async function SyncSeriesData() {
|
||||
async function SyncSerieData(entryId) {
|
||||
const oldEntry = await Entry.findByPk(entryId, {
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
{ model: EntrySeen, as: 'entrySeen' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{ model: EntryId, as: "entryId" },
|
||||
{ model: EntryRating, as: "entryRating" },
|
||||
{ model: EntrySeen, as: "entrySeen" },
|
||||
{ model: Season, as: "seasons" },
|
||||
{ model: Media, as: "medias" },
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
attributes: ['id'],
|
||||
as: "genres",
|
||||
attributes: ["id"],
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
}
|
||||
]
|
||||
attributes: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
logToFile(`Sync Started For: ${oldEntry.entryId.tmdb_id}/${oldEntry.title}`)
|
||||
logToFile(`Sync Started For: ${oldEntry.entryId.tmdb_id}/${oldEntry.title}`);
|
||||
|
||||
if (!oldEntry)
|
||||
throw NotFoundError('Entry Not Found');
|
||||
const entryData = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries);
|
||||
if (!oldEntry) throw NotFoundError("Entry Not Found");
|
||||
const entryData = await fetchEntryData(
|
||||
oldEntry.entryId.tmdb_id,
|
||||
oldEntry.is_tvseries,
|
||||
);
|
||||
|
||||
if (!entryData)
|
||||
throw new ValidationError(`Couldn't Fetch Entry Data`);
|
||||
if (!entryData) throw new ValidationError(`Couldn't Fetch Entry Data`);
|
||||
|
||||
// ! 1 - Normal Data
|
||||
let newData = {
|
||||
@@ -671,14 +686,17 @@ async function SyncSerieData(entryId) {
|
||||
|
||||
tagline: entryData.tagline || null,
|
||||
storyline: entryData.overview,
|
||||
country: entryData.production_countries.length > 0 ? entryData.production_countries[0].name : null,
|
||||
country:
|
||||
entryData.production_countries.length > 0
|
||||
? entryData.production_countries[0].name
|
||||
: null,
|
||||
|
||||
status: entryData.status,
|
||||
|
||||
poster_path: entryData.poster_path,
|
||||
banner_path: entryData.backdrop_path,
|
||||
|
||||
last_fetch: new Date()
|
||||
last_fetch: new Date(),
|
||||
};
|
||||
|
||||
await oldEntry.update(newData);
|
||||
@@ -691,30 +709,39 @@ async function SyncSerieData(entryId) {
|
||||
|
||||
// ! 3 - Ratings
|
||||
await oldEntry.entryRating.update({
|
||||
tmdb_rating: entryData.vote_average
|
||||
tmdb_rating: entryData.vote_average,
|
||||
});
|
||||
|
||||
// ! 4 - Genres
|
||||
const currentGenresIds = oldEntry.genres.map(genre => genre.id);
|
||||
const currentGenresIds = oldEntry.genres.map((genre) => genre.id);
|
||||
entryData.genres.forEach(async (genre) => {
|
||||
// ? only assing the genre if its not already asigned
|
||||
if (!currentGenresIds.includes(genre.id)) {
|
||||
await EntryGenre.create({
|
||||
genre_id: genre.id,
|
||||
entry_id: oldEntry.id
|
||||
})
|
||||
entry_id: oldEntry.id,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// ! 5 - Seasons
|
||||
// ? only update the last seasons available + season 0 (specials)
|
||||
if (oldEntry.is_tvseries) {
|
||||
const latestAvailableSeason = await Math.max(...oldEntry.seasons.map(s => s.season_number));
|
||||
const latestAvailableSeason = await Math.max(
|
||||
...oldEntry.seasons.map((s) => s.season_number),
|
||||
);
|
||||
for (const season of entryData.seasons) {
|
||||
if (season.season_number != 0 && season.season_number != latestAvailableSeason) continue;
|
||||
if (
|
||||
season.season_number != 0 &&
|
||||
season.season_number != latestAvailableSeason
|
||||
)
|
||||
continue;
|
||||
|
||||
// ? fetch new season data from tmdb
|
||||
let seasonData = await fetchSeasonData(oldEntry.entryId.tmdb_id, season.season_number);
|
||||
let seasonData = await fetchSeasonData(
|
||||
oldEntry.entryId.tmdb_id,
|
||||
season.season_number,
|
||||
);
|
||||
|
||||
// * find or create the season
|
||||
const [oldSeason, createdSeason] = await Season.findOrCreate({
|
||||
@@ -731,7 +758,7 @@ async function SyncSerieData(entryId) {
|
||||
tmdb_rating: seasonData.vote_average,
|
||||
poster_path: seasonData.poster_path,
|
||||
banner_path: null,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// ? if the season already exist then just update it with new data
|
||||
@@ -769,7 +796,7 @@ async function SyncSerieData(entryId) {
|
||||
air_date: episode.air_date,
|
||||
tmdb_rating: episode.vote_average,
|
||||
still_path: episode.still_path,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// ? if the episode already exist then just update it with new data
|
||||
@@ -802,4 +829,4 @@ module.exports = {
|
||||
refrechEntry,
|
||||
SyncSeriesData,
|
||||
SyncSerieData,
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user