Skip to content

Commit

Permalink
Fix import naming stories folders + format FS : check audio
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck ALARY committed Feb 29, 2024
1 parent 7b2d5d9 commit 17fe7b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
32 changes: 22 additions & 10 deletions public/MainEvents/Processes/Import/ConvertFolderFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getStoriesPath, initTmpPath } from '../Helpers/AppPaths.js'
import { convertStoryImages } from './Helpers/ImageFile.js'
import { stringSlugify } from '../../Helpers/Strings.js'
import { findAgeInStoryName, generateDirNameStory } from '../Helpers/Stories.js'
import { convertAudios } from './Helpers/AudioFile.js'

const
varsToTransitionNode = (transitionActionNodeIndexInLI, transitionNumberOfOptions, transitionSelectedOptionIndex, actionNodeKey) => {
Expand Down Expand Up @@ -39,7 +40,7 @@ function convertFolderFS (srcPath, storyName) {
const
ri = decipherXXTEA(fs.readFileSync(path.join(srcPath, 'ri'))).toString('utf8').match(/.{12}/g),
si = decipherXXTEA(fs.readFileSync(path.join(srcPath, 'si'))).toString('utf8').match(/.{12}/g),
countFiles = ri.length * 2 + si.length + 1
countFiles = ri.length * 2 + si.length * 2 + 1

process.stdout.write('*story-reading-metadata*1*' + countFiles + '*')

Expand All @@ -60,11 +61,14 @@ function convertFolderFS (srcPath, storyName) {

renameImage = (name) => findNewName(name, '.png', imagesNewNames),
renameAudio = (name) => findNewName(name, '.mp3', audiosNewNames),
renameToTmp = (prefix, name) => prefix + '_' + name.replace('\\', '_'),
renameToTmpImage = (name) => renameToTmp('IMG', name),
renameToTmpAudio = (name) => renameToTmp('AUD', name),

tmpUuid = stringSlugify(path.basename(srcPath)),
uuid = tmpUuid.length > 36 ? tmpUuid.substring(0, 36) : tmpUuid,
{age, title} = findAgeInStoryName(storyName || path.basename(srcPath)),
dstPath = getStoriesPath(generateDirNameStory(title, uuid)),
dstPath = getStoriesPath(generateDirNameStory(title, uuid, age)),
srcImagesPath = path.join(srcPath, 'rf'),
srcAudiosPath = path.join(srcPath, 'sf'),
dstImagesPath = path.join(dstPath, 'images'),
Expand Down Expand Up @@ -159,7 +163,7 @@ function convertFolderFS (srcPath, storyName) {
fs.writeFileSync(path.join(dstPath, 'metadata.json'), JSON.stringify(metadata))

const
tmpImagesPath = initTmpPath('story'),
tmpPath = initTmpPath('story'),

toSrcPathsArray = (arr, srcPath) => {
return arr.map((v) => {
Expand All @@ -172,7 +176,8 @@ function convertFolderFS (srcPath, storyName) {
return path.join(dstPath, renameFunction(v))
})
},
tmpImagesPathsArray = toDstPathsArray(ri, tmpImagesPath, renameImage)
tmpImagesPathsArray = toDstPathsArray(ri, tmpPath, renameToTmpImage),
tmpMusicsPathsArray = toDstPathsArray(si, tmpPath, renameToTmpAudio)

decipherMedias(
toSrcPathsArray(ri, srcImagesPath),
Expand All @@ -186,14 +191,21 @@ function convertFolderFS (srcPath, storyName) {
countFiles,
(index) => decipherMedias(
toSrcPathsArray(si, srcAudiosPath),
toDstPathsArray(si, dstAudiosPath, renameAudio),
[...tmpMusicsPathsArray],
index,
countFiles,
() => {
fs.copyFileSync(path.join(dstImagesPath, firstStageNode.image), path.join(dstPath, metadata.image))
fs.copyFileSync(path.join(dstAudiosPath, firstStageNode.audio), path.join(dstPath, 'title.mp3'))
process.stdout.write('success')
}
(index) => convertAudios(
tmpMusicsPathsArray,
toDstPathsArray(si, dstAudiosPath, renameAudio),
index,
countFiles,
() => {
fs.copyFileSync(path.join(dstImagesPath, firstStageNode.image), path.join(dstPath, metadata.image))
fs.copyFileSync(path.join(dstAudiosPath, firstStageNode.audio), path.join(dstPath, 'title.mp3'))
process.stdout.write('success')
},
false
)
)
)
)
Expand Down
9 changes: 4 additions & 5 deletions public/MainEvents/Processes/Import/ConvertFolderSTUdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ function convertFolderSTUdio (srcPath, storyName) {
stageNodes = [...studioData.stageNodes],
firstStageNode = stageNodes.shift(),

{
title,
age
} = findAgeInStoryName(typeof studioData.title === 'string' ? studioData.title : (storyName || path.basename(srcPath))),
{title, age} = findAgeInStoryName(
typeof studioData.title === 'string' ? studioData.title : (storyName || path.basename(srcPath))
),

dstPath = getStoriesPath(generateDirNameStory(title, firstStageNode.uuid)),
dstPath = getStoriesPath(generateDirNameStory(title, firstStageNode.uuid, age)),
dstImagesPath = path.join(dstPath, 'images'),
dstAudiosPath = path.join(dstPath, 'audios'),

Expand Down

0 comments on commit 17fe7b2

Please sign in to comment.