diff --git a/client/pages/audiobook/_id/edit.vue b/client/pages/audiobook/_id/edit.vue index 976262f2..7e078bce 100644 --- a/client/pages/audiobook/_id/edit.vue +++ b/client/pages/audiobook/_id/edit.vue @@ -56,6 +56,28 @@ + +
+ Check Track Numbers +
+ + + + + + + + + + + + + + + +
FilenameIndex# From Metadata# From Filename# From Probe
{{ trackData.filename }}{{ trackData.currentTrackNum }}{{ trackData.trackNumFromMeta }}{{ trackData.trackNumFromFilename }}{{ trackData.scanDataTrackNum }}
+
+
@@ -95,7 +117,9 @@ export default { group: 'description', ghostClass: 'ghost' }, - saving: false + saving: false, + checkingTrackNumbers: false, + trackNumData: [] } }, computed: { @@ -172,9 +196,26 @@ export default { }, streamAudiobook() { return this.$store.state.streamAudiobook + }, + showExperimentalFeatures() { + return this.$store.state.showExperimentalFeatures } }, methods: { + checkTrackNumbers() { + this.checkingTrackNumbers = true + this.$axios + .$get(`/api/scantracks/${this.audiobookId}`) + .then((res) => { + console.log('RES', res) + this.trackNumData = res + this.checkingTrackNumbers = false + }) + .catch((error) => { + console.error('Failed', error) + this.checkingTrackNumbers = false + }) + }, includeToggled(audio) { var new_index = 0 if (audio.include) { diff --git a/server/ApiController.js b/server/ApiController.js index c87575da..367f8570 100644 --- a/server/ApiController.js +++ b/server/ApiController.js @@ -1,10 +1,13 @@ const express = require('express') const Path = require('path') const fs = require('fs-extra') + const Logger = require('./Logger') -const User = require('./objects/User') const { isObject } = require('./utils/index') +const audioFileScanner = require('./utils/audioFileScanner') + const Library = require('./objects/Library') +const User = require('./objects/User') class ApiController { constructor(MetadataPath, db, scanner, auth, streamManager, rssFeeds, downloadManager, coverController, backupManager, watcher, emitter, clientEmitter) { @@ -77,6 +80,8 @@ class ApiController { this.router.get('/download/:id', this.download.bind(this)) this.router.get('/filesystem', this.getFileSystemPaths.bind(this)) + + this.router.get('/scantracks/:id', this.scanAudioTrackNums.bind(this)) } find(req, res) { @@ -783,5 +788,18 @@ class ApiController { var dirs = await this.getDirectories(global.appRoot, '/', excludedDirs) res.json(dirs) } + + async scanAudioTrackNums(req, res) { + if (!req.user || !req.user.isRoot) { + return res.sendStatus(403) + } + var audiobook = this.db.audiobooks.find(ab => ab.id === req.params.id) + if (!audiobook) { + return res.status(404).send('Audiobook not found') + } + + var scandata = await audioFileScanner.scanTrackNumbers(audiobook) + res.json(scandata) + } } module.exports = ApiController \ No newline at end of file diff --git a/server/Db.js b/server/Db.js index 20558c72..4f324ee0 100644 --- a/server/Db.js +++ b/server/Db.js @@ -82,10 +82,14 @@ class Db { await this.load() // Insert Defaults - if (!this.users.find(u => u.type === 'root')) { + var rootUser = this.users.find(u => u.type === 'root') + if (!rootUser) { var token = await jwt.sign({ userId: 'root' }, process.env.TOKEN_SECRET) Logger.debug('Generated default token', token) + Logger.info('[Db] Root user created') await this.insertEntity('user', this.getDefaultUser(token)) + } else { + Logger.info(`[Db] Root user exists, pw: ${rootUser.hasPw}`) } if (!this.libraries.length) { @@ -123,19 +127,6 @@ class Db { await Promise.all([p1, p2, p3, p4]) } - // insertAudiobook(audiobook) { - // return this.insertAudiobooks([audiobook]) - // } - - // insertAudiobooks(audiobooks) { - // return this.audiobooksDb.insert(audiobooks).then((results) => { - // Logger.debug(`[DB] Inserted ${results.inserted} audiobooks`) - // this.audiobooks = this.audiobooks.concat(audiobooks) - // }).catch((error) => { - // Logger.error(`[DB] Insert audiobooks Failed ${error}`) - // }) - // } - updateAudiobook(audiobook) { return this.audiobooksDb.update((record) => record.id === audiobook.id, () => audiobook).then((results) => { Logger.debug(`[DB] Audiobook updated ${results.updated}`) @@ -146,26 +137,6 @@ class Db { }) } - // insertUser(user) { - // return this.usersDb.insert([user]).then((results) => { - // Logger.debug(`[DB] Inserted user ${results.inserted}`) - // this.users.push(user) - // return true - // }).catch((error) => { - // Logger.error(`[DB] Insert user Failed ${error}`) - // return false - // }) - // } - - // insertSettings(settings) { - // return this.settingsDb.insert([settings]).then((results) => { - // Logger.debug(`[DB] Inserted ${results.inserted} settings`) - // this.settings = this.settings.concat(settings) - // }).catch((error) => { - // Logger.error(`[DB] Insert settings Failed ${error}`) - // }) - // } - updateUserStream(userId, streamId) { return this.usersDb.update((record) => record.id === userId, (user) => { user.stream = streamId diff --git a/server/objects/User.js b/server/objects/User.js index 0a5044cd..23e2b9d3 100644 --- a/server/objects/User.js +++ b/server/objects/User.js @@ -37,6 +37,9 @@ class User { get canUpload() { return !!this.permissions.upload && this.isActive } + get hasPw() { + return !!this.pash && !!this.pash.length + } getDefaultUserSettings() { return { diff --git a/server/utils/audioFileScanner.js b/server/utils/audioFileScanner.js index ab6f25aa..ed35481e 100644 --- a/server/utils/audioFileScanner.js +++ b/server/utils/audioFileScanner.js @@ -111,7 +111,6 @@ async function scanAudioFiles(audiobook, newAudioFiles) { var scanData = await scan(audioFile.fullPath) if (!scanData || scanData.error) { Logger.error('[AudioFileScanner] Scan failed for', audioFile.path) - // audiobook.invalidAudioFiles.push(parts[i]) continue; } @@ -233,4 +232,27 @@ async function rescanAudioFiles(audiobook) { return updates } -module.exports.rescanAudioFiles = rescanAudioFiles \ No newline at end of file +module.exports.rescanAudioFiles = rescanAudioFiles + +async function scanTrackNumbers(audiobook) { + var tracks = audiobook.tracks || [] + var scannedTrackNumData = [] + for (let i = 0; i < tracks.length; i++) { + var track = tracks[i] + var scanData = await scan(track.fullPath) + + var trackNumFromMeta = getTrackNumberFromMeta(scanData) + var book = audiobook.book || {} + var trackNumFromFilename = getTrackNumberFromFilename(book.title, book.author, book.series, book.publishYear, track.filename) + Logger.info(`[AudioFileScanner] Track # for "${track.filename}", Metadata: "${trackNumFromMeta}", Filename: "${trackNumFromFilename}", Current: "${track.index}"`) + scannedTrackNumData.push({ + filename: track.filename, + currentTrackNum: track.index, + trackNumFromFilename, + trackNumFromMeta, + scanDataTrackNum: scanData.file_tag_track + }) + } + return scannedTrackNumData +} +module.exports.scanTrackNumbers = scanTrackNumbers \ No newline at end of file