2022-04-06 20:36:17 -05:00
|
|
|
<template>
|
2022-04-10 20:31:47 -05:00
|
|
|
<div class="w-full h-full py-6 px-2">
|
2022-04-06 20:36:17 -05:00
|
|
|
<div v-if="localLibraryItem" class="w-full h-full">
|
2022-04-10 20:31:47 -05:00
|
|
|
<div class="px-2 flex items-center mb-2">
|
2022-04-08 18:07:31 -05:00
|
|
|
<p class="text-base font-book font-semibold">{{ mediaMetadata.title }}</p>
|
|
|
|
<div class="flex-grow" />
|
|
|
|
|
2022-04-10 20:31:47 -05:00
|
|
|
<button v-if="audioTracks.length && !isPodcast" class="shadow-sm text-accent flex items-center justify-center rounded-full mx-2" @click.stop="play">
|
2022-04-06 20:36:17 -05:00
|
|
|
<span class="material-icons" style="font-size: 2rem">play_arrow</span>
|
|
|
|
</button>
|
2022-04-08 18:07:31 -05:00
|
|
|
<span class="material-icons" @click="showItemDialog">more_vert</span>
|
2022-04-06 20:36:17 -05:00
|
|
|
</div>
|
2022-04-07 18:46:58 -05:00
|
|
|
|
2022-04-10 20:31:47 -05:00
|
|
|
<p class="px-2 text-sm mb-0.5 text-white text-opacity-75">Folder: {{ folderName }}</p>
|
2022-04-08 18:07:31 -05:00
|
|
|
|
2022-04-10 20:31:47 -05:00
|
|
|
<p class="px-2 mb-4 text-xs text-gray-400">{{ libraryItemId ? 'Linked to item on server ' + liServerAddress : 'Not linked to server item' }}</p>
|
2022-04-07 18:46:58 -05:00
|
|
|
|
2022-04-06 20:36:17 -05:00
|
|
|
<div v-if="isScanning" class="w-full text-center p-4">
|
|
|
|
<p>Scanning...</p>
|
|
|
|
</div>
|
2022-04-13 20:24:54 -05:00
|
|
|
<div v-else class="w-full max-w-full media-item-container overflow-y-auto overflow-x-hidden relative">
|
2022-04-10 20:31:47 -05:00
|
|
|
<div v-if="!isPodcast" class="w-full">
|
|
|
|
<p class="text-base mb-2">Audio Tracks ({{ audioTracks.length }})</p>
|
2022-04-13 20:24:54 -05:00
|
|
|
|
|
|
|
<draggable v-model="audioTracksCopy" v-bind="dragOptions" handle=".drag-handle" draggable=".item" tag="div" @start="drag = true" @end="drag = false" @update="draggableUpdate">
|
|
|
|
<transition-group type="transition" :name="!drag ? 'dragtrack' : null">
|
|
|
|
<template v-for="track in audioTracksCopy">
|
|
|
|
<div :key="track.localFileId" class="flex items-center my-1 item">
|
|
|
|
<div class="w-8 h-12 flex items-center justify-center" style="min-width: 32px">
|
|
|
|
<span class="material-icons drag-handle text-lg text-white text-opacity-50 hover:text-opacity-100">menu</span>
|
|
|
|
</div>
|
|
|
|
<div class="w-8 h-12 flex items-center justify-center" style="min-width: 32px">
|
|
|
|
<p class="font-mono font-bold text-xl">{{ track.index }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow px-2">
|
|
|
|
<p class="text-xs">{{ track.title }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="w-20 text-center text-gray-300" style="min-width: 80px">
|
|
|
|
<p class="text-xs">{{ track.mimeType }}</p>
|
|
|
|
<p class="text-sm">{{ $elapsedPretty(track.duration) }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="w-12 h-12 flex items-center justify-center" style="min-width: 48px">
|
|
|
|
<span class="material-icons" @click="showTrackDialog(track)">more_vert</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</transition-group>
|
|
|
|
</draggable>
|
|
|
|
|
|
|
|
<!-- <template v-for="track in audioTracks">
|
2022-04-10 20:31:47 -05:00
|
|
|
<div :key="track.localFileId" class="flex items-center my-1">
|
|
|
|
<div class="w-10 h-12 flex items-center justify-center" style="min-width: 48px">
|
|
|
|
<p class="font-mono font-bold text-xl">{{ track.index }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow px-2">
|
|
|
|
<p class="text-xs">{{ track.title }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="w-20 text-center text-gray-300" style="min-width: 80px">
|
|
|
|
<p class="text-xs">{{ track.mimeType }}</p>
|
|
|
|
<p class="text-sm">{{ $elapsedPretty(track.duration) }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="w-12 h-12 flex items-center justify-center" style="min-width: 48px">
|
|
|
|
<span class="material-icons" @click="showTrackDialog(track)">more_vert</span>
|
|
|
|
</div>
|
2022-04-06 20:36:17 -05:00
|
|
|
</div>
|
2022-04-13 20:24:54 -05:00
|
|
|
</template> -->
|
2022-04-10 20:31:47 -05:00
|
|
|
</div>
|
|
|
|
<div v-else class="w-full">
|
|
|
|
<p class="text-base mb-2">Episodes ({{ audioTracks.length }})</p>
|
|
|
|
<template v-for="episode in audioTracks">
|
|
|
|
<div :key="episode.id" class="flex items-center my-1">
|
|
|
|
<div class="w-10 h-12 flex items-center justify-center" style="min-width: 48px">
|
|
|
|
<p class="font-mono font-bold text-xl">{{ episode.index }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow px-2">
|
|
|
|
<p class="text-xs">{{ episode.title }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="w-20 text-center text-gray-300" style="min-width: 80px">
|
|
|
|
<p class="text-xs">{{ episode.audioTrack.mimeType }}</p>
|
|
|
|
<p class="text-sm">{{ $elapsedPretty(episode.audioTrack.duration) }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="w-12 h-12 flex items-center justify-center" style="min-width: 48px">
|
|
|
|
<span class="material-icons" @click="showTrackDialog(episode)">more_vert</span>
|
|
|
|
</div>
|
2022-04-06 20:36:17 -05:00
|
|
|
</div>
|
2022-04-10 20:31:47 -05:00
|
|
|
</template>
|
|
|
|
</div>
|
2022-04-06 20:36:17 -05:00
|
|
|
|
2022-04-08 18:07:31 -05:00
|
|
|
<p v-if="otherFiles.length" class="text-lg mb-2 pt-8">Other Files</p>
|
|
|
|
<template v-for="file in otherFiles">
|
2022-04-06 20:36:17 -05:00
|
|
|
<div :key="file.id" class="flex items-center my-1">
|
|
|
|
<div class="w-12 h-12 flex items-center justify-center">
|
|
|
|
<img v-if="(file.mimeType || '').startsWith('image')" :src="getCapImageSrc(file.contentUrl)" class="w-full h-full object-contain" />
|
|
|
|
<span v-else class="material-icons">music_note</span>
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow px-2">
|
|
|
|
<p class="text-sm">{{ file.filename }}</p>
|
|
|
|
</div>
|
|
|
|
<div class="w-20 text-center text-gray-300">
|
|
|
|
<p class="text-xs">{{ file.mimeType }}</p>
|
|
|
|
<p class="text-sm">{{ $bytesPretty(file.size) }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-10 20:31:47 -05:00
|
|
|
<div v-else class="px-2 w-full h-full">
|
2022-04-06 20:36:17 -05:00
|
|
|
<p class="text-lg text-center px-8">{{ failed ? 'Failed to get local library item ' + localLibraryItemId : 'Loading..' }}</p>
|
|
|
|
</div>
|
2022-04-08 18:07:31 -05:00
|
|
|
|
|
|
|
<modals-dialog v-model="showDialog" :items="dialogItems" @action="dialogAction" />
|
2022-04-06 20:36:17 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-13 20:24:54 -05:00
|
|
|
import draggable from 'vuedraggable'
|
|
|
|
|
2022-04-06 20:36:17 -05:00
|
|
|
import { Capacitor } from '@capacitor/core'
|
|
|
|
import { Dialog } from '@capacitor/dialog'
|
|
|
|
import { AbsFileSystem } from '@/plugins/capacitor'
|
|
|
|
|
|
|
|
export default {
|
2022-04-13 20:24:54 -05:00
|
|
|
components: {
|
|
|
|
draggable
|
|
|
|
},
|
2022-04-06 20:36:17 -05:00
|
|
|
asyncData({ params }) {
|
|
|
|
return {
|
|
|
|
localLibraryItemId: params.id
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2022-04-13 20:24:54 -05:00
|
|
|
drag: false,
|
|
|
|
dragOptions: {
|
|
|
|
animation: 200,
|
|
|
|
group: 'description',
|
|
|
|
delay: 40,
|
|
|
|
delayOnTouchOnly: true
|
|
|
|
},
|
2022-04-06 20:36:17 -05:00
|
|
|
failed: false,
|
|
|
|
localLibraryItem: null,
|
2022-04-13 20:24:54 -05:00
|
|
|
audioTracksCopy: [],
|
2022-04-06 20:36:17 -05:00
|
|
|
removingItem: false,
|
|
|
|
folderId: null,
|
|
|
|
folder: null,
|
2022-04-08 18:07:31 -05:00
|
|
|
isScanning: false,
|
|
|
|
showDialog: false,
|
2022-04-10 20:31:47 -05:00
|
|
|
selectedAudioTrack: null,
|
|
|
|
selectedEpisode: null
|
2022-04-06 20:36:17 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-04-08 18:07:31 -05:00
|
|
|
basePath() {
|
|
|
|
return this.localLibraryItem ? this.localLibraryItem.basePath : null
|
|
|
|
},
|
2022-04-06 20:36:17 -05:00
|
|
|
localFiles() {
|
|
|
|
return this.localLibraryItem ? this.localLibraryItem.localFiles : []
|
|
|
|
},
|
2022-04-08 18:07:31 -05:00
|
|
|
otherFiles() {
|
|
|
|
if (!this.localFiles.filter) {
|
|
|
|
console.error('Invalid local files', this.localFiles)
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
return this.localFiles.filter((lf) => {
|
2022-04-10 20:31:47 -05:00
|
|
|
if (this.isPodcast) return !this.audioTracks.find((episode) => episode.audioTrack.localFileId == lf.id)
|
2022-04-08 18:07:31 -05:00
|
|
|
return !this.audioTracks.find((at) => at.localFileId == lf.id)
|
|
|
|
})
|
|
|
|
},
|
2022-04-06 20:36:17 -05:00
|
|
|
folderName() {
|
|
|
|
return this.folder ? this.folder.name : null
|
|
|
|
},
|
|
|
|
mediaType() {
|
|
|
|
return this.localLibraryItem ? this.localLibraryItem.mediaType : null
|
2022-04-07 18:46:58 -05:00
|
|
|
},
|
2022-04-10 20:31:47 -05:00
|
|
|
isPodcast() {
|
|
|
|
return this.mediaType == 'podcast'
|
|
|
|
},
|
2022-04-08 18:07:31 -05:00
|
|
|
libraryItemId() {
|
2022-04-07 18:46:58 -05:00
|
|
|
return this.localLibraryItem ? this.localLibraryItem.libraryItemId : null
|
2022-04-06 20:36:17 -05:00
|
|
|
},
|
2022-04-08 18:07:31 -05:00
|
|
|
liServerAddress() {
|
|
|
|
return this.localLibraryItem ? this.localLibraryItem.serverAddress : null
|
|
|
|
},
|
2022-04-06 20:36:17 -05:00
|
|
|
media() {
|
|
|
|
return this.localLibraryItem ? this.localLibraryItem.media : null
|
|
|
|
},
|
|
|
|
mediaMetadata() {
|
|
|
|
return this.media ? this.media.metadata || {} : {}
|
|
|
|
},
|
|
|
|
audioTracks() {
|
|
|
|
if (!this.media) return []
|
|
|
|
if (this.mediaType == 'book') {
|
|
|
|
return this.media.tracks || []
|
|
|
|
} else {
|
|
|
|
return this.media.episodes || []
|
|
|
|
}
|
2022-04-08 18:07:31 -05:00
|
|
|
},
|
|
|
|
dialogItems() {
|
|
|
|
if (this.selectedAudioTrack) {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
text: 'Hard Delete',
|
|
|
|
value: 'track-delete'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
} else {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
text: 'Scan',
|
|
|
|
value: 'scan'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Force Re-Scan',
|
|
|
|
value: 'rescan'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Remove',
|
|
|
|
value: 'remove'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Hard Delete',
|
|
|
|
value: 'delete'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-04-06 20:36:17 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-04-13 20:24:54 -05:00
|
|
|
draggableUpdate() {
|
|
|
|
console.log('Draggable update', this.audioTracksCopy)
|
|
|
|
// var copyOfCopy = this.audioTracksCopy.map((at) => ({ ...at }))
|
|
|
|
// const payload = {
|
|
|
|
// localLibraryItemId: this.localLibraryItemId,
|
|
|
|
// tracks: copyOfCopy
|
|
|
|
// }
|
|
|
|
// this.$db.updateLocalTrackOrder(payload)
|
|
|
|
},
|
2022-04-08 18:07:31 -05:00
|
|
|
showItemDialog() {
|
|
|
|
this.selectedAudioTrack = null
|
|
|
|
this.showDialog = true
|
|
|
|
},
|
|
|
|
showTrackDialog(track) {
|
2022-04-10 20:31:47 -05:00
|
|
|
if (this.isPodcast) {
|
|
|
|
this.selectedAudioTrack = null
|
|
|
|
this.selectedEpisode = track
|
|
|
|
} else {
|
|
|
|
this.selectedEpisode = null
|
|
|
|
this.selectedAudioTrack = track
|
|
|
|
}
|
2022-04-08 18:07:31 -05:00
|
|
|
this.showDialog = true
|
|
|
|
},
|
2022-04-06 20:36:17 -05:00
|
|
|
play() {
|
2022-04-10 20:31:47 -05:00
|
|
|
this.$eventBus.$emit('play-item', { libraryItemId: this.localLibraryItemId })
|
2022-04-06 20:36:17 -05:00
|
|
|
},
|
|
|
|
getCapImageSrc(contentUrl) {
|
|
|
|
return Capacitor.convertFileSrc(contentUrl)
|
|
|
|
},
|
2022-04-08 18:07:31 -05:00
|
|
|
dialogAction(action) {
|
|
|
|
console.log('Dialog action', action)
|
|
|
|
if (action == 'scan') {
|
|
|
|
this.scanItem()
|
|
|
|
} else if (action == 'rescan') {
|
|
|
|
this.scanItem(true)
|
|
|
|
} else if (action == 'remove') {
|
|
|
|
this.removeItem()
|
|
|
|
} else if (action == 'delete') {
|
|
|
|
this.deleteItem()
|
|
|
|
} else if (action == 'track-delete') {
|
2022-04-10 20:31:47 -05:00
|
|
|
if (this.isPodcast) this.deleteEpisode()
|
|
|
|
else this.deleteTrack()
|
2022-04-08 18:07:31 -05:00
|
|
|
}
|
|
|
|
this.showDialog = false
|
2022-04-06 20:36:17 -05:00
|
|
|
},
|
2022-04-08 18:07:31 -05:00
|
|
|
getLocalFileForTrack(localFileId) {
|
|
|
|
return this.localFiles.find((lf) => lf.id == localFileId)
|
2022-04-06 20:36:17 -05:00
|
|
|
},
|
2022-04-10 20:31:47 -05:00
|
|
|
async deleteEpisode() {
|
|
|
|
if (!this.selectedEpisode) return
|
|
|
|
var localFile = this.getLocalFileForTrack(this.selectedEpisode.audioTrack.localFileId)
|
|
|
|
if (!localFile) {
|
|
|
|
this.$toast.error('Audio track does not have matching local file..')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var trackPath = localFile ? localFile.basePath : this.selectedEpisode.title
|
|
|
|
const { value } = await Dialog.confirm({
|
|
|
|
title: 'Confirm',
|
|
|
|
message: `Warning! This will delete the audio file "${trackPath}" from your file system. Are you sure?`
|
|
|
|
})
|
|
|
|
if (value) {
|
|
|
|
var res = await AbsFileSystem.deleteTrackFromItem({ id: this.localLibraryItem.id, trackLocalFileId: localFile.id, trackContentUrl: this.selectedEpisode.audioTrack.contentUrl })
|
|
|
|
if (res && res.id) {
|
|
|
|
this.$toast.success('Deleted track successfully')
|
|
|
|
this.localLibraryItem = res
|
|
|
|
} else this.$toast.error('Failed to delete')
|
|
|
|
}
|
|
|
|
},
|
2022-04-08 18:07:31 -05:00
|
|
|
async deleteTrack() {
|
|
|
|
if (!this.selectedAudioTrack) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var localFile = this.getLocalFileForTrack(this.selectedAudioTrack.localFileId)
|
|
|
|
if (!localFile) {
|
|
|
|
this.$toast.error('Audio track does not have matching local file..')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var trackPath = localFile ? localFile.basePath : this.selectedAudioTrack.title
|
|
|
|
const { value } = await Dialog.confirm({
|
|
|
|
title: 'Confirm',
|
|
|
|
message: `Warning! This will delete the audio file "${trackPath}" from your file system. Are you sure?`
|
|
|
|
})
|
|
|
|
if (value) {
|
|
|
|
var res = await AbsFileSystem.deleteTrackFromItem({ id: this.localLibraryItem.id, trackLocalFileId: this.selectedAudioTrack.localFileId, trackContentUrl: this.selectedAudioTrack.contentUrl })
|
|
|
|
if (res && res.id) {
|
|
|
|
this.$toast.success('Deleted track successfully')
|
|
|
|
this.localLibraryItem = res
|
|
|
|
} else this.$toast.error('Failed to delete')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async deleteItem() {
|
|
|
|
const { value } = await Dialog.confirm({
|
|
|
|
title: 'Confirm',
|
|
|
|
message: `Warning! This will delete the folder "${this.basePath}" and all contents. Are you sure?`
|
|
|
|
})
|
|
|
|
if (value) {
|
|
|
|
var res = await AbsFileSystem.deleteItem(this.localLibraryItem)
|
|
|
|
if (res && res.success) {
|
|
|
|
this.$toast.success('Deleted Successfully')
|
|
|
|
this.$router.replace(`/localMedia/folders/${this.folderId}`)
|
|
|
|
} else this.$toast.error('Failed to delete')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async removeItem() {
|
2022-04-06 20:36:17 -05:00
|
|
|
var deleteMessage = 'Are you sure you want to remove this local library item? (does not delete anything in your file system)'
|
|
|
|
const { value } = await Dialog.confirm({
|
|
|
|
title: 'Confirm',
|
|
|
|
message: deleteMessage
|
|
|
|
})
|
|
|
|
if (value) {
|
|
|
|
this.removingItem = true
|
|
|
|
await AbsFileSystem.removeLocalLibraryItem({ localLibraryItemId: this.localLibraryItemId })
|
|
|
|
this.removingItem = false
|
|
|
|
this.$router.replace(`/localMedia/folders/${this.folderId}`)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async scanItem(forceAudioProbe = false) {
|
2022-04-08 18:07:31 -05:00
|
|
|
if (this.isScanning) return
|
|
|
|
|
2022-04-06 20:36:17 -05:00
|
|
|
this.isScanning = true
|
|
|
|
var response = await AbsFileSystem.scanLocalLibraryItem({ localLibraryItemId: this.localLibraryItemId, forceAudioProbe })
|
|
|
|
|
|
|
|
if (response && response.localLibraryItem) {
|
|
|
|
if (response.updated) {
|
|
|
|
this.$toast.success('Local item was updated')
|
|
|
|
this.localLibraryItem = response.localLibraryItem
|
|
|
|
} else {
|
|
|
|
this.$toast.info('Local item was up to date')
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log('Failed')
|
|
|
|
this.$toast.error('Something went wrong..')
|
|
|
|
}
|
|
|
|
this.isScanning = false
|
|
|
|
},
|
|
|
|
async init() {
|
|
|
|
this.localLibraryItem = await this.$db.getLocalLibraryItem(this.localLibraryItemId)
|
2022-04-08 18:07:31 -05:00
|
|
|
|
2022-04-06 20:36:17 -05:00
|
|
|
if (!this.localLibraryItem) {
|
|
|
|
console.error('Failed to get local library item', this.localLibraryItemId)
|
|
|
|
this.failed = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-04-13 20:24:54 -05:00
|
|
|
this.audioTracksCopy = this.audioTracks.map((at) => ({ ...at }))
|
|
|
|
|
2022-04-06 20:36:17 -05:00
|
|
|
this.folderId = this.localLibraryItem.folderId
|
|
|
|
this.folder = await this.$db.getLocalFolder(this.folderId)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.init()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-04-13 20:24:54 -05:00
|
|
|
<style>
|
2022-04-06 20:36:17 -05:00
|
|
|
.media-item-container {
|
|
|
|
height: calc(100vh - 200px);
|
|
|
|
max-height: calc(100vh - 200px);
|
|
|
|
}
|
2022-04-13 20:24:54 -05:00
|
|
|
.sortable-ghost {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
.dragtrack-enter-from,
|
|
|
|
.dragtrack-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateX(30px);
|
|
|
|
}
|
|
|
|
|
|
|
|
.dragtrack-leave-active {
|
|
|
|
position: absolute;
|
|
|
|
}
|
2022-04-06 20:36:17 -05:00
|
|
|
</style>
|