2021-08-18 00:01:11 +02:00
|
|
|
<template>
|
2021-08-26 16:47:51 +02:00
|
|
|
<div id="page-wrapper" class="bg-bg page overflow-hidden relative" :class="streamAudiobook ? 'streaming' : ''">
|
2021-08-18 00:01:11 +02:00
|
|
|
<div v-show="saving" class="absolute z-20 w-full h-full flex items-center justify-center">
|
|
|
|
<ui-loading-indicator />
|
|
|
|
</div>
|
|
|
|
<div class="w-full h-full overflow-y-auto p-8">
|
|
|
|
<div class="w-full flex justify-between items-center pb-6 pt-2">
|
|
|
|
<p class="text-lg">Drag files into correct track order</p>
|
|
|
|
<ui-btn color="success" @click="saveTracklist">Save Tracklist</ui-btn>
|
|
|
|
</div>
|
|
|
|
<div class="w-full flex items-center text-sm py-4 bg-primary border-l border-r border-t border-gray-600">
|
|
|
|
<div class="font-book text-center px-4 w-12">New</div>
|
|
|
|
<div class="font-book text-center px-4 w-12">Old</div>
|
|
|
|
<div class="font-book text-center px-4 w-32">Track Parsed from Filename</div>
|
|
|
|
<div class="font-book text-center px-4 w-32">Track From Metadata</div>
|
|
|
|
<div class="font-book truncate px-4 flex-grow">Filename</div>
|
|
|
|
|
|
|
|
<div class="font-mono w-20 text-center">Size</div>
|
|
|
|
<div class="font-mono w-20 text-center">Duration</div>
|
|
|
|
<div class="font-mono text-center w-20">Status</div>
|
|
|
|
<div class="font-mono w-56">Notes</div>
|
2021-09-05 01:02:42 +02:00
|
|
|
<div class="font-book w-40">Include in Tracklist</div>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
<draggable v-model="files" v-bind="dragOptions" class="list-group border border-gray-600" draggable=".item" tag="ul" @start="drag = true" @end="drag = false">
|
|
|
|
<transition-group type="transition" :name="!drag ? 'flip-list' : null">
|
2021-09-05 01:02:42 +02:00
|
|
|
<li v-for="(audio, index) in files" :key="audio.path" :class="audio.include ? 'item' : 'exclude'" class="w-full list-group-item flex items-center">
|
2021-08-18 00:01:11 +02:00
|
|
|
<div class="font-book text-center px-4 py-1 w-12">
|
2021-09-05 01:02:42 +02:00
|
|
|
{{ audio.include ? index - numExcluded + 1 : -1 }}
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
2021-09-05 01:02:42 +02:00
|
|
|
<div class="font-book text-center px-4 w-12">{{ audio.index }}</div>
|
2021-08-20 00:29:36 +02:00
|
|
|
<div class="font-book text-center px-2 w-32">
|
2021-08-18 00:01:11 +02:00
|
|
|
{{ audio.trackNumFromFilename }}
|
|
|
|
</div>
|
2021-08-20 00:29:36 +02:00
|
|
|
<div class="font-book text-center w-32">
|
2021-08-18 00:01:11 +02:00
|
|
|
{{ audio.trackNumFromMeta }}
|
|
|
|
</div>
|
|
|
|
<div class="font-book truncate px-4 flex-grow">
|
|
|
|
{{ audio.filename }}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="font-mono w-20 text-center">
|
|
|
|
{{ $bytesPretty(audio.size) }}
|
|
|
|
</div>
|
|
|
|
<div class="font-mono w-20">
|
|
|
|
{{ $secondsToTimestamp(audio.duration) }}
|
|
|
|
</div>
|
|
|
|
<div class="font-mono text-center w-20">
|
|
|
|
<span class="material-icons text-sm" :class="audio.invalid ? 'text-error' : 'text-success'">{{ getStatusIcon(audio) }}</span>
|
|
|
|
</div>
|
|
|
|
<div class="font-sans text-xs font-normal w-56">
|
|
|
|
{{ audio.error }}
|
|
|
|
</div>
|
2021-09-05 01:02:42 +02:00
|
|
|
<div class="font-sans text-xs font-normal w-40 flex justify-center">
|
|
|
|
<ui-toggle-switch v-model="audio.include" :off-color="'error'" @input="includeToggled(audio)" />
|
|
|
|
</div>
|
2021-08-18 00:01:11 +02:00
|
|
|
</li>
|
|
|
|
</transition-group>
|
|
|
|
</draggable>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import draggable from 'vuedraggable'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
draggable
|
|
|
|
},
|
|
|
|
async asyncData({ store, params, app, redirect, route }) {
|
2021-08-24 01:31:04 +02:00
|
|
|
if (!store.state.user.user) {
|
2021-08-18 00:01:11 +02:00
|
|
|
return redirect(`/login?redirect=${route.path}`)
|
|
|
|
}
|
2021-09-07 00:42:15 +02:00
|
|
|
if (!store.getters['user/getUserCanUpdate']) {
|
|
|
|
return redirect('/?error=unauthorized')
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
var audiobook = await app.$axios.$get(`/api/audiobook/${params.id}`).catch((error) => {
|
|
|
|
console.error('Failed', error)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
if (!audiobook) {
|
|
|
|
console.error('No audiobook...', params.id)
|
|
|
|
return redirect('/')
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
audiobook,
|
2021-09-05 01:02:42 +02:00
|
|
|
files: audiobook.audioFiles ? audiobook.audioFiles.map((af) => ({ ...af, include: !af.exclude })) : []
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
drag: false,
|
|
|
|
dragOptions: {
|
|
|
|
animation: 200,
|
|
|
|
group: 'description',
|
|
|
|
ghostClass: 'ghost'
|
|
|
|
},
|
|
|
|
saving: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
audioFiles() {
|
|
|
|
return this.audiobook.audioFiles || []
|
|
|
|
},
|
2021-09-05 01:02:42 +02:00
|
|
|
numExcluded() {
|
|
|
|
var count = 0
|
|
|
|
this.files.forEach((file) => {
|
|
|
|
if (!file.include) count++
|
|
|
|
})
|
|
|
|
return count
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
missingPartChunks() {
|
|
|
|
if (this.missingParts === 1) return this.missingParts[0]
|
|
|
|
var chunks = []
|
|
|
|
|
|
|
|
var currentIndex = this.missingParts[0]
|
|
|
|
var currentChunk = [this.missingParts[0]]
|
|
|
|
|
|
|
|
for (let i = 1; i < this.missingParts.length; i++) {
|
|
|
|
var partIndex = this.missingParts[i]
|
|
|
|
if (currentIndex === partIndex - 1) {
|
|
|
|
currentChunk.push(partIndex)
|
|
|
|
currentIndex = partIndex
|
|
|
|
} else {
|
|
|
|
// console.log('Chunk ended', currentChunk.join(', '), currentIndex, partIndex)
|
|
|
|
if (currentChunk.length === 0) {
|
|
|
|
console.error('How is current chunk 0?', currentChunk.join(', '))
|
|
|
|
}
|
|
|
|
chunks.push(currentChunk)
|
|
|
|
currentChunk = [partIndex]
|
|
|
|
currentIndex = partIndex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentChunk.length) {
|
|
|
|
chunks.push(currentChunk)
|
|
|
|
}
|
|
|
|
chunks = chunks.map((chunk) => {
|
|
|
|
if (chunk.length === 1) return chunk[0]
|
|
|
|
else return `${chunk[0]}-${chunk[chunk.length - 1]}`
|
|
|
|
})
|
|
|
|
return chunks
|
|
|
|
},
|
|
|
|
missingParts() {
|
|
|
|
return this.audiobook.missingParts || []
|
|
|
|
},
|
|
|
|
invalidParts() {
|
|
|
|
return this.audiobook.invalidParts || []
|
|
|
|
},
|
|
|
|
audiobookId() {
|
|
|
|
return this.audiobook.id
|
|
|
|
},
|
|
|
|
title() {
|
|
|
|
return this.book.title || 'No Title'
|
|
|
|
},
|
|
|
|
author() {
|
|
|
|
return this.book.author || 'Unknown'
|
|
|
|
},
|
|
|
|
tracks() {
|
|
|
|
return this.audiobook.tracks
|
|
|
|
},
|
|
|
|
durationPretty() {
|
|
|
|
return this.audiobook.durationPretty
|
|
|
|
},
|
|
|
|
sizePretty() {
|
|
|
|
return this.audiobook.sizePretty
|
|
|
|
},
|
|
|
|
book() {
|
|
|
|
return this.audiobook.book || {}
|
|
|
|
},
|
|
|
|
tracks() {
|
|
|
|
return this.audiobook.tracks || []
|
|
|
|
},
|
|
|
|
streamAudiobook() {
|
|
|
|
return this.$store.state.streamAudiobook
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-09-05 01:02:42 +02:00
|
|
|
includeToggled(audio) {
|
|
|
|
var new_index = 0
|
|
|
|
if (audio.include) {
|
|
|
|
new_index = this.numExcluded
|
|
|
|
}
|
|
|
|
var old_index = this.files.findIndex((f) => f.ino === audio.ino)
|
|
|
|
if (new_index >= this.files.length) {
|
|
|
|
var k = new_index - this.files.length + 1
|
|
|
|
while (k--) {
|
|
|
|
this.files.push(undefined)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.files.splice(new_index, 0, this.files.splice(old_index, 1)[0])
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
saveTracklist() {
|
2021-09-05 01:02:42 +02:00
|
|
|
var orderedFileData = this.files.map((file) => {
|
|
|
|
return {
|
|
|
|
index: file.index,
|
|
|
|
filename: file.filename,
|
|
|
|
ino: file.ino,
|
|
|
|
exclude: !file.include
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-08-18 00:01:11 +02:00
|
|
|
this.saving = true
|
|
|
|
this.$axios
|
2021-09-05 01:02:42 +02:00
|
|
|
.$patch(`/api/audiobook/${this.audiobook.id}/tracks`, { orderedFileData })
|
2021-08-18 00:01:11 +02:00
|
|
|
.then((data) => {
|
|
|
|
console.log('Finished patching files', data)
|
|
|
|
this.saving = false
|
|
|
|
this.$toast.success('Tracks Updated')
|
|
|
|
this.$router.push(`/audiobook/${this.audiobookId}`)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
|
|
|
this.saving = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getStatusIcon(audio) {
|
|
|
|
if (audio.invalid) {
|
|
|
|
return 'error_outline'
|
|
|
|
} else {
|
|
|
|
return 'check_circle'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.flip-list-move {
|
|
|
|
transition: transform 0.5s;
|
|
|
|
}
|
|
|
|
.no-move {
|
|
|
|
transition: transform 0s;
|
|
|
|
}
|
|
|
|
.ghost {
|
|
|
|
opacity: 0.5;
|
|
|
|
background-color: rgba(255, 255, 255, 0.25);
|
|
|
|
}
|
|
|
|
.list-group {
|
|
|
|
min-height: 30px;
|
|
|
|
}
|
2021-09-05 01:02:42 +02:00
|
|
|
.list-group-item:not(.exclude) {
|
2021-08-18 00:01:11 +02:00
|
|
|
cursor: n-resize;
|
|
|
|
}
|
2021-09-05 01:02:42 +02:00
|
|
|
.list-group-item.exclude {
|
|
|
|
cursor: not-allowed;
|
|
|
|
}
|
|
|
|
.list-group-item:not(.ghost):not(.exclude):hover {
|
2021-08-18 00:01:11 +02:00
|
|
|
background-color: rgba(0, 0, 0, 0.1);
|
|
|
|
}
|
2021-09-05 01:02:42 +02:00
|
|
|
.list-group-item:nth-child(even):not(.ghost):not(.exclude) {
|
2021-08-18 00:01:11 +02:00
|
|
|
background-color: rgba(0, 0, 0, 0.25);
|
|
|
|
}
|
2021-09-05 01:02:42 +02:00
|
|
|
.list-group-item:nth-child(even):not(.ghost):not(.exclude):hover {
|
2021-08-18 00:01:11 +02:00
|
|
|
background-color: rgba(0, 0, 0, 0.1);
|
|
|
|
}
|
2021-09-05 01:02:42 +02:00
|
|
|
|
|
|
|
.list-group-item.exclude:not(.ghost) {
|
|
|
|
background-color: rgba(255, 0, 0, 0.25);
|
|
|
|
}
|
|
|
|
.list-group-item.exclude:not(.ghost):hover {
|
|
|
|
background-color: rgba(223, 0, 0, 0.25);
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
</style>
|