From 120c70622a5e2a04e8f0de292aa939df1ad06a61 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 10 Oct 2021 19:29:22 -0500 Subject: [PATCH] Fix folder browser, fix track number parsed from filename too large, add mp4 audiobook support --- client/components/modals/LibrariesModal.vue | 2 +- client/package.json | 2 +- client/pages/upload/index.vue | 4 ++-- package.json | 2 +- server/ApiController.js | 10 +++++++--- server/objects/Audiobook.js | 3 ++- server/objects/Backup.js | 1 - server/utils/audioFileScanner.js | 5 ++++- server/utils/globals.js | 2 +- server/utils/scandir.js | 7 +++++++ 10 files changed, 26 insertions(+), 12 deletions(-) diff --git a/client/components/modals/LibrariesModal.vue b/client/components/modals/LibrariesModal.vue index f55946bb..36d88bc4 100644 --- a/client/components/modals/LibrariesModal.vue +++ b/client/components/modals/LibrariesModal.vue @@ -5,7 +5,7 @@

{{ title }}

-
+

{{ libraries.length }} Libraries

diff --git a/client/package.json b/client/package.json index 981602f1..e6b52f9d 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "audiobookshelf-client", - "version": "1.4.4", + "version": "1.4.5", "description": "Audiobook manager and player", "main": "index.js", "scripts": { diff --git a/client/pages/upload/index.vue b/client/pages/upload/index.vue index 3a714030..a1061e4a 100644 --- a/client/pages/upload/index.vue +++ b/client/pages/upload/index.vue @@ -129,9 +129,9 @@ export default { title: null, author: null, series: null, - acceptedAudioFormats: ['.mp3', '.m4b', '.m4a', '.flac', '.opus'], + acceptedAudioFormats: ['.mp3', '.m4b', '.m4a', '.flac', '.opus', '.mp4'], acceptedImageFormats: ['.png', '.jpg', '.jpeg', '.webp'], - inputAccept: '.png, .jpg, .jpeg, .webp, .mp3, .m4b, .m4a, .flac, .opus', + inputAccept: '.png, .jpg, .jpeg, .webp, .mp3, .m4b, .m4a, .flac, .opus, .mp4', isDragOver: false, showUploader: true, validAudioFiles: [], diff --git a/package.json b/package.json index 25ebed41..ad56f44f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "audiobookshelf", - "version": "1.4.4", + "version": "1.4.5", "description": "Self-hosted audiobook server for managing and playing audiobooks", "main": "index.js", "scripts": { diff --git a/server/ApiController.js b/server/ApiController.js index 55df8479..1e429595 100644 --- a/server/ApiController.js +++ b/server/ApiController.js @@ -692,7 +692,7 @@ class ApiController { var path = Path.join(relpath, dirname) var isDir = (await fs.lstat(fullPath)).isDirectory() - if (isDir && !excludedDirs.includes(dirname)) { + if (isDir && !excludedDirs.includes(path) && dirname !== 'node_modules') { return { path, dirname, @@ -713,12 +713,16 @@ class ApiController { } async getFileSystemPaths(req, res) { - var excludedDirs = ['node_modules', 'client', 'server', '.git', 'static', 'build', 'dist', 'metadata', 'config', 'sys', 'proc'] + var excludedDirs = ['node_modules', 'client', 'server', '.git', 'static', 'build', 'dist', 'metadata', 'config', 'sys', 'proc'].map(dirname => { + return Path.sep + dirname + }) // Do not include existing mapped library paths in response this.db.libraries.forEach(lib => { lib.folders.forEach((folder) => { - excludedDirs.push(Path.basename(folder.fullPath)) + var dir = folder.fullPath + if (dir.includes(global.appRoot)) dir = dir.replace(global.appRoot, '') + excludedDirs.push(dir) }) }) diff --git a/server/objects/Audiobook.js b/server/objects/Audiobook.js index 8de6b15a..f7bfdecc 100644 --- a/server/objects/Audiobook.js +++ b/server/objects/Audiobook.js @@ -456,11 +456,12 @@ class Audiobook { var current_index = 1 var missingParts = [] + for (let i = 0; i < this.tracks.length; i++) { var _track = this.tracks[i] if (_track.index > current_index) { var num_parts_missing = _track.index - current_index - for (let x = 0; x < num_parts_missing; x++) { + for (let x = 0; x < num_parts_missing && x < 9999; x++) { missingParts.push(current_index + x) } } diff --git a/server/objects/Backup.js b/server/objects/Backup.js index ee1184ba..116ab1a2 100644 --- a/server/objects/Backup.js +++ b/server/objects/Backup.js @@ -67,7 +67,6 @@ class Backup { this.filename = this.id + '.audiobookshelf' this.path = Path.join('backups', this.filename) this.fullPath = Path.join(this.backupDirPath, this.filename) - console.log('Backup fullpath', this.fullPath) this.createdAt = Date.now() } diff --git a/server/utils/audioFileScanner.js b/server/utils/audioFileScanner.js index b2973b6d..ab6f25aa 100644 --- a/server/utils/audioFileScanner.js +++ b/server/utils/audioFileScanner.js @@ -12,6 +12,7 @@ function getDefaultAudioStream(audioStreams) { } async function scan(path) { + Logger.debug(`Scanning path "${path}"`) var probeData = await prober(path) if (!probeData || !probeData.audio_streams || !probeData.audio_streams.length) { return { @@ -86,7 +87,7 @@ function getTrackNumberFromFilename(title, author, series, publishYear, filename // Remove eg. "disc 1" from path partbasename = partbasename.replace(/ disc \d\d? /i, '') - var numbersinpath = partbasename.match(/\d+/g) + var numbersinpath = partbasename.match(/\d{1,4}/g) if (!numbersinpath) return null var number = numbersinpath.length ? parseInt(numbersinpath[0]) : null @@ -99,6 +100,8 @@ async function scanAudioFiles(audiobook, newAudioFiles) { return } + Logger.debug('[AudioFileScanner] Scanning audio files') + var tracks = [] var numDuplicateTracks = 0 var numInvalidTracks = 0 diff --git a/server/utils/globals.js b/server/utils/globals.js index 490cd5ea..cf92f06f 100644 --- a/server/utils/globals.js +++ b/server/utils/globals.js @@ -1,6 +1,6 @@ const globals = { SupportedImageTypes: ['png', 'jpg', 'jpeg', 'webp'], - SupportedAudioTypes: ['m4b', 'mp3', 'm4a', 'flac', 'opus'], + SupportedAudioTypes: ['m4b', 'mp3', 'm4a', 'flac', 'opus', 'mp4'], SupportedEbookTypes: ['epub', 'pdf', 'mobi'] } diff --git a/server/utils/scandir.js b/server/utils/scandir.js index 7a4f5276..a4d421dd 100644 --- a/server/utils/scandir.js +++ b/server/utils/scandir.js @@ -1,4 +1,5 @@ const Path = require('path') +const fs = require('fs-extra') const dir = require('node-dir') const Logger = require('../Logger') const { getIno } = require('./index') @@ -120,6 +121,12 @@ async function scanRootDir(folder, serverSettings = {}) { var folderPath = folder.fullPath var parseSubtitle = !!serverSettings.scannerParseSubtitle + var pathExists = await fs.pathExists(folderPath) + if (!pathExists) { + Logger.error(`[scandir] Invalid folder path does not exist "${folderPath}"`) + return [] + } + var pathdata = await getPaths(folderPath) var filepaths = pathdata.files.map(filepath => { return Path.normalize(filepath).replace(folderPath, '')