2021-09-04 21:17:26 +02:00
|
|
|
<template>
|
2021-09-06 21:13:01 +02:00
|
|
|
<div class="w-full h-full overflow-hidden overflow-y-auto px-4 py-6">
|
2021-09-15 03:45:00 +02:00
|
|
|
<p class="text-center text-lg mb-4 py-8">Preparing downloads can take several minutes and will be stored in <span class="bg-primary bg-opacity-75 font-mono p-1 text-base">/metadata/downloads</span>. After the download is ready, it will remain available for 60 minutes, then be deleted.<br />Download will timeout after 15 minutes.</p>
|
2021-10-10 23:36:21 +02:00
|
|
|
<div v-if="showM4bDownload" class="w-full border border-black-200 p-4 my-4">
|
2021-09-15 03:45:00 +02:00
|
|
|
<div class="flex items-center">
|
|
|
|
<div>
|
|
|
|
<p class="text-lg">M4B Audiobook File <span class="text-error">*</span></p>
|
|
|
|
<p class="max-w-xs text-sm pt-2 text-gray-300">Generate a .M4B audiobook file with embedded cover image and chapters.</p>
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow" />
|
|
|
|
<div>
|
|
|
|
<p v-if="singleDownloadStatus === $constants.DownloadStatus.FAILED" class="text-error mb-2">Download Failed</p>
|
|
|
|
<p v-if="singleDownloadStatus === $constants.DownloadStatus.READY" class="text-success mb-2">Download Ready!</p>
|
|
|
|
<p v-if="singleDownloadStatus === $constants.DownloadStatus.EXPIRED" class="text-error mb-2">Download Expired</p>
|
2021-09-04 21:17:26 +02:00
|
|
|
|
2021-09-15 03:45:00 +02:00
|
|
|
<ui-btn v-if="singleDownloadStatus !== $constants.DownloadStatus.READY" :loading="singleDownloadStatus === $constants.DownloadStatus.PENDING" :disabled="tempDisable" @click="startSingleAudioDownload">Start Download</ui-btn>
|
|
|
|
<div v-else>
|
|
|
|
<ui-btn @click="downloadWithProgress(singleAudioDownload)">Download</ui-btn>
|
|
|
|
<p class="px-0.5 py-1 text-sm font-mono text-center">Size: {{ $bytesPretty(singleAudioDownload.size) }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="w-full border border-black-200 p-4 my-4">
|
2021-09-04 21:17:26 +02:00
|
|
|
<div class="flex items-center">
|
2021-09-15 03:45:00 +02:00
|
|
|
<div>
|
|
|
|
<p v-if="totalFiles > 1" class="text-lg">Zip {{ totalFiles }} Files</p>
|
|
|
|
<p v-else>Zip 1 File</p>
|
|
|
|
<p class="max-w-xs text-sm pt-2 text-gray-300">Generate a .ZIP file from the contents of the audiobook directory.</p>
|
|
|
|
</div>
|
|
|
|
|
2021-09-04 21:17:26 +02:00
|
|
|
<div class="flex-grow" />
|
|
|
|
<div>
|
2021-09-15 03:45:00 +02:00
|
|
|
<p v-if="zipDownloadStatus === $constants.DownloadStatus.FAILED" class="text-error mb-2">Download Failed</p>
|
|
|
|
<p v-if="zipDownloadStatus === $constants.DownloadStatus.READY" class="text-success mb-2">Download Ready!</p>
|
|
|
|
<p v-if="zipDownloadStatus === $constants.DownloadStatus.EXPIRED" class="text-error mb-2">Download Expired</p>
|
|
|
|
|
|
|
|
<ui-btn v-if="zipDownloadStatus !== $constants.DownloadStatus.READY" :loading="zipDownloadStatus === $constants.DownloadStatus.PENDING" :disabled="tempDisable" @click="startZipDownload">Start Download</ui-btn>
|
|
|
|
<div v-else>
|
|
|
|
<ui-btn @click="downloadWithProgress(zipDownload)">Download</ui-btn>
|
|
|
|
<p class="px-0.5 py-1 text-sm font-mono text-center">Size: {{ $bytesPretty(zipDownload.size) }}</p>
|
|
|
|
</div>
|
2021-09-04 21:17:26 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-10-10 23:36:21 +02:00
|
|
|
<div v-if="showM4bDownload" class="w-full flex items-center justify-center absolute bottom-4 left-0 right-0 text-center">
|
2021-09-15 03:45:00 +02:00
|
|
|
<p class="text-error text-lg">* <strong>Experimental:</strong> Merging multiple .m4b files may have issues. <a href="https://github.com/advplyr/audiobookshelf/issues" class="underline text-blue-600" target="_blank">Report issues here.</a></p>
|
|
|
|
</div>
|
|
|
|
|
2021-09-04 21:17:26 +02:00
|
|
|
<div v-if="isDownloading" class="absolute top-0 left-0 w-full h-full bg-black bg-opacity-50 z-50 flex items-center justify-center">
|
|
|
|
<div class="w-80 border border-black-400 bg-bg rounded-xl h-20">
|
|
|
|
<div class="w-full h-full flex items-center justify-center">
|
|
|
|
<p class="text-lg">Download.... {{ downloadPercent }}%</p>
|
|
|
|
<p class="w-24 font-mono pl-8 text-right">
|
|
|
|
{{ downloadAmount }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
processing: Boolean,
|
|
|
|
audiobook: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
tempDisable: false,
|
|
|
|
isDownloading: false,
|
|
|
|
downloadPercent: '0',
|
|
|
|
downloadAmount: '0 KB'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
2021-09-15 03:45:00 +02:00
|
|
|
singleDownloadStatus(newVal) {
|
2021-09-04 21:17:26 +02:00
|
|
|
if (newVal) {
|
|
|
|
this.tempDisable = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
audiobookId() {
|
|
|
|
return this.audiobook ? this.audiobook.id : null
|
|
|
|
},
|
2021-10-10 23:36:21 +02:00
|
|
|
_audiobook() {
|
|
|
|
return this.audiobook || {}
|
|
|
|
},
|
2021-09-04 21:17:26 +02:00
|
|
|
downloads() {
|
|
|
|
return this.$store.getters['downloads/getDownloads'](this.audiobookId)
|
|
|
|
},
|
|
|
|
singleAudioDownload() {
|
|
|
|
return this.downloads.find((d) => d.type === 'singleAudio')
|
|
|
|
},
|
2021-09-15 03:45:00 +02:00
|
|
|
singleDownloadStatus() {
|
|
|
|
return this.singleAudioDownload ? this.singleAudioDownload.status : false
|
2021-09-04 21:17:26 +02:00
|
|
|
},
|
2021-09-15 03:45:00 +02:00
|
|
|
zipDownload() {
|
|
|
|
return this.downloads.find((d) => d.type === 'zip')
|
2021-09-04 21:17:26 +02:00
|
|
|
},
|
2021-09-15 03:45:00 +02:00
|
|
|
zipDownloadStatus() {
|
|
|
|
return this.zipDownload ? this.zipDownload.status : false
|
2021-09-06 21:13:01 +02:00
|
|
|
},
|
|
|
|
isSingleTrack() {
|
|
|
|
if (!this.audiobook.tracks) return false
|
|
|
|
return this.audiobook.tracks.length === 1
|
|
|
|
},
|
|
|
|
singleTrackPath() {
|
|
|
|
if (!this.isSingleTrack) return null
|
|
|
|
return this.audiobook.tracks[0].path
|
2021-09-15 03:45:00 +02:00
|
|
|
},
|
|
|
|
audioFiles() {
|
|
|
|
return this.audiobook ? this.audiobook.audioFiles || [] : []
|
|
|
|
},
|
|
|
|
otherFiles() {
|
|
|
|
return this.audiobook ? this.audiobook.otherFiles || [] : []
|
|
|
|
},
|
|
|
|
totalFiles() {
|
|
|
|
return this.audioFiles.length + this.otherFiles.length
|
2021-10-10 23:36:21 +02:00
|
|
|
},
|
|
|
|
showM4bDownload() {
|
2021-12-02 02:07:03 +01:00
|
|
|
return !this._audiobook.isMissing && !this._audiobook.isInvalid && this._audiobook.tracks.length
|
2021-09-04 21:17:26 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-09-15 03:45:00 +02:00
|
|
|
startZipDownload() {
|
|
|
|
// console.log('Download request received', this.audiobook)
|
|
|
|
|
|
|
|
this.tempDisable = true
|
|
|
|
setTimeout(() => {
|
|
|
|
this.tempDisable = false
|
|
|
|
}, 1000)
|
|
|
|
|
|
|
|
var downloadPayload = {
|
|
|
|
audiobookId: this.audiobook.id,
|
|
|
|
type: 'zip'
|
|
|
|
}
|
|
|
|
this.$root.socket.emit('download', downloadPayload)
|
|
|
|
},
|
2021-09-04 21:17:26 +02:00
|
|
|
startSingleAudioDownload() {
|
2021-09-15 03:45:00 +02:00
|
|
|
// console.log('Download request received', this.audiobook)
|
2021-09-04 21:17:26 +02:00
|
|
|
|
|
|
|
this.tempDisable = true
|
|
|
|
setTimeout(() => {
|
|
|
|
this.tempDisable = false
|
|
|
|
}, 1000)
|
|
|
|
|
|
|
|
var downloadPayload = {
|
|
|
|
audiobookId: this.audiobook.id,
|
2021-09-09 12:10:55 +02:00
|
|
|
type: 'singleAudio',
|
|
|
|
includeMetadata: true,
|
|
|
|
includeCover: true
|
2021-09-04 21:17:26 +02:00
|
|
|
}
|
|
|
|
this.$root.socket.emit('download', downloadPayload)
|
|
|
|
},
|
2021-09-15 03:45:00 +02:00
|
|
|
downloadWithProgress(download) {
|
|
|
|
var downloadId = download.id
|
2021-09-04 21:17:26 +02:00
|
|
|
var downloadUrl = `${process.env.serverUrl}/api/download/${downloadId}`
|
2021-09-15 03:45:00 +02:00
|
|
|
var filename = download.filename
|
2021-09-04 21:17:26 +02:00
|
|
|
|
|
|
|
this.isDownloading = true
|
|
|
|
|
|
|
|
var request = new XMLHttpRequest()
|
|
|
|
request.responseType = 'blob'
|
|
|
|
request.open('get', downloadUrl, true)
|
|
|
|
request.setRequestHeader('Authorization', `Bearer ${this.$store.getters['user/getToken']}`)
|
|
|
|
request.send()
|
|
|
|
|
|
|
|
request.onreadystatechange = () => {
|
|
|
|
if (request.readyState === 4) {
|
|
|
|
this.isDownloading = false
|
|
|
|
}
|
|
|
|
if (request.readyState == 4 && request.status == 200) {
|
|
|
|
const url = window.URL.createObjectURL(request.response)
|
|
|
|
|
|
|
|
const anchor = document.createElement('a')
|
|
|
|
anchor.href = url
|
|
|
|
anchor.download = filename
|
|
|
|
document.body.appendChild(anchor)
|
|
|
|
anchor.click()
|
|
|
|
setTimeout(() => {
|
|
|
|
if (anchor) anchor.remove()
|
|
|
|
}, 1000)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
request.onerror = (err) => {
|
|
|
|
console.error('Download error', err)
|
|
|
|
this.isDownloading = false
|
|
|
|
}
|
|
|
|
|
|
|
|
request.onprogress = (e) => {
|
|
|
|
const percent_complete = Math.floor((e.loaded / e.total) * 100)
|
|
|
|
this.downloadAmount = this.$bytesPretty(e.loaded)
|
|
|
|
this.downloadPercent = percent_complete
|
|
|
|
|
|
|
|
// const duration = (new Date().getTime() - startTime) / 1000
|
|
|
|
// const bps = e.loaded / duration
|
|
|
|
// const kbps = Math.floor(bps / 1024)
|
|
|
|
// const time = (e.total - e.loaded) / bps
|
|
|
|
// const seconds = Math.floor(time % 60)
|
|
|
|
// const minutes = Math.floor(time / 60)
|
|
|
|
// console.log(`${percent_complete}% - ${kbps} Kbps - ${minutes} min ${seconds} sec remaining`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|