Update:Uploader to treat audio files as separate audiobooks if uploading only audio files #670

This commit is contained in:
advplyr 2022-06-18 16:44:20 -05:00
parent 5452a57a14
commit 0c8fd6ab0e
2 changed files with 44 additions and 12 deletions

View File

@ -28,11 +28,11 @@ export default {
var validOtherFiles = []
var ignoredFiles = []
files.forEach((file) => {
var filetype = this.checkFileType(file.name)
if (!filetype) ignoredFiles.push(file)
// var filetype = this.checkFileType(file.name)
if (!file.filetype) ignoredFiles.push(file)
else {
file.filetype = filetype
if (filetype === 'audio' || (filetype === 'ebook' && mediaType === 'book')) validItemFiles.push(file)
// file.filetype = filetype
if (file.filetype === 'audio' || (file.filetype === 'ebook' && mediaType === 'book')) validItemFiles.push(file)
else validOtherFiles.push(file)
}
})
@ -82,12 +82,18 @@ export default {
items: itemResults,
ignoredFiles: ignoredFilesInRoot
}
} else {
} else if (filetree.some((f) => f.filetype !== 'audio') || mediaType !== 'book') {
// Single Book drop
return {
items: this.itemFromTreeItems(filetree, mediaType),
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) {
@ -95,11 +101,12 @@ export default {
path: '/',
items: []
}
function traverseFileTreePromise(item, currtreemap) {
function traverseFileTreePromise(item, currtreemap, checkFileType) {
return new Promise((resolve) => {
if (item.isFile) {
item.file((file) => {
file.filepath = currtreemap.path + file.name //save full path
file.filetype = checkFileType(file.name)
currtreemap.items.push(file)
resolve(file)
})
@ -119,7 +126,7 @@ export default {
dirReader.readEntries((entries) => {
if (entries.length > 0) {
for (let entr of entries) {
entriesPromises.push(traverseFileTreePromise(entr, newtreemap))
entriesPromises.push(traverseFileTreePromise(entr, newtreemap, checkFileType))
}
readEntries()
} else {
@ -135,7 +142,7 @@ export default {
return new Promise((resolve, reject) => {
let entriesPromises = []
for (let it of dataTransferItems) {
var filetree = traverseFileTreePromise(it.webkitGetAsEntry(), treemap)
var filetree = traverseFileTreePromise(it.webkitGetAsEntry(), treemap, this.checkFileType)
entriesPromises.push(filetree)
}
Promise.all(entriesPromises).then(() => {
@ -152,7 +159,9 @@ export default {
...book
}
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)
@ -165,6 +174,9 @@ export default {
if (dirs.length) {
audiobook.author = dirs.pop()
}
} else {
// Use file basename as title
audiobook.title = Path.basename(firstBookFile.name, Path.extname(firstBookFile.name))
}
return audiobook
},
@ -178,7 +190,12 @@ export default {
if (!firstAudioFile.filepath) return podcast // No path
var firstPath = Path.dirname(firstAudioFile.filepath)
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
},
cleanItem(item, mediaType, index) {
@ -188,6 +205,7 @@ export default {
async getItemsFromDataTransferItems(dataTransferItems, mediaType) {
var files = await this.getFilesDropped(dataTransferItems)
if (!files || !files.length) return { error: 'No files found ' }
var itemData = this.fileTreeToItems(files, mediaType)
if (!itemData.items.length && !itemData.ignoredFiles.length) {
return { error: 'Invalid file drop' }
@ -218,9 +236,12 @@ export default {
else {
file.filetype = filetype
if (file.webkitRelativePath) file.filepath = file.webkitRelativePath
else file.filepath = file.name
if (filetype === 'audio' || (filetype === 'ebook' && mediaType === 'book')) {
var dir = file.filepath ? Path.dirname(file.filepath) : ''
if (dir === '.') dir = ''
if (!itemMap[dir]) {
itemMap[dir] = {
path: dir,
@ -246,8 +267,17 @@ export default {
}
})
var items = []
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 {
items,
ignoredFiles: ignoredFiles

View File

@ -29,7 +29,9 @@
</div>
</div>
<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>
<!-- Item list header -->