Update podcast search page to support manually entering podcast RSS feed

This commit is contained in:
advplyr 2022-04-13 16:55:48 -05:00
parent 2c6e1cc2b5
commit 4edba20e9e
6 changed files with 87 additions and 37 deletions

View file

@ -56,7 +56,6 @@
<p class="break-words mb-1">{{ episode.title }}</p>
<p v-if="episode.subtitle" class="break-words mb-1 text-sm text-gray-300 episode-subtitle">{{ episode.subtitle }}</p>
<p class="text-xs text-gray-300">Published {{ episode.publishedAt ? $dateDistanceFromNow(episode.publishedAt) : 'Unknown' }}</p>
<!-- <span class="material-icons cursor-pointer text-lg hover:text-success" @click="saveEpisode(episode)">save</span> -->
</div>
</div>
</div>
@ -246,17 +245,15 @@ export default {
this.$toast.error(errorMsg)
})
},
saveEpisode(episode) {
console.log('Save episode', episode)
},
init() {
this.podcast.title = this._podcastData.title
this.podcast.author = this._podcastData.artistName || ''
this.podcast.description = this._podcastData.description || this.feedMetadata.description || ''
// Prefer using itunes podcast data but not always passed in if manually entering rss feed
this.podcast.title = this._podcastData.title || this.feedMetadata.title || ''
this.podcast.author = this._podcastData.artistName || this.feedMetadata.author || ''
this.podcast.description = this._podcastData.description || this.feedMetadata.descriptionPlain || ''
this.podcast.releaseDate = this._podcastData.releaseDate || ''
this.podcast.genres = this._podcastData.genres || []
this.podcast.feedUrl = this._podcastData.feedUrl
this.podcast.imageUrl = this._podcastData.cover || ''
this.podcast.genres = this._podcastData.genres || this.feedMetadata.categories || []
this.podcast.feedUrl = this._podcastData.feedUrl || this.feedMetadata.feedUrl || ''
this.podcast.imageUrl = this._podcastData.cover || this.feedMetadata.image || ''
this.podcast.itunesPageUrl = this._podcastData.pageUrl || ''
this.podcast.itunesId = this._podcastData.id || ''
this.podcast.itunesArtistId = this._podcastData.artistId || ''

View file

@ -342,15 +342,16 @@ export default {
return this.$toast.error('Podcast does not have an RSS Feed')
}
this.fetchingRSSFeed = true
var podcastfeed = await this.$axios.$post(`/api/podcasts/feed`, { rssFeed: this.mediaMetadata.feedUrl }).catch((error) => {
var payload = await this.$axios.$post(`/api/podcasts/feed`, { rssFeed: this.mediaMetadata.feedUrl }).catch((error) => {
console.error('Failed to get feed', error)
this.$toast.error('Failed to get podcast feed')
return null
})
this.fetchingRSSFeed = false
if (!podcastfeed) return
if (!payload) return
console.log('Podcast feed', podcastfeed)
console.log('Podcast feed', payload)
const podcastfeed = payload.podcast
if (!podcastfeed.episodes || !podcastfeed.episodes.length) {
this.$toast.info('No episodes found in RSS feed')
return

View file

@ -6,9 +6,9 @@
<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="submitSearch" class="flex">
<ui-text-input v-model="searchTerm" :disabled="processing" placeholder="Search term" class="flex-grow mr-2" />
<ui-btn type="submit" :disabled="processing">Search Podcasts</ui-btn>
<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>
@ -54,11 +54,10 @@ export default {
},
data() {
return {
searchTerm: '',
searchInput: '',
results: [],
termSearched: '',
processing: false,
showNewPodcastModal: false,
selectedPodcast: null,
selectedPodcastFeed: null
@ -70,13 +69,35 @@ export default {
}
},
methods: {
async submitSearch() {
if (!this.searchTerm) return
console.log('Searching', this.searchTerm)
var term = this.searchTerm
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) {
this.processing = true
this.termSearched = ''
var results = await this.$axios.$get(`/api/search/podcast?term=${encodeURIComponent(this.searchTerm)}`).catch((error) => {
var results = await this.$axios.$get(`/api/search/podcast?term=${encodeURIComponent(term)}`).catch((error) => {
console.error('Search request failed', error)
return []
})
@ -92,17 +113,18 @@ export default {
return
}
this.processing = true
var podcastfeed = await this.$axios.$post(`/api/podcasts/feed`, { rssFeed: podcast.feedUrl }).catch((error) => {
var payload = await this.$axios.$post(`/api/podcasts/feed`, { rssFeed: podcast.feedUrl }).catch((error) => {
console.error('Failed to get feed', error)
this.$toast.error('Failed to get podcast feed')
return null
})
this.processing = false
if (!podcastfeed) return
this.selectedPodcastFeed = podcastfeed
if (!payload) return
this.selectedPodcastFeed = payload.podcast
this.selectedPodcast = podcast
this.showNewPodcastModal = true
console.log('Got podcast feed', podcastfeed)
console.log('Got podcast feed', payload.podcast)
}
},
mounted() {}