2022-03-27 22:37:04 +02:00
|
|
|
<template>
|
|
|
|
<modals-modal v-model="show" name="podcast-episodes-modal" :width="1200" :height="'unset'" :processing="processing">
|
|
|
|
<template #outer>
|
|
|
|
<div class="absolute top-0 left-0 p-5 w-2/3 overflow-hidden">
|
2023-02-11 22:02:56 +01:00
|
|
|
<p class="text-3xl text-white truncate">{{ title }}</p>
|
2022-03-27 22:37:04 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<div ref="wrapper" id="podcast-wrapper" class="p-4 w-full text-sm py-2 rounded-lg bg-bg shadow-lg border border-black-300 relative overflow-hidden">
|
2023-04-21 00:51:06 +02:00
|
|
|
<div v-if="episodesCleaned.length" class="w-full py-3 mx-auto flex">
|
2023-02-19 21:07:32 +01:00
|
|
|
<form @submit.prevent="submit" class="flex flex-grow">
|
2023-02-21 20:30:42 +01:00
|
|
|
<ui-text-input v-model="search" @input="inputUpdate" type="search" :placeholder="$strings.PlaceholderSearchEpisode" class="flex-grow mr-2 text-sm md:text-base" />
|
2023-02-19 21:07:32 +01:00
|
|
|
</form>
|
|
|
|
</div>
|
2022-03-27 22:37:04 +02:00
|
|
|
<div ref="episodeContainer" id="episodes-scroll" class="w-full overflow-x-hidden overflow-y-auto">
|
|
|
|
<div
|
2023-02-19 21:07:32 +01:00
|
|
|
v-for="(episode, index) in episodesList"
|
2022-03-27 22:37:04 +02:00
|
|
|
:key="index"
|
|
|
|
class="relative"
|
2023-10-17 00:47:44 +02:00
|
|
|
:class="getIsEpisodeDownloaded(episode) ? 'bg-primary bg-opacity-40' : selectedEpisodes[episode.cleanUrl] ? 'cursor-pointer bg-success bg-opacity-10' : index % 2 == 0 ? 'cursor-pointer bg-primary bg-opacity-25 hover:bg-opacity-40' : 'cursor-pointer bg-primary bg-opacity-5 hover:bg-opacity-25'"
|
2023-04-21 00:51:06 +02:00
|
|
|
@click="toggleSelectEpisode(episode)"
|
2022-03-27 22:37:04 +02:00
|
|
|
>
|
|
|
|
<div class="absolute top-0 left-0 h-full flex items-center p-2">
|
2023-10-17 00:47:44 +02:00
|
|
|
<span v-if="getIsEpisodeDownloaded(episode)" class="material-icons text-success text-xl">download_done</span>
|
2023-04-21 00:51:06 +02:00
|
|
|
<ui-checkbox v-else v-model="selectedEpisodes[episode.cleanUrl]" small checkbox-bg="primary" border-color="gray-600" />
|
2022-03-27 22:37:04 +02:00
|
|
|
</div>
|
|
|
|
<div class="px-8 py-2">
|
2023-02-27 03:56:07 +01:00
|
|
|
<div class="flex items-center font-semibold text-gray-200">
|
|
|
|
<div v-if="episode.season || episode.episode">#</div>
|
|
|
|
<div v-if="episode.season">{{ episode.season }}x</div>
|
|
|
|
<div v-if="episode.episode">{{ episode.episode }}</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex items-center mb-1">
|
|
|
|
<div class="break-words">{{ episode.title }}</div>
|
|
|
|
<widgets-podcast-type-indicator :type="episode.episodeType" />
|
|
|
|
</div>
|
2024-02-18 18:24:36 +01:00
|
|
|
<p v-if="episode.subtitle" class="mb-1 text-sm text-gray-300 line-clamp-2">{{ episode.subtitle }}</p>
|
2022-03-27 22:37:04 +02:00
|
|
|
<p class="text-xs text-gray-300">Published {{ episode.publishedAt ? $dateDistanceFromNow(episode.publishedAt) : 'Unknown' }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex justify-end pt-4">
|
2023-07-01 00:30:15 +02:00
|
|
|
<ui-checkbox v-if="!allDownloaded" v-model="selectAll" @input="toggleSelectAll" :label="selectAllLabel" small checkbox-bg="primary" border-color="gray-600" class="mx-8" />
|
2022-08-28 15:48:41 +02:00
|
|
|
<ui-btn v-if="!allDownloaded" :disabled="!episodesSelected.length" @click="submit">{{ buttonText }}</ui-btn>
|
|
|
|
<p v-else class="text-success text-base px-2 py-4">All episodes are downloaded</p>
|
2022-03-27 22:37:04 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</modals-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: Boolean,
|
|
|
|
libraryItem: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
|
|
|
},
|
|
|
|
episodes: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
processing: false,
|
2023-04-21 00:51:06 +02:00
|
|
|
episodesCleaned: [],
|
2022-08-28 15:48:41 +02:00
|
|
|
selectedEpisodes: {},
|
2023-02-19 21:07:32 +01:00
|
|
|
selectAll: false,
|
|
|
|
search: null,
|
|
|
|
searchTimeout: null,
|
2024-01-05 21:39:25 +01:00
|
|
|
searchText: null,
|
|
|
|
downloadedEpisodeGuidMap: {},
|
|
|
|
downloadedEpisodeUrlMap: {}
|
2022-03-27 22:37:04 +02:00
|
|
|
}
|
|
|
|
},
|
2022-04-10 18:01:50 +02:00
|
|
|
watch: {
|
|
|
|
show: {
|
|
|
|
immediate: true,
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) this.init()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-03-27 22:37:04 +02:00
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get() {
|
|
|
|
return this.value
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
title() {
|
|
|
|
if (!this.libraryItem) return ''
|
|
|
|
return this.libraryItem.media.metadata.title || 'Unknown'
|
|
|
|
},
|
2022-04-09 11:44:31 +02:00
|
|
|
allDownloaded() {
|
2023-10-28 22:54:19 +02:00
|
|
|
return !this.episodesCleaned.some((episode) => !this.getIsEpisodeDownloaded(episode))
|
2022-04-09 11:44:31 +02:00
|
|
|
},
|
2022-03-27 22:37:04 +02:00
|
|
|
episodesSelected() {
|
|
|
|
return Object.keys(this.selectedEpisodes).filter((key) => !!this.selectedEpisodes[key])
|
|
|
|
},
|
|
|
|
buttonText() {
|
2023-07-01 00:30:15 +02:00
|
|
|
if (!this.episodesSelected.length) return this.$strings.LabelNoEpisodesSelected
|
|
|
|
if (this.episodesSelected.length === 1) return `${this.$strings.LabelDownload} ${this.$strings.LabelEpisode.toLowerCase()}`
|
|
|
|
return this.$getString('LabelDownloadNEpisodes', [this.episodesSelected.length])
|
2022-03-27 22:37:04 +02:00
|
|
|
},
|
|
|
|
itemEpisodes() {
|
2023-10-17 00:47:44 +02:00
|
|
|
return this.libraryItem?.media.episodes || []
|
2023-02-19 21:07:32 +01:00
|
|
|
},
|
|
|
|
episodesList() {
|
2023-04-21 00:51:06 +02:00
|
|
|
return this.episodesCleaned.filter((episode) => {
|
2023-02-19 21:07:32 +01:00
|
|
|
if (!this.searchText) return true
|
2023-07-01 00:30:15 +02:00
|
|
|
return episode.title?.toLowerCase().includes(this.searchText) || episode.subtitle?.toLowerCase().includes(this.searchText)
|
2023-02-19 21:07:32 +01:00
|
|
|
})
|
2023-07-01 00:30:15 +02:00
|
|
|
},
|
|
|
|
selectAllLabel() {
|
|
|
|
if (this.episodesList.length === this.episodesCleaned.length) {
|
|
|
|
return this.$strings.LabelSelectAllEpisodes
|
|
|
|
}
|
2023-10-17 00:47:44 +02:00
|
|
|
const episodesNotDownloaded = this.episodesList.filter((ep) => !this.getIsEpisodeDownloaded(ep)).length
|
2023-07-01 00:30:15 +02:00
|
|
|
return this.$getString('LabelSelectEpisodesShowing', [episodesNotDownloaded])
|
2022-03-27 22:37:04 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2023-10-17 00:47:44 +02:00
|
|
|
getIsEpisodeDownloaded(episode) {
|
2024-01-05 21:39:25 +01:00
|
|
|
if (episode.guid && !!this.downloadedEpisodeGuidMap[episode.guid]) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (this.downloadedEpisodeUrlMap[episode.cleanUrl]) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2023-10-17 00:47:44 +02:00
|
|
|
},
|
2023-07-07 01:06:26 +02:00
|
|
|
/**
|
2023-10-17 00:47:44 +02:00
|
|
|
* UPDATE: As of v2.4.5 guid is used for matching existing downloaded episodes if it is found on the RSS feed.
|
|
|
|
* Fallback to checking the clean url
|
|
|
|
* @see https://github.com/advplyr/audiobookshelf/issues/2207
|
|
|
|
*
|
2023-07-07 01:06:26 +02:00
|
|
|
* RSS feed episode url is used for matching with existing downloaded episodes.
|
|
|
|
* Some RSS feeds include timestamps in the episode url (e.g. patreon) that can change on requests.
|
|
|
|
* These need to be removed in order to detect the same episode each time the feed is pulled.
|
|
|
|
*
|
|
|
|
* An RSS feed may include an `id` in the query string. In these cases we want to leave the `id`.
|
|
|
|
* @see https://github.com/advplyr/audiobookshelf/issues/1896
|
|
|
|
*
|
|
|
|
* @param {string} url - rss feed episode url
|
|
|
|
* @returns {string} rss feed episode url without dynamic query strings
|
|
|
|
*/
|
|
|
|
getCleanEpisodeUrl(url) {
|
|
|
|
let queryString = url.split('?')[1]
|
|
|
|
if (!queryString) return url
|
|
|
|
|
|
|
|
const searchParams = new URLSearchParams(queryString)
|
|
|
|
for (const p of Array.from(searchParams.keys())) {
|
|
|
|
if (p !== 'id') searchParams.delete(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!searchParams.toString()) return url
|
|
|
|
return `${url}?${searchParams.toString()}`
|
|
|
|
},
|
2023-02-19 21:07:32 +01:00
|
|
|
inputUpdate() {
|
|
|
|
clearTimeout(this.searchTimeout)
|
|
|
|
this.searchTimeout = setTimeout(() => {
|
2023-07-01 00:30:15 +02:00
|
|
|
if (!this.search?.trim()) {
|
2023-02-19 21:07:32 +01:00
|
|
|
this.searchText = ''
|
2023-07-01 00:30:15 +02:00
|
|
|
this.checkSetIsSelectedAll()
|
2023-02-19 21:07:32 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
this.searchText = this.search.toLowerCase().trim()
|
2023-07-01 00:30:15 +02:00
|
|
|
this.checkSetIsSelectedAll()
|
2023-02-19 21:07:32 +01:00
|
|
|
}, 500)
|
|
|
|
},
|
2022-08-28 15:48:41 +02:00
|
|
|
toggleSelectAll(val) {
|
2023-07-01 00:30:15 +02:00
|
|
|
for (const episode of this.episodesList) {
|
2023-10-17 00:47:44 +02:00
|
|
|
if (this.getIsEpisodeDownloaded(episode)) this.selectedEpisodes[episode.cleanUrl] = false
|
2023-04-21 00:51:06 +02:00
|
|
|
else this.$set(this.selectedEpisodes, episode.cleanUrl, val)
|
2022-08-28 15:48:41 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
checkSetIsSelectedAll() {
|
2023-07-01 00:30:15 +02:00
|
|
|
for (const episode of this.episodesList) {
|
2023-10-17 00:47:44 +02:00
|
|
|
if (!this.getIsEpisodeDownloaded(episode) && !this.selectedEpisodes[episode.cleanUrl]) {
|
2022-08-28 15:48:41 +02:00
|
|
|
this.selectAll = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.selectAll = true
|
2022-03-27 22:37:04 +02:00
|
|
|
},
|
2023-04-21 00:51:06 +02:00
|
|
|
toggleSelectEpisode(episode) {
|
2023-10-17 00:47:44 +02:00
|
|
|
if (this.getIsEpisodeDownloaded(episode)) return
|
2023-04-21 00:51:06 +02:00
|
|
|
this.$set(this.selectedEpisodes, episode.cleanUrl, !this.selectedEpisodes[episode.cleanUrl])
|
2022-08-28 15:48:41 +02:00
|
|
|
this.checkSetIsSelectedAll()
|
2022-08-28 14:22:51 +02:00
|
|
|
},
|
2022-03-27 22:37:04 +02:00
|
|
|
submit() {
|
2023-07-01 00:30:15 +02:00
|
|
|
let episodesToDownload = []
|
2022-03-27 22:37:04 +02:00
|
|
|
if (this.episodesSelected.length) {
|
2023-04-21 00:51:06 +02:00
|
|
|
episodesToDownload = this.episodesSelected.map((cleanUrl) => this.episodesCleaned.find((ep) => ep.cleanUrl == cleanUrl))
|
2022-03-27 22:37:04 +02:00
|
|
|
}
|
|
|
|
|
2023-07-01 00:30:15 +02:00
|
|
|
const payloadSize = JSON.stringify(episodesToDownload).length
|
|
|
|
const sizeInMb = payloadSize / 1024 / 1024
|
|
|
|
const sizeInMbPretty = sizeInMb.toFixed(2) + 'MB'
|
2022-04-24 02:41:06 +02:00
|
|
|
console.log('Request size', sizeInMb)
|
|
|
|
if (sizeInMb > 4.99) {
|
|
|
|
return this.$toast.error(`Request is too large (${sizeInMbPretty}) should be < 5Mb`)
|
|
|
|
}
|
2022-03-27 22:37:04 +02:00
|
|
|
|
|
|
|
this.processing = true
|
|
|
|
this.$axios
|
|
|
|
.$post(`/api/podcasts/${this.libraryItem.id}/download-episodes`, episodesToDownload)
|
|
|
|
.then(() => {
|
|
|
|
this.processing = false
|
|
|
|
this.$toast.success('Started downloading episodes')
|
|
|
|
this.show = false
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to download episodes', error)
|
|
|
|
this.processing = false
|
2023-07-01 00:30:15 +02:00
|
|
|
this.$toast.error(error.response?.data || 'Failed to download episodes')
|
2022-08-28 15:48:41 +02:00
|
|
|
|
|
|
|
this.selectedEpisodes = {}
|
|
|
|
this.selectAll = false
|
2022-03-27 22:37:04 +02:00
|
|
|
})
|
2022-04-10 18:01:50 +02:00
|
|
|
},
|
|
|
|
init() {
|
2024-01-05 21:39:25 +01:00
|
|
|
this.downloadedEpisodeGuidMap = {}
|
|
|
|
this.downloadedEpisodeUrlMap = {}
|
|
|
|
|
|
|
|
this.itemEpisodes.forEach((episode) => {
|
|
|
|
if (episode.guid) this.downloadedEpisodeGuidMap[episode.guid] = episode.id
|
|
|
|
if (episode.enclosure?.url) this.downloadedEpisodeUrlMap[this.getCleanEpisodeUrl(episode.enclosure.url)] = episode.id
|
|
|
|
})
|
|
|
|
|
2023-04-21 00:51:06 +02:00
|
|
|
this.episodesCleaned = this.episodes
|
|
|
|
.filter((ep) => ep.enclosure?.url)
|
|
|
|
.map((_ep) => {
|
|
|
|
return {
|
|
|
|
..._ep,
|
2023-07-07 01:06:26 +02:00
|
|
|
cleanUrl: this.getCleanEpisodeUrl(_ep.enclosure.url)
|
2023-04-21 00:51:06 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
this.episodesCleaned.sort((a, b) => (a.publishedAt < b.publishedAt ? 1 : -1))
|
2022-08-28 15:48:41 +02:00
|
|
|
this.selectAll = false
|
|
|
|
this.selectedEpisodes = {}
|
2022-03-27 22:37:04 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
#podcast-wrapper {
|
|
|
|
min-height: 400px;
|
|
|
|
max-height: 80vh;
|
|
|
|
}
|
|
|
|
#episodes-scroll {
|
|
|
|
max-height: calc(80vh - 200px);
|
|
|
|
}
|
2022-08-28 05:40:02 +02:00
|
|
|
</style>
|