mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-28 01:29:27 +01:00
Update:Uploader to treat audio files as separate audiobooks if uploading only audio files #670
This commit is contained in:
parent
5452a57a14
commit
0c8fd6ab0e
@ -28,11 +28,11 @@ export default {
|
|||||||
var validOtherFiles = []
|
var validOtherFiles = []
|
||||||
var ignoredFiles = []
|
var ignoredFiles = []
|
||||||
files.forEach((file) => {
|
files.forEach((file) => {
|
||||||
var filetype = this.checkFileType(file.name)
|
// var filetype = this.checkFileType(file.name)
|
||||||
if (!filetype) ignoredFiles.push(file)
|
if (!file.filetype) ignoredFiles.push(file)
|
||||||
else {
|
else {
|
||||||
file.filetype = filetype
|
// file.filetype = filetype
|
||||||
if (filetype === 'audio' || (filetype === 'ebook' && mediaType === 'book')) validItemFiles.push(file)
|
if (file.filetype === 'audio' || (file.filetype === 'ebook' && mediaType === 'book')) validItemFiles.push(file)
|
||||||
else validOtherFiles.push(file)
|
else validOtherFiles.push(file)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -82,12 +82,18 @@ export default {
|
|||||||
items: itemResults,
|
items: itemResults,
|
||||||
ignoredFiles: ignoredFilesInRoot
|
ignoredFiles: ignoredFilesInRoot
|
||||||
}
|
}
|
||||||
} else {
|
} else if (filetree.some((f) => f.filetype !== 'audio') || mediaType !== 'book') {
|
||||||
// Single Book drop
|
// Single Book drop
|
||||||
return {
|
return {
|
||||||
items: this.itemFromTreeItems(filetree, mediaType),
|
items: this.itemFromTreeItems(filetree, mediaType),
|
||||||
ignoredFiles: []
|
ignoredFiles: []
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Only audio files dropped so treat each one as an audiobook
|
||||||
|
return {
|
||||||
|
items: filetree.map((audioFile) => ({ itemFiles: [audioFile], otherFiles: [], ignoredFiles: [] })),
|
||||||
|
ignoredFiles: []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getFilesDropped(dataTransferItems) {
|
getFilesDropped(dataTransferItems) {
|
||||||
@ -95,11 +101,12 @@ export default {
|
|||||||
path: '/',
|
path: '/',
|
||||||
items: []
|
items: []
|
||||||
}
|
}
|
||||||
function traverseFileTreePromise(item, currtreemap) {
|
function traverseFileTreePromise(item, currtreemap, checkFileType) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (item.isFile) {
|
if (item.isFile) {
|
||||||
item.file((file) => {
|
item.file((file) => {
|
||||||
file.filepath = currtreemap.path + file.name //save full path
|
file.filepath = currtreemap.path + file.name //save full path
|
||||||
|
file.filetype = checkFileType(file.name)
|
||||||
currtreemap.items.push(file)
|
currtreemap.items.push(file)
|
||||||
resolve(file)
|
resolve(file)
|
||||||
})
|
})
|
||||||
@ -119,7 +126,7 @@ export default {
|
|||||||
dirReader.readEntries((entries) => {
|
dirReader.readEntries((entries) => {
|
||||||
if (entries.length > 0) {
|
if (entries.length > 0) {
|
||||||
for (let entr of entries) {
|
for (let entr of entries) {
|
||||||
entriesPromises.push(traverseFileTreePromise(entr, newtreemap))
|
entriesPromises.push(traverseFileTreePromise(entr, newtreemap, checkFileType))
|
||||||
}
|
}
|
||||||
readEntries()
|
readEntries()
|
||||||
} else {
|
} else {
|
||||||
@ -135,7 +142,7 @@ export default {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let entriesPromises = []
|
let entriesPromises = []
|
||||||
for (let it of dataTransferItems) {
|
for (let it of dataTransferItems) {
|
||||||
var filetree = traverseFileTreePromise(it.webkitGetAsEntry(), treemap)
|
var filetree = traverseFileTreePromise(it.webkitGetAsEntry(), treemap, this.checkFileType)
|
||||||
entriesPromises.push(filetree)
|
entriesPromises.push(filetree)
|
||||||
}
|
}
|
||||||
Promise.all(entriesPromises).then(() => {
|
Promise.all(entriesPromises).then(() => {
|
||||||
@ -152,7 +159,9 @@ export default {
|
|||||||
...book
|
...book
|
||||||
}
|
}
|
||||||
var firstBookFile = book.itemFiles[0]
|
var firstBookFile = book.itemFiles[0]
|
||||||
if (!firstBookFile.filepath) return audiobook // No path
|
if (!firstBookFile.filepath) {
|
||||||
|
return audiobook // No path
|
||||||
|
}
|
||||||
|
|
||||||
var firstBookPath = Path.dirname(firstBookFile.filepath)
|
var firstBookPath = Path.dirname(firstBookFile.filepath)
|
||||||
|
|
||||||
@ -165,6 +174,9 @@ export default {
|
|||||||
if (dirs.length) {
|
if (dirs.length) {
|
||||||
audiobook.author = dirs.pop()
|
audiobook.author = dirs.pop()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Use file basename as title
|
||||||
|
audiobook.title = Path.basename(firstBookFile.name, Path.extname(firstBookFile.name))
|
||||||
}
|
}
|
||||||
return audiobook
|
return audiobook
|
||||||
},
|
},
|
||||||
@ -178,7 +190,12 @@ export default {
|
|||||||
if (!firstAudioFile.filepath) return podcast // No path
|
if (!firstAudioFile.filepath) return podcast // No path
|
||||||
var firstPath = Path.dirname(firstAudioFile.filepath)
|
var firstPath = Path.dirname(firstAudioFile.filepath)
|
||||||
var dirs = firstPath.split('/').filter(d => !!d && d !== '.')
|
var dirs = firstPath.split('/').filter(d => !!d && d !== '.')
|
||||||
podcast.title = dirs.length > 1 ? dirs[1] : dirs[0]
|
if (dirs.length) {
|
||||||
|
podcast.title = dirs.length > 1 ? dirs[1] : dirs[0]
|
||||||
|
} else {
|
||||||
|
podcast.title = Path.basename(firstAudioFile.name, Path.extname(firstAudioFile.name))
|
||||||
|
}
|
||||||
|
|
||||||
return podcast
|
return podcast
|
||||||
},
|
},
|
||||||
cleanItem(item, mediaType, index) {
|
cleanItem(item, mediaType, index) {
|
||||||
@ -188,6 +205,7 @@ export default {
|
|||||||
async getItemsFromDataTransferItems(dataTransferItems, mediaType) {
|
async getItemsFromDataTransferItems(dataTransferItems, mediaType) {
|
||||||
var files = await this.getFilesDropped(dataTransferItems)
|
var files = await this.getFilesDropped(dataTransferItems)
|
||||||
if (!files || !files.length) return { error: 'No files found ' }
|
if (!files || !files.length) return { error: 'No files found ' }
|
||||||
|
|
||||||
var itemData = this.fileTreeToItems(files, mediaType)
|
var itemData = this.fileTreeToItems(files, mediaType)
|
||||||
if (!itemData.items.length && !itemData.ignoredFiles.length) {
|
if (!itemData.items.length && !itemData.ignoredFiles.length) {
|
||||||
return { error: 'Invalid file drop' }
|
return { error: 'Invalid file drop' }
|
||||||
@ -218,9 +236,12 @@ export default {
|
|||||||
else {
|
else {
|
||||||
file.filetype = filetype
|
file.filetype = filetype
|
||||||
if (file.webkitRelativePath) file.filepath = file.webkitRelativePath
|
if (file.webkitRelativePath) file.filepath = file.webkitRelativePath
|
||||||
|
else file.filepath = file.name
|
||||||
|
|
||||||
if (filetype === 'audio' || (filetype === 'ebook' && mediaType === 'book')) {
|
if (filetype === 'audio' || (filetype === 'ebook' && mediaType === 'book')) {
|
||||||
var dir = file.filepath ? Path.dirname(file.filepath) : ''
|
var dir = file.filepath ? Path.dirname(file.filepath) : ''
|
||||||
|
if (dir === '.') dir = ''
|
||||||
|
|
||||||
if (!itemMap[dir]) {
|
if (!itemMap[dir]) {
|
||||||
itemMap[dir] = {
|
itemMap[dir] = {
|
||||||
path: dir,
|
path: dir,
|
||||||
@ -246,8 +267,17 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var items = []
|
||||||
var index = 1
|
var index = 1
|
||||||
var items = Object.values(itemMap).map(i => this.cleanItem(i, mediaType, index++))
|
// If book media type and all files are audio files then treat each one as an audiobook
|
||||||
|
if (itemMap[''] && !otherFiles.length && mediaType === 'book' && !itemMap[''].itemFiles.some(f => f.filetype !== 'audio')) {
|
||||||
|
items = itemMap[''].itemFiles.map((audioFile) => {
|
||||||
|
return this.cleanItem({ itemFiles: [audioFile], otherFiles: [], ignoredFiles: [] }, mediaType, index++)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
items = Object.values(itemMap).map(i => this.cleanItem(i, mediaType, index++))
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items,
|
items,
|
||||||
ignoredFiles: ignoredFiles
|
ignoredFiles: ignoredFiles
|
||||||
|
@ -29,7 +29,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pt-8 text-center">
|
<div class="pt-8 text-center">
|
||||||
<p class="text-xs text-white text-opacity-50 font-mono"><strong>Supported File Types: </strong>{{ inputAccept.join(', ') }}</p>
|
<p class="text-xs text-white text-opacity-50 font-mono mb-4"><strong>Supported File Types: </strong>{{ inputAccept.join(', ') }}</p>
|
||||||
|
|
||||||
|
<p class="text-sm text-white text-opacity-70">Folders with media files will be treated as separate library items. <span v-if="selectedLibraryMediaType === 'book'">If uploading only audio files then each audio file will be treated as a separate audiobook.</span></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Item list header -->
|
<!-- Item list header -->
|
||||||
|
Loading…
Reference in New Issue
Block a user