2022-04-10 20:31:47 -05:00
|
|
|
<template>
|
2023-02-25 16:33:06 -06:00
|
|
|
<div class="w-full py-4 overflow-hidden relative border-b border-white border-opacity-10" @click.stop="goToEpisodePage">
|
2022-04-15 20:48:39 -05:00
|
|
|
<div v-if="episode" class="w-full px-1">
|
|
|
|
<!-- Help debug for testing -->
|
|
|
|
<!-- <template>
|
|
|
|
<p class="text-xs mb-1">{{ isLocal ? 'LOCAL' : 'NOT LOCAL' }}</p>
|
|
|
|
<p class="text-xs mb-4">Lid:{{ libraryItemId }}<br />Eid:{{ episode.id }}<br />LLid:{{ localLibraryItemId }}<br />LEid:{{ localEpisodeId }}</p>
|
|
|
|
<p v-if="itemProgress">Server Media Progress {{ Math.round(itemProgress.progress * 100) }}</p>
|
|
|
|
<p v-else>No Server Media Progress</p>
|
|
|
|
<p v-if="localMediaProgress">Local Media Progress {{ Math.round(localMediaProgress.progress * 100) }}</p>
|
|
|
|
<p v-else>No Local Media Progress</p>
|
2023-12-16 17:21:19 -06:00
|
|
|
</template>-->
|
2022-04-12 18:40:35 -05:00
|
|
|
|
2024-11-13 17:25:26 -06:00
|
|
|
<p v-if="publishedAt" class="text-xs text-fg-muted mb-1">{{ $getString('LabelPublishedDate', [$formatDate(publishedAt, 'MMM do, yyyy')]) }}</p>
|
2022-04-10 20:31:47 -05:00
|
|
|
|
2023-12-16 17:21:19 -06:00
|
|
|
<p class="text-sm font-semibold">{{ title }}</p>
|
2023-02-25 16:33:06 -06:00
|
|
|
|
2023-12-10 17:53:27 -06:00
|
|
|
<p class="text-sm text-fg episode-subtitle mt-1.5 mb-0.5" v-html="subtitle" />
|
2023-05-19 17:57:36 -05:00
|
|
|
|
|
|
|
<div v-if="episodeNumber || season || episodeType" class="flex py-2 items-center -mx-0.5">
|
2023-12-10 17:53:27 -06:00
|
|
|
<div v-if="episodeNumber" class="px-2 pt-px pb-0.5 mx-0.5 bg-primary bg-opacity-50 rounded-full text-xs font-light text-fg">Episode #{{ episodeNumber }}</div>
|
|
|
|
<div v-if="season" class="px-2 pt-px pb-0.5 mx-0.5 bg-primary bg-opacity-50 rounded-full text-xs font-light text-fg">Season #{{ season }}</div>
|
2023-12-16 17:21:19 -06:00
|
|
|
<div v-if="episodeType" class="px-2 pt-px pb-0.5 mx-0.5 bg-primary bg-opacity-50 rounded-full text-xs font-light text-fg capitalize">{{ episodeType }}</div>
|
2023-05-19 17:57:36 -05:00
|
|
|
</div>
|
2022-07-02 14:33:53 -05:00
|
|
|
|
2022-04-15 20:48:39 -05:00
|
|
|
<div class="flex items-center pt-2">
|
2023-12-10 17:53:27 -06:00
|
|
|
<div class="h-8 px-4 border border-border rounded-full flex items-center justify-center cursor-pointer" :class="userIsFinished ? 'text-white text-opacity-40' : ''" @click.stop="playClick">
|
2023-12-15 17:35:37 -06:00
|
|
|
<span v-if="!playerIsStartingForThisMedia" class="material-icons" :class="streamIsPlaying ? '' : 'text-success'">{{ streamIsPlaying ? 'pause' : 'play_arrow' }}</span>
|
|
|
|
<svg v-else class="animate-spin" style="width: 24px; height: 24px" viewBox="0 0 24 24">
|
|
|
|
<path fill="currentColor" d="M12,4V2A10,10 0 0,0 2,12H4A8,8 0 0,1 12,4Z" />
|
|
|
|
</svg>
|
2022-04-15 20:48:39 -05:00
|
|
|
<p class="pl-2 pr-1 text-sm font-semibold">{{ timeRemaining }}</p>
|
2022-04-10 20:31:47 -05:00
|
|
|
</div>
|
2022-04-15 20:48:39 -05:00
|
|
|
|
|
|
|
<ui-read-icon-btn :disabled="isProcessingReadUpdate" :is-read="userIsFinished" borderless class="mx-1 mt-0.5" @click="toggleFinished" />
|
|
|
|
|
2023-02-25 16:33:06 -06:00
|
|
|
<button v-if="!isLocal" class="mx-1.5 mt-1.5" @click.stop="addToPlaylist">
|
2022-12-03 17:05:43 -06:00
|
|
|
<span class="material-icons text-2xl">playlist_add</span>
|
|
|
|
</button>
|
|
|
|
|
2022-08-10 23:20:56 -04:00
|
|
|
<div v-if="userCanDownload">
|
2022-04-28 17:13:21 -04:00
|
|
|
<span v-if="isLocal" class="material-icons-outlined px-2 text-success text-lg">audio_file</span>
|
2024-11-13 17:25:26 -06:00
|
|
|
<span v-else-if="!localEpisode" class="material-icons mx-1.5 mt-2 text-xl" :class="downloadItem || startingDownload ? 'animate-bounce text-warning text-opacity-75' : ''" @click.stop="downloadClick">{{ downloadItem || startingDownload ? 'downloading' : 'download' }}</span>
|
2022-04-28 17:13:21 -04:00
|
|
|
<span v-else class="material-icons px-2 text-success text-xl">download_done</span>
|
|
|
|
</div>
|
2022-12-10 10:29:56 -06:00
|
|
|
|
|
|
|
<div class="flex-grow" />
|
2022-04-10 20:31:47 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2022-12-10 10:29:56 -06:00
|
|
|
<div v-if="processing" class="absolute top-0 left-0 w-full h-full bg-black bg-opacity-30 flex items-center justify-center">
|
|
|
|
<widgets-loading-spinner size="la-lg" />
|
|
|
|
</div>
|
|
|
|
|
2022-04-10 20:31:47 -05:00
|
|
|
<div v-if="!userIsFinished" class="absolute bottom-0 left-0 h-0.5 bg-warning" :style="{ width: itemProgressPercent * 100 + '%' }" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-05-22 15:56:32 -05:00
|
|
|
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
2024-05-26 22:08:53 +01:00
|
|
|
import cellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
|
2022-04-10 20:31:47 -05:00
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
libraryItemId: String,
|
|
|
|
episode: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
2022-04-15 20:48:39 -05:00
|
|
|
},
|
|
|
|
localLibraryItemId: String,
|
|
|
|
localEpisode: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
|
|
|
},
|
|
|
|
isLocal: Boolean
|
2022-04-10 20:31:47 -05:00
|
|
|
},
|
2024-05-26 22:08:53 +01:00
|
|
|
mixins: [cellularPermissionHelpers],
|
2022-04-10 20:31:47 -05:00
|
|
|
data() {
|
|
|
|
return {
|
2022-12-10 10:29:56 -06:00
|
|
|
isProcessingReadUpdate: false,
|
2023-12-16 17:21:19 -06:00
|
|
|
processing: false,
|
|
|
|
startingDownload: false
|
2022-04-10 20:31:47 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-04-28 17:13:21 -04:00
|
|
|
isIos() {
|
|
|
|
return this.$platform === 'ios'
|
|
|
|
},
|
2022-04-10 20:31:47 -05:00
|
|
|
mediaType() {
|
|
|
|
return 'podcast'
|
|
|
|
},
|
2022-05-22 15:49:42 -05:00
|
|
|
userCanDownload() {
|
|
|
|
return this.$store.getters['user/getUserCanDownload']
|
|
|
|
},
|
2022-04-10 20:31:47 -05:00
|
|
|
audioFile() {
|
|
|
|
return this.episode.audioFile
|
|
|
|
},
|
|
|
|
title() {
|
|
|
|
return this.episode.title || ''
|
|
|
|
},
|
2023-02-25 16:33:06 -06:00
|
|
|
subtitle() {
|
2023-05-19 17:57:36 -05:00
|
|
|
return this.episode.subtitle || this.episode.description || ''
|
|
|
|
},
|
|
|
|
episodeNumber() {
|
|
|
|
return this.episode.episode
|
|
|
|
},
|
|
|
|
season() {
|
|
|
|
return this.episode.season
|
|
|
|
},
|
|
|
|
episodeType() {
|
|
|
|
if (this.episode.episodeType === 'full') return null // only show Trailer/Bonus
|
|
|
|
return this.episode.episodeType
|
2022-04-10 20:31:47 -05:00
|
|
|
},
|
|
|
|
duration() {
|
|
|
|
return this.$secondsToTimestamp(this.episode.duration)
|
|
|
|
},
|
|
|
|
isStreaming() {
|
2023-06-19 12:37:44 -05:00
|
|
|
return this.$store.getters['getIsMediaStreaming'](this.libraryItemId, this.episode.id)
|
2022-04-15 20:48:39 -05:00
|
|
|
},
|
2022-04-10 20:31:47 -05:00
|
|
|
streamIsPlaying() {
|
|
|
|
return this.$store.state.playerIsPlaying && this.isStreaming
|
|
|
|
},
|
2023-12-15 17:35:37 -06:00
|
|
|
playerIsStartingPlayback() {
|
|
|
|
// Play has been pressed and waiting for native play response
|
|
|
|
return this.$store.state.playerIsStartingPlayback
|
|
|
|
},
|
|
|
|
playerIsStartingForThisMedia() {
|
|
|
|
const mediaId = this.$store.state.playerStartingPlaybackMediaId
|
2023-12-18 17:05:34 -06:00
|
|
|
if (!mediaId) return false
|
|
|
|
|
2023-12-15 17:35:37 -06:00
|
|
|
return mediaId === this.episode?.id
|
|
|
|
},
|
2022-04-10 20:31:47 -05:00
|
|
|
itemProgress() {
|
|
|
|
if (this.isLocal) return this.$store.getters['globals/getLocalMediaProgressById'](this.libraryItemId, this.episode.id)
|
|
|
|
return this.$store.getters['user/getUserMediaProgress'](this.libraryItemId, this.episode.id)
|
|
|
|
},
|
2022-04-15 20:48:39 -05:00
|
|
|
localMediaProgress() {
|
|
|
|
if (this.isLocal) return this.$store.getters['globals/getLocalMediaProgressById'](this.libraryItemId, this.episode.id)
|
|
|
|
else if (this.localLibraryItemId && this.localEpisode) {
|
|
|
|
return this.$store.getters['globals/getLocalMediaProgressById'](this.localLibraryItemId, this.localEpisode.id)
|
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
},
|
2022-04-10 20:31:47 -05:00
|
|
|
itemProgressPercent() {
|
2023-11-25 12:56:29 -06:00
|
|
|
return this.itemProgress?.progress || 0
|
2022-04-10 20:31:47 -05:00
|
|
|
},
|
|
|
|
userIsFinished() {
|
2023-11-25 12:56:29 -06:00
|
|
|
return !!this.itemProgress?.isFinished
|
2022-04-10 20:31:47 -05:00
|
|
|
},
|
|
|
|
timeRemaining() {
|
|
|
|
if (this.streamIsPlaying) return 'Playing'
|
|
|
|
if (!this.itemProgressPercent) return this.$elapsedPretty(this.episode.duration)
|
|
|
|
if (this.userIsFinished) return 'Finished'
|
|
|
|
var remaining = Math.floor(this.itemProgress.duration - this.itemProgress.currentTime)
|
|
|
|
return `${this.$elapsedPretty(remaining)} left`
|
|
|
|
},
|
|
|
|
publishedAt() {
|
|
|
|
return this.episode.publishedAt
|
|
|
|
},
|
|
|
|
downloadItem() {
|
|
|
|
return this.$store.getters['globals/getDownloadItem'](this.libraryItemId, this.episode.id)
|
2022-04-15 20:48:39 -05:00
|
|
|
},
|
|
|
|
localEpisodeId() {
|
2023-11-25 12:56:29 -06:00
|
|
|
return this.localEpisode?.id || null
|
2022-04-10 20:31:47 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2023-02-25 16:33:06 -06:00
|
|
|
goToEpisodePage() {
|
|
|
|
this.$router.push(`/item/${this.libraryItemId}/${this.episode.id}`)
|
2022-12-10 10:29:56 -06:00
|
|
|
},
|
2022-12-03 17:05:43 -06:00
|
|
|
addToPlaylist() {
|
|
|
|
this.$emit('addToPlaylist', this.episode)
|
|
|
|
},
|
2022-05-22 15:56:32 -05:00
|
|
|
async selectFolder() {
|
|
|
|
var folderObj = await AbsFileSystem.selectFolder({ mediaType: this.mediaType })
|
|
|
|
if (folderObj.error) {
|
|
|
|
return this.$toast.error(`Error: ${folderObj.error || 'Unknown Error'}`)
|
|
|
|
}
|
|
|
|
return folderObj
|
2022-04-10 20:31:47 -05:00
|
|
|
},
|
2022-12-08 00:28:28 -05:00
|
|
|
async downloadClick() {
|
2023-12-16 17:21:19 -06:00
|
|
|
if (this.downloadItem || this.startingDownload) return
|
|
|
|
|
2024-05-26 22:08:53 +01:00
|
|
|
const hasPermission = await this.checkCellularPermission('download')
|
|
|
|
if (!hasPermission) return
|
|
|
|
|
2023-12-16 17:21:19 -06:00
|
|
|
this.startingDownload = true
|
|
|
|
setTimeout(() => {
|
|
|
|
this.startingDownload = false
|
|
|
|
}, 1000)
|
|
|
|
|
2023-01-08 15:32:15 -06:00
|
|
|
await this.$hapticsImpact()
|
2022-08-10 23:20:56 -04:00
|
|
|
if (this.isIos) {
|
|
|
|
// no local folders on iOS
|
|
|
|
this.startDownload()
|
|
|
|
} else {
|
|
|
|
this.download()
|
|
|
|
}
|
2022-04-10 20:31:47 -05:00
|
|
|
},
|
|
|
|
async download(selectedLocalFolder = null) {
|
2023-06-04 14:59:55 -05:00
|
|
|
let localFolder = selectedLocalFolder
|
2022-04-10 20:31:47 -05:00
|
|
|
if (!localFolder) {
|
2023-06-04 14:59:55 -05:00
|
|
|
const localFolders = (await this.$db.getLocalFolders()) || []
|
2022-04-10 20:31:47 -05:00
|
|
|
console.log('Local folders loaded', localFolders.length)
|
2023-06-04 14:59:55 -05:00
|
|
|
const foldersWithMediaType = localFolders.filter((lf) => {
|
2022-04-10 20:31:47 -05:00
|
|
|
console.log('Checking local folder', lf.mediaType)
|
|
|
|
return lf.mediaType == this.mediaType
|
|
|
|
})
|
|
|
|
console.log('Folders with media type', this.mediaType, foldersWithMediaType.length)
|
2023-06-04 14:59:55 -05:00
|
|
|
const internalStorageFolder = foldersWithMediaType.find((f) => f.id === `internal-${this.mediaType}`)
|
2022-04-10 20:31:47 -05:00
|
|
|
if (!foldersWithMediaType.length) {
|
2023-06-04 14:59:55 -05:00
|
|
|
localFolder = {
|
|
|
|
id: `internal-${this.mediaType}`,
|
|
|
|
name: 'Internal App Storage',
|
|
|
|
mediaType: this.mediaType
|
|
|
|
}
|
|
|
|
} else if (foldersWithMediaType.length === 1 && internalStorageFolder) {
|
|
|
|
localFolder = internalStorageFolder
|
2022-04-10 20:31:47 -05:00
|
|
|
} else {
|
2023-06-04 14:59:55 -05:00
|
|
|
this.$store.commit('globals/showSelectLocalFolderModal', {
|
|
|
|
mediaType: this.mediaType,
|
|
|
|
callback: (folder) => {
|
|
|
|
this.download(folder)
|
|
|
|
}
|
|
|
|
})
|
2022-04-10 20:31:47 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Local folder', JSON.stringify(localFolder))
|
|
|
|
|
2023-12-08 07:30:54 +00:00
|
|
|
this.startDownload(localFolder)
|
2022-04-10 20:31:47 -05:00
|
|
|
},
|
|
|
|
async startDownload(localFolder) {
|
2022-08-10 23:20:56 -04:00
|
|
|
var payload = {
|
|
|
|
libraryItemId: this.libraryItemId,
|
2022-08-11 11:20:29 -04:00
|
|
|
episodeId: this.episode.id
|
2022-08-10 23:20:56 -04:00
|
|
|
}
|
|
|
|
if (localFolder) {
|
2022-08-21 18:03:27 -05:00
|
|
|
payload.localFolderId = localFolder.id
|
2022-08-10 23:20:56 -04:00
|
|
|
}
|
|
|
|
var downloadRes = await AbsDownloader.downloadLibraryItem(payload)
|
2022-04-10 20:31:47 -05:00
|
|
|
if (downloadRes && downloadRes.error) {
|
|
|
|
var errorMsg = downloadRes.error || 'Unknown error'
|
|
|
|
console.error('Download error', errorMsg)
|
|
|
|
this.$toast.error(errorMsg)
|
|
|
|
}
|
|
|
|
},
|
2022-12-08 00:28:28 -05:00
|
|
|
async playClick() {
|
2023-12-15 17:35:37 -06:00
|
|
|
if (this.playerIsStartingPlayback) return
|
|
|
|
|
2023-01-08 15:32:15 -06:00
|
|
|
await this.$hapticsImpact()
|
2022-04-10 20:31:47 -05:00
|
|
|
if (this.streamIsPlaying) {
|
|
|
|
this.$eventBus.$emit('pause-item')
|
|
|
|
} else {
|
2023-12-15 17:35:37 -06:00
|
|
|
this.$store.commit('setPlayerIsStartingPlayback', this.episode.id)
|
|
|
|
|
2022-04-15 20:48:39 -05:00
|
|
|
if (this.localEpisode && this.localLibraryItemId) {
|
|
|
|
console.log('Play local episode', this.localEpisode.id, this.localLibraryItemId)
|
|
|
|
|
|
|
|
this.$eventBus.$emit('play-item', {
|
|
|
|
libraryItemId: this.localLibraryItemId,
|
2022-08-11 17:36:27 -05:00
|
|
|
episodeId: this.localEpisode.id,
|
|
|
|
serverLibraryItemId: this.libraryItemId,
|
|
|
|
serverEpisodeId: this.episode.id
|
2022-04-15 20:48:39 -05:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.$eventBus.$emit('play-item', {
|
|
|
|
libraryItemId: this.libraryItemId,
|
|
|
|
episodeId: this.episode.id
|
|
|
|
})
|
|
|
|
}
|
2022-04-10 20:31:47 -05:00
|
|
|
}
|
|
|
|
},
|
2022-04-15 20:48:39 -05:00
|
|
|
async toggleFinished() {
|
2023-01-08 15:32:15 -06:00
|
|
|
await this.$hapticsImpact()
|
2023-06-18 14:26:04 -05:00
|
|
|
|
2022-04-10 20:31:47 -05:00
|
|
|
this.isProcessingReadUpdate = true
|
2022-04-15 20:48:39 -05:00
|
|
|
if (this.isLocal || this.localEpisode) {
|
2023-06-18 14:26:04 -05:00
|
|
|
const isFinished = !this.userIsFinished
|
|
|
|
const localLibraryItemId = this.isLocal ? this.libraryItemId : this.localLibraryItemId
|
|
|
|
const localEpisodeId = this.isLocal ? this.episode.id : this.localEpisode.id
|
|
|
|
const payload = await this.$db.updateLocalMediaProgressFinished({ localLibraryItemId, localEpisodeId, isFinished })
|
2022-04-15 20:48:39 -05:00
|
|
|
console.log('toggleFinished payload', JSON.stringify(payload))
|
2023-06-18 14:26:04 -05:00
|
|
|
if (payload?.error) {
|
|
|
|
this.$toast.error(payload?.error || 'Unknown error')
|
2022-04-15 20:48:39 -05:00
|
|
|
} else {
|
2023-06-18 14:26:04 -05:00
|
|
|
const localMediaProgress = payload.localMediaProgress
|
2022-04-15 20:48:39 -05:00
|
|
|
console.log('toggleFinished localMediaProgress', JSON.stringify(localMediaProgress))
|
|
|
|
if (localMediaProgress) {
|
|
|
|
this.$store.commit('globals/updateLocalMediaProgress', localMediaProgress)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.isProcessingReadUpdate = false
|
|
|
|
} else {
|
2023-06-18 14:26:04 -05:00
|
|
|
const updatePayload = {
|
2022-04-15 20:48:39 -05:00
|
|
|
isFinished: !this.userIsFinished
|
|
|
|
}
|
2023-09-17 12:43:50 -05:00
|
|
|
this.$nativeHttp
|
|
|
|
.patch(`/api/me/progress/${this.libraryItemId}/${this.episode.id}`, updatePayload)
|
2022-04-15 20:48:39 -05:00
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
|
|
|
this.$toast.error(`Failed to mark as ${updatePayload.isFinished ? 'Finished' : 'Not Finished'}`)
|
|
|
|
})
|
2023-06-18 14:26:04 -05:00
|
|
|
.finally(() => {
|
|
|
|
this.isProcessingReadUpdate = false
|
|
|
|
})
|
2022-04-15 20:48:39 -05:00
|
|
|
}
|
2022-04-10 20:31:47 -05:00
|
|
|
}
|
2022-04-15 20:48:39 -05:00
|
|
|
}
|
2022-04-10 20:31:47 -05:00
|
|
|
}
|
2022-12-08 00:28:28 -05:00
|
|
|
</script>
|