mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
This commit is contained in:
parent
03963aa9a1
commit
b9dee8704f
@ -56,6 +56,28 @@
|
||||
</li>
|
||||
</transition-group>
|
||||
</draggable>
|
||||
|
||||
<div v-if="showExperimentalFeatures" class="p-4">
|
||||
<ui-btn :loading="checkingTrackNumbers" small @click="checkTrackNumbers">Check Track Numbers</ui-btn>
|
||||
<div v-if="trackNumData && trackNumData.length" class="w-full max-w-4xl py-2">
|
||||
<table class="tracksTable">
|
||||
<tr>
|
||||
<th class="text-left">Filename</th>
|
||||
<th class="w-32">Index</th>
|
||||
<th class="w-32"># From Metadata</th>
|
||||
<th class="w-32"># From Filename</th>
|
||||
<th class="w-32"># From Probe</th>
|
||||
</tr>
|
||||
<tr v-for="trackData in trackNumData" :key="trackData.filename">
|
||||
<td class="text-xs">{{ trackData.filename }}</td>
|
||||
<td class="text-center">{{ trackData.currentTrackNum }}</td>
|
||||
<td class="text-center">{{ trackData.trackNumFromMeta }}</td>
|
||||
<td class="text-center">{{ trackData.trackNumFromFilename }}</td>
|
||||
<td class="text-center">{{ trackData.scanDataTrackNum }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@ -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) {
|
||||
|
@ -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
|
39
server/Db.js
39
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
|
||||
|
@ -37,6 +37,9 @@ class User {
|
||||
get canUpload() {
|
||||
return !!this.permissions.upload && this.isActive
|
||||
}
|
||||
get hasPw() {
|
||||
return !!this.pash && !!this.pash.length
|
||||
}
|
||||
|
||||
getDefaultUserSettings() {
|
||||
return {
|
||||
|
@ -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
|
||||
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
|
Loading…
Reference in New Issue
Block a user