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
@@ -15,15 +15,13 @@ async function bulkImportMovies(movies) {
|
||||
const waitTime = 10000;
|
||||
|
||||
let entries = [];
|
||||
let overAllFetches = 0
|
||||
let overAllFetches = 0;
|
||||
let currenFetch = 0;
|
||||
|
||||
// ? gettings all entries from db
|
||||
const entriesFromDb = await Entry.findAll({
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' }
|
||||
]
|
||||
})
|
||||
include: [{ model: EntryId, as: "entryId" }],
|
||||
});
|
||||
|
||||
// ? creating a dict from the entries
|
||||
const entriesDict = entriesFromDb.reduce((dict, entry) => {
|
||||
@@ -32,20 +30,30 @@ async function bulkImportMovies(movies) {
|
||||
}, {});
|
||||
|
||||
for (const movie of movies) {
|
||||
|
||||
if (entriesDict[movie.tmdbId]) {
|
||||
console.log(`Entry already exists: ${entriesDict[movie.tmdbId].title} (${movie.tmdbId})`)
|
||||
console.log(
|
||||
`Entry already exists: ${entriesDict[movie.tmdbId].title} (${movie.tmdbId})`,
|
||||
);
|
||||
// ? adding date seen
|
||||
await EntrySeen.destroy({ where: { entry_id: entriesDict[movie.tmdbId].id } });
|
||||
await EntrySeen.create({ entry_id: entriesDict[movie.tmdbId].id, date_seen: movie.dateSeen, seen_with: "" });
|
||||
await EntrySeen.destroy({
|
||||
where: { entry_id: entriesDict[movie.tmdbId].id },
|
||||
});
|
||||
await EntrySeen.create({
|
||||
entry_id: entriesDict[movie.tmdbId].id,
|
||||
date_seen: movie.dateSeen,
|
||||
seen_with: "",
|
||||
});
|
||||
|
||||
// ? adding entry user rating
|
||||
if (movie.userRating != 0) {
|
||||
await EntryRating.update({ user_rating: movie.userRating }, {
|
||||
where: {
|
||||
entry_id: entriesDict[movie.tmdbId].id
|
||||
}
|
||||
});
|
||||
await EntryRating.update(
|
||||
{ user_rating: movie.userRating },
|
||||
{
|
||||
where: {
|
||||
entry_id: entriesDict[movie.tmdbId].id,
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const data = await fetchEntryData(movie.tmdbId, false);
|
||||
@@ -55,20 +63,27 @@ async function bulkImportMovies(movies) {
|
||||
const entry = await saveEntry(data);
|
||||
|
||||
// ? adding date seen
|
||||
await EntrySeen.create({ entry_id: entry.id, date_seen: movie.dateSeen, seen_with: "" });
|
||||
await EntrySeen.create({
|
||||
entry_id: entry.id,
|
||||
date_seen: movie.dateSeen,
|
||||
seen_with: "",
|
||||
});
|
||||
|
||||
// ? adding entry user rating
|
||||
if (movie.userRating != 0) {
|
||||
await EntryRating.update({ user_rating: movie.userRating }, {
|
||||
where: {
|
||||
entry_id: entry.id
|
||||
}
|
||||
});
|
||||
await EntryRating.update(
|
||||
{ user_rating: movie.userRating },
|
||||
{
|
||||
where: {
|
||||
entry_id: entry.id,
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
entries.push(entry)
|
||||
entries.push(entry);
|
||||
// ? wait 100ms between each tmdb fetch
|
||||
await new Promise(resolve => setTimeout(resolve, fetchInterval));
|
||||
await new Promise((resolve) => setTimeout(resolve, fetchInterval));
|
||||
console.log(`${currenFetch} imported id: ${movie.tmdbId}`);
|
||||
currenFetch++;
|
||||
overAllFetches++;
|
||||
@@ -76,31 +91,28 @@ async function bulkImportMovies(movies) {
|
||||
// ? stop 10 seconds after 35 tmdb fetch
|
||||
if (currenFetch == maxFetches) {
|
||||
console.log(`Now waiting ${waitTime / 1000} seconds...`);
|
||||
await new Promise(resolve => setTimeout(resolve, waitTime));
|
||||
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
||||
currentFetch = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
async function bulkImportTmdb(movies) {
|
||||
const maxFetches = 35; // ! max fetch per 10 seconds
|
||||
const fetchInterval = 500;
|
||||
const waitTime = 10000;
|
||||
|
||||
let entries = [];
|
||||
let overAllFetches = 0
|
||||
let overAllFetches = 0;
|
||||
let currentFetch = 0;
|
||||
|
||||
// ? gettings all entries from db
|
||||
const entriesFromDb = await Entry.findAll({
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' }
|
||||
]
|
||||
})
|
||||
include: [{ model: EntryId, as: "entryId" }],
|
||||
});
|
||||
|
||||
// ? creating a dict from the entries
|
||||
const entriesDict = entriesFromDb.reduce((dict, entry) => {
|
||||
@@ -112,7 +124,9 @@ async function bulkImportTmdb(movies) {
|
||||
|
||||
for (const movie of movies) {
|
||||
if (entriesDict[movie]) {
|
||||
console.log(`Entry already exists: ${entriesDict[movie].title} (${movie})`)
|
||||
console.log(
|
||||
`Entry already exists: ${entriesDict[movie].title} (${movie})`,
|
||||
);
|
||||
created.push(movie);
|
||||
} else {
|
||||
if (created.includes(movie)) continue; // * skip doubles
|
||||
@@ -122,20 +136,21 @@ async function bulkImportTmdb(movies) {
|
||||
console.log(`${currentFetch} data null for id: ${movie.id}`);
|
||||
}
|
||||
|
||||
|
||||
// ? saving the entry
|
||||
const entry = await saveEntry(data);
|
||||
entries.push(entry)
|
||||
created.push(movie)
|
||||
entries.push(entry);
|
||||
created.push(movie);
|
||||
currentFetch += data.seasons.length;
|
||||
|
||||
// TODO implement option like rating, dateseen...
|
||||
|
||||
// ? wait 100ms between each tmdb fetch
|
||||
await new Promise(resolve => setTimeout(resolve, fetchInterval));
|
||||
console.log(`${overAllFetches} (${currentFetch + 1}/${maxFetches}) imported ${entry.title}`);
|
||||
await new Promise((resolve) => setTimeout(resolve, fetchInterval));
|
||||
console.log(
|
||||
`${overAllFetches} (${currentFetch + 1}/${maxFetches}) imported ${entry.title}`,
|
||||
);
|
||||
if (data.seasons.length)
|
||||
console.log(`With ${data.seasons.length} season(s).`)
|
||||
console.log(`With ${data.seasons.length} season(s).`);
|
||||
|
||||
currentFetch++;
|
||||
overAllFetches++;
|
||||
@@ -143,42 +158,40 @@ async function bulkImportTmdb(movies) {
|
||||
// ? stop 10 seconds after 35 tmdb fetch
|
||||
if (currentFetch >= maxFetches) {
|
||||
console.log(`Now waiting ${waitTime / 1000} seconds...`);
|
||||
await new Promise(resolve => setTimeout(resolve, waitTime));
|
||||
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
||||
currentFetch = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
async function bulkImportEpisodes(episodesSeen) {
|
||||
try {
|
||||
// ! DANGER clearing old episode seen
|
||||
await EpisodeSeen.destroy({
|
||||
where: {
|
||||
entry_id: {
|
||||
[Op.ne]: 3
|
||||
}
|
||||
}
|
||||
})
|
||||
[Op.ne]: 3,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// ? gettings all entries from db
|
||||
const entriesFromDb = await Entry.findAll({
|
||||
where: {
|
||||
is_tvseries: 1
|
||||
is_tvseries: 1,
|
||||
},
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryId, as: "entryId" },
|
||||
{
|
||||
model: Season, as: 'seasons', include:
|
||||
[
|
||||
{ model: Episode, as: 'episodes' }
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
model: Season,
|
||||
as: "seasons",
|
||||
include: [{ model: Episode, as: "episodes" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// ? creating two dictionnaries names & ids
|
||||
const idsDict = entriesFromDb.reduce((dict, entry) => {
|
||||
@@ -198,14 +211,16 @@ async function bulkImportEpisodes(episodesSeen) {
|
||||
|
||||
for (let i = 0; i < episodesSeen.length; i++) {
|
||||
let theEntry;
|
||||
if (episodesSeen[i].type == 'id') {
|
||||
if (episodesSeen[i].type == "id") {
|
||||
theEntry = idsDict[episodesSeen[i].id];
|
||||
} else if (episodesSeen[i].type == 'title') {
|
||||
} else if (episodesSeen[i].type == "title") {
|
||||
theEntry = titlesDict[episodesSeen[i].title.toLowerCase()];
|
||||
}
|
||||
|
||||
if (!theEntry) {
|
||||
console.log(`No entry found for line ${i + 1} (${episodesSeen[i].id || episodesSeen[i].title})`);
|
||||
console.log(
|
||||
`No entry found for line ${i + 1} (${episodesSeen[i].id || episodesSeen[i].title})`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -221,18 +236,22 @@ async function bulkImportEpisodes(episodesSeen) {
|
||||
episodes++;
|
||||
|
||||
let date_seen = episodesSeen[i].date_seen;
|
||||
if (new Date(episodesSeen[i].date_seen) < new Date(episode.air_date)) {
|
||||
date_seen = episode.air_date.toISOString().split('T')[0];
|
||||
console.log(`Date seen changed for ${theEntry.title} S${episodesSeen[i].season}E${episodesSeen[i].episode} from ${episodesSeen[i].date_seen} to ${date_seen}`);
|
||||
if (
|
||||
new Date(episodesSeen[i].date_seen) < new Date(episode.air_date)
|
||||
) {
|
||||
date_seen = episode.air_date.toISOString().split("T")[0];
|
||||
console.log(
|
||||
`Date seen changed for ${theEntry.title} S${episodesSeen[i].season}E${episodesSeen[i].episode} from ${episodesSeen[i].date_seen} to ${date_seen}`,
|
||||
);
|
||||
}
|
||||
|
||||
let id = `${theEntry.id}${(episodesSeen[i].season + 0)}${episode.id}${date_seen.replace(/-/g, '')}`;
|
||||
let id = `${theEntry.id}${episodesSeen[i].season + 0}${episode.id}${date_seen.replace(/-/g, "")}`;
|
||||
if (!added[id]) {
|
||||
await EpisodeSeen.create({
|
||||
entry_id: theEntry.id,
|
||||
episode_id: episode.id,
|
||||
date_seen: date_seen,
|
||||
seen_with: episodesSeen[i].seen_with
|
||||
seen_with: episodesSeen[i].seen_with,
|
||||
});
|
||||
added[id] = true;
|
||||
rows++;
|
||||
@@ -243,11 +262,13 @@ async function bulkImportEpisodes(episodesSeen) {
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`rows:${rows}, seasons:${seasons}, episodes:${episodes} (out of ${episodesSeen.length})`)
|
||||
console.log(
|
||||
`rows:${rows}, seasons:${seasons}, episodes:${episodes} (out of ${episodesSeen.length})`,
|
||||
);
|
||||
console.log(added);
|
||||
return rows;
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,4 +276,4 @@ module.exports = {
|
||||
bulkImportMovies,
|
||||
bulkImportTmdb,
|
||||
bulkImportEpisodes,
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user