Refactored clips into chapters.

This commit is contained in:
DebaucheryLibrarian
2021-02-27 00:37:22 +01:00
parent 0eba0461c9
commit bb20659934
115 changed files with 671 additions and 194 deletions

View File

@@ -249,44 +249,47 @@ async function updateReleasesSearch(releaseIds) {
}
}
async function storeClips(releases) {
const clips = releases.map(release => release.clips?.map((clip, index) => ({
title: clip.title,
description: clip.description,
async function storeChapters(releases) {
const chapters = releases.map(release => release.chapters?.map((chapter, index) => ({
releaseId: release.id,
clip: index + 1,
duration: clip.duration,
poster: clip.poster,
photos: clip.photos,
tags: clip.tags,
index: index + 1,
time: chapter.time,
duration: chapter.duration,
title: chapter.title,
description: chapter.description,
poster: chapter.poster,
photos: chapter.photos,
tags: chapter.tags,
}))).flat().filter(Boolean);
const curatedClipEntries = clips.map(clip => ({
title: clip.title,
description: clip.description,
duration: clip.duration,
release_id: clip.releaseId,
clip: clip.clip,
const curatedChapterEntries = chapters.map(chapter => ({
index: chapter.index,
time: chapter.time,
duration: chapter.duration,
title: chapter.title,
description: chapter.description,
release_id: chapter.releaseId,
}));
const storedClips = await bulkInsert('clips', curatedClipEntries, ['release_id', 'clip']);
const clipIdsByReleaseIdAndClip = storedClips.reduce((acc, clip) => ({
const storedChapters = await bulkInsert('chapters', curatedChapterEntries, ['release_id', 'index']);
const chapterIdsByReleaseIdAndChapter = storedChapters.reduce((acc, chapter) => ({
...acc,
[clip.release_id]: {
...acc[clip.release_id],
[clip.clip]: clip.id,
[chapter.release_id]: {
...acc[chapter.release_id],
[chapter.index]: chapter.id,
},
}), {});
const clipsWithId = clips.map(clip => ({
...clip,
id: clipIdsByReleaseIdAndClip[clip.releaseId][clip.clip],
const chaptersWithId = chapters.map(chapter => ({
...chapter,
id: chapterIdsByReleaseIdAndChapter[chapter.releaseId][chapter.index],
}));
await associateReleaseTags(clipsWithId, 'clip');
await associateReleaseTags(chaptersWithId, 'chapter');
// media is more error-prone, associate separately
await associateReleaseMedia(clipsWithId, 'clip');
await associateReleaseMedia(chaptersWithId, 'chapter');
}
async function storeScenes(releases) {
@@ -313,7 +316,7 @@ async function storeScenes(releases) {
const [actors] = await Promise.all([
associateActors(releasesWithId, batchId),
associateReleaseTags(releasesWithId),
storeClips(releasesWithId),
storeChapters(releasesWithId),
]);
await updateReleasesSearch(releasesWithId.map(release => release.id));