2022-03-07 02:02:06 +01:00
|
|
|
<template>
|
2022-03-14 01:34:31 +01:00
|
|
|
<div class="page" :class="streamLibraryItem ? 'streaming' : ''">
|
2022-05-14 00:40:43 +02:00
|
|
|
<app-book-shelf-toolbar page="podcast-search" />
|
|
|
|
<div class="w-full h-full overflow-y-auto p-12 relative">
|
|
|
|
<div class="w-full max-w-3xl mx-auto">
|
|
|
|
<form @submit.prevent="submit" class="flex">
|
|
|
|
<ui-text-input v-model="searchInput" :disabled="processing" placeholder="Enter search term or RSS feed URL" class="flex-grow mr-2" />
|
|
|
|
<ui-btn type="submit" :disabled="processing">Submit</ui-btn>
|
|
|
|
</form>
|
|
|
|
</div>
|
2022-03-07 02:02:06 +01:00
|
|
|
|
2022-05-14 00:40:43 +02:00
|
|
|
<div class="w-full max-w-3xl mx-auto py-4">
|
|
|
|
<p v-if="termSearched && !results.length && !processing" class="text-center text-xl">No podcasts found</p>
|
|
|
|
<template v-for="podcast in results">
|
|
|
|
<div :key="podcast.id" class="flex p-1 hover:bg-primary hover:bg-opacity-25 cursor-pointer" @click="selectPodcast(podcast)">
|
|
|
|
<div class="w-24 min-w-24 h-24 bg-primary">
|
|
|
|
<img v-if="podcast.cover" :src="podcast.cover" class="h-full w-full" />
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow pl-4 max-w-2xl">
|
|
|
|
<a :href="podcast.pageUrl" class="text-lg text-gray-200 hover:underline" target="_blank" @click.stop>{{ podcast.title }}</a>
|
|
|
|
<p class="text-base text-gray-300 whitespace-nowrap truncate">by {{ podcast.artistName }}</p>
|
|
|
|
<p class="text-xs text-gray-400 leading-5">{{ podcast.genres.join(', ') }}</p>
|
|
|
|
<p class="text-xs text-gray-400 leading-5">{{ podcast.trackCount }} Episodes</p>
|
|
|
|
</div>
|
2022-03-07 02:02:06 +01:00
|
|
|
</div>
|
2022-05-14 00:40:43 +02:00
|
|
|
</template>
|
|
|
|
</div>
|
2022-03-07 02:02:06 +01:00
|
|
|
|
2022-05-14 00:40:43 +02:00
|
|
|
<div v-show="processing" class="absolute top-0 left-0 w-full h-full flex items-center justify-center bg-black bg-opacity-25 z-40">
|
|
|
|
<ui-loading-indicator />
|
2022-03-07 02:02:06 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-19 01:16:54 +01:00
|
|
|
|
|
|
|
<modals-podcast-new-modal v-model="showNewPodcastModal" :podcast-data="selectedPodcast" :podcast-feed-data="selectedPodcastFeed" />
|
2022-03-07 02:02:06 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2022-03-22 01:24:38 +01:00
|
|
|
async asyncData({ params, query, store, app, redirect }) {
|
|
|
|
var libraryId = params.library
|
2022-04-14 19:57:34 +02:00
|
|
|
var libraryData = await store.dispatch('libraries/fetch', libraryId)
|
|
|
|
if (!libraryData) {
|
2022-03-22 01:24:38 +01:00
|
|
|
return redirect('/oops?message=Library not found')
|
|
|
|
}
|
2022-04-14 19:57:34 +02:00
|
|
|
|
|
|
|
// Redirect book libraries
|
|
|
|
const library = libraryData.library
|
|
|
|
if (library.mediaType === 'book') {
|
|
|
|
return redirect(`/library/${libraryId}`)
|
|
|
|
}
|
|
|
|
|
2022-03-22 01:24:38 +01:00
|
|
|
return {
|
|
|
|
libraryId
|
|
|
|
}
|
|
|
|
},
|
2022-03-07 02:02:06 +01:00
|
|
|
data() {
|
|
|
|
return {
|
2022-04-13 23:55:48 +02:00
|
|
|
searchInput: '',
|
2022-03-07 02:02:06 +01:00
|
|
|
results: [],
|
|
|
|
termSearched: '',
|
2022-03-19 01:16:54 +01:00
|
|
|
processing: false,
|
|
|
|
showNewPodcastModal: false,
|
|
|
|
selectedPodcast: null,
|
|
|
|
selectedPodcastFeed: null
|
2022-03-07 02:02:06 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-03-14 01:34:31 +01:00
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
2022-03-07 02:02:06 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-04-13 23:55:48 +02:00
|
|
|
submit() {
|
|
|
|
if (!this.searchInput) return
|
|
|
|
|
|
|
|
if (this.searchInput.startsWith('http:') || this.searchInput.startsWith('https:')) {
|
|
|
|
this.termSearched = ''
|
|
|
|
this.results = []
|
|
|
|
this.checkRSSFeed(this.searchInput)
|
|
|
|
} else {
|
|
|
|
this.submitSearch(this.searchInput)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async checkRSSFeed(rssFeed) {
|
|
|
|
this.processing = true
|
|
|
|
var payload = await this.$axios.$post(`/api/podcasts/feed`, { rssFeed }).catch((error) => {
|
|
|
|
console.error('Failed to get feed', error)
|
|
|
|
this.$toast.error('Failed to get podcast feed')
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
this.processing = false
|
|
|
|
if (!payload) return
|
|
|
|
|
|
|
|
this.selectedPodcastFeed = payload.podcast
|
|
|
|
this.selectedPodcast = null
|
|
|
|
this.showNewPodcastModal = true
|
|
|
|
},
|
|
|
|
async submitSearch(term) {
|
2022-03-07 02:02:06 +01:00
|
|
|
this.processing = true
|
|
|
|
this.termSearched = ''
|
2022-04-13 23:55:48 +02:00
|
|
|
var results = await this.$axios.$get(`/api/search/podcast?term=${encodeURIComponent(term)}`).catch((error) => {
|
2022-03-07 02:02:06 +01:00
|
|
|
console.error('Search request failed', error)
|
|
|
|
return []
|
|
|
|
})
|
|
|
|
console.log('Got results', results)
|
|
|
|
this.results = results
|
|
|
|
this.termSearched = term
|
|
|
|
this.processing = false
|
|
|
|
},
|
|
|
|
async selectPodcast(podcast) {
|
|
|
|
console.log('Selected podcast', podcast)
|
|
|
|
if (!podcast.feedUrl) {
|
|
|
|
this.$toast.error('Invalid podcast - no feed')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.processing = true
|
2022-04-13 23:55:48 +02:00
|
|
|
var payload = await this.$axios.$post(`/api/podcasts/feed`, { rssFeed: podcast.feedUrl }).catch((error) => {
|
2022-03-07 02:02:06 +01:00
|
|
|
console.error('Failed to get feed', error)
|
|
|
|
this.$toast.error('Failed to get podcast feed')
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
this.processing = false
|
2022-04-13 23:55:48 +02:00
|
|
|
if (!payload) return
|
|
|
|
|
|
|
|
this.selectedPodcastFeed = payload.podcast
|
2022-03-19 01:16:54 +01:00
|
|
|
this.selectedPodcast = podcast
|
|
|
|
this.showNewPodcastModal = true
|
2022-04-13 23:55:48 +02:00
|
|
|
console.log('Got podcast feed', payload.podcast)
|
2022-03-07 02:02:06 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|