Add Podcast match tab and find covers

This commit is contained in:
advplyr 2022-04-13 18:13:39 -05:00
parent 4edba20e9e
commit 3f6ed6dbf9
10 changed files with 113 additions and 20 deletions

View File

@ -4,7 +4,7 @@
<div class="h-24 bg-primary" :style="{ minWidth: 96 / bookCoverAspectRatio + 'px' }"> <div class="h-24 bg-primary" :style="{ minWidth: 96 / bookCoverAspectRatio + 'px' }">
<img v-if="selectedCover" :src="selectedCover" class="h-full w-full object-contain" /> <img v-if="selectedCover" :src="selectedCover" class="h-full w-full object-contain" />
</div> </div>
<div class="px-4 flex-grow"> <div v-if="!isPodcast" class="px-4 flex-grow">
<div class="flex items-center"> <div class="flex items-center">
<h1>{{ book.title }}</h1> <h1>{{ book.title }}</h1>
<div class="flex-grow" /> <div class="flex-grow" />
@ -15,6 +15,12 @@
<p class="text-gray-500 text-xs">{{ book.description }}</p> <p class="text-gray-500 text-xs">{{ book.description }}</p>
</div> </div>
</div> </div>
<div v-else class="px-4 flex-grow">
<h1>{{ book.title }}</h1>
<p class="text-base text-gray-300 whitespace-nowrap truncate">by {{ book.author }}</p>
<p class="text-xs text-gray-400 leading-5">{{ book.genres.join(', ') }}</p>
<p class="text-xs text-gray-400 leading-5">{{ book.trackCount }} Episodes</p>
</div>
</div> </div>
<div v-if="bookCovers.length > 1" class="flex"> <div v-if="bookCovers.length > 1" class="flex">
<template v-for="cover in bookCovers"> <template v-for="cover in bookCovers">
@ -33,6 +39,7 @@ export default {
type: Object, type: Object,
default: () => {} default: () => {}
}, },
isPodcast: Boolean,
bookCoverAspectRatio: Number bookCoverAspectRatio: Number
}, },
data() { data() {

View File

@ -116,19 +116,16 @@ export default {
userCanDownload() { userCanDownload() {
return this.$store.getters['user/getUserCanDownload'] return this.$store.getters['user/getUserCanDownload']
}, },
showExperimentalFeatures() {
return this.$store.state.showExperimentalFeatures
},
availableTabs() { availableTabs() {
if (!this.userCanUpdate && !this.userCanDownload) return [] if (!this.userCanUpdate && !this.userCanDownload) return []
return this.tabs.filter((tab) => { return this.tabs.filter((tab) => {
if (tab.id === 'download' && this.isMissing) return false if (tab.id === 'download' && this.isMissing) return false
if (this.mediaType == 'podcast' && (tab.id == 'match' || tab.id == 'chapters')) return false if (this.mediaType == 'podcast' && tab.id == 'chapters') return false
if (this.mediaType == 'book' && tab.id == 'episodes') return false if (this.mediaType == 'book' && tab.id == 'episodes') return false
if ((tab.id === 'download' || tab.id === 'files') && this.userCanDownload) return true if ((tab.id === 'download' || tab.id === 'files') && this.userCanDownload) return true
if (tab.id !== 'download' && tab.id !== 'files' && this.userCanUpdate) return true if (tab.id !== 'download' && tab.id !== 'files' && this.userCanUpdate) return true
if (tab.id === 'match' && this.userCanUpdate && this.showExperimentalFeatures) return true if (tab.id === 'match' && this.userCanUpdate) return true
return false return false
}) })
}, },

View File

@ -121,6 +121,7 @@ export default {
} }
}, },
providers() { providers() {
if (this.isPodcast) return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers return this.$store.state.scanners.providers
}, },
searchTitleLabel() { searchTitleLabel() {
@ -137,6 +138,12 @@ export default {
libraryItemId() { libraryItemId() {
return this.libraryItem ? this.libraryItem.id : null return this.libraryItem ? this.libraryItem.id : null
}, },
mediaType() {
return this.libraryItem ? this.libraryItem.mediaType : null
},
isPodcast() {
return this.mediaType == 'podcast'
},
media() { media() {
return this.libraryItem ? this.libraryItem.media || {} : {} return this.libraryItem ? this.libraryItem.media || {} : {}
}, },
@ -212,7 +219,8 @@ export default {
this.imageUrl = this.media.coverPath || '' this.imageUrl = this.media.coverPath || ''
this.searchTitle = this.mediaMetadata.title || '' this.searchTitle = this.mediaMetadata.title || ''
this.searchAuthor = this.mediaMetadata.authorName || '' this.searchAuthor = this.mediaMetadata.authorName || ''
this.provider = localStorage.getItem('book-provider') || 'openlibrary' if (this.isPodcast) this.provider = 'itunes'
else this.provider = localStorage.getItem('book-provider') || 'google'
}, },
removeCover() { removeCover() {
if (!this.media.coverPath) { if (!this.media.coverPath) {
@ -278,6 +286,7 @@ export default {
getSearchQuery() { getSearchQuery() {
var searchQuery = `provider=${this.provider}&title=${this.searchTitle}` var searchQuery = `provider=${this.provider}&title=${this.searchTitle}`
if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}` if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}`
if (this.isPodcast) searchQuery += '&podcast=1'
return searchQuery return searchQuery
}, },
persistProvider() { persistProvider() {

View File

@ -7,14 +7,14 @@
<ui-btn :loading="checkingNewEpisodes" @click="checkForNewEpisodes">Check for new episodes</ui-btn> <ui-btn :loading="checkingNewEpisodes" @click="checkForNewEpisodes">Check for new episodes</ui-btn>
</div> --> </div> -->
<div class="w-full p-4 bg-primary"> <div v-if="episodes.length" class="w-full p-4 bg-primary">
<p>Podcast Episodes</p> <p>Podcast Episodes</p>
</div> </div>
<div v-if="!episodes.length" class="flex my-4 text-center justify-center text-xl">No Episodes</div> <div v-if="!episodes.length" class="flex my-4 text-center justify-center text-xl">No Episodes</div>
<table v-else class="text-sm tracksTable"> <table v-else class="text-sm tracksTable">
<tr class="font-book"> <tr class="font-book">
<th class="text-left">Sort #</th> <th class="text-left">Sort #</th>
<th class="text-left">Episode #</th> <th class="text-left whitespace-nowrap">Episode #</th>
<th class="text-left">Title</th> <th class="text-left">Title</th>
<th class="text-center w-28">Duration</th> <th class="text-center w-28">Duration</th>
<th class="text-center w-28">Size</th> <th class="text-center w-28">Size</th>

View File

@ -22,7 +22,7 @@
</div> </div>
<div v-show="!processing" class="w-full max-h-full overflow-y-auto overflow-x-hidden matchListWrapper"> <div v-show="!processing" class="w-full max-h-full overflow-y-auto overflow-x-hidden matchListWrapper">
<template v-for="(res, index) in searchResults"> <template v-for="(res, index) in searchResults">
<cards-book-match-card :key="index" :book="res" :book-cover-aspect-ratio="bookCoverAspectRatio" @select="selectMatch" /> <cards-book-match-card :key="index" :book="res" :is-podcast="isPodcast" :book-cover-aspect-ratio="bookCoverAspectRatio" @select="selectMatch" />
</template> </template>
</div> </div>
<div v-if="selectedMatch" class="absolute top-0 left-0 w-full bg-bg h-full p-8 max-h-full overflow-y-auto overflow-x-hidden"> <div v-if="selectedMatch" class="absolute top-0 left-0 w-full bg-bg h-full p-8 max-h-full overflow-y-auto overflow-x-hidden">
@ -109,6 +109,36 @@
<p v-if="mediaMetadata.asin" class="text-xs ml-1 text-white text-opacity-60">Currently: {{ mediaMetadata.asin || '' }}</p> <p v-if="mediaMetadata.asin" class="text-xs ml-1 text-white text-opacity-60">Currently: {{ mediaMetadata.asin || '' }}</p>
</div> </div>
</div> </div>
<div v-if="selectedMatch.itunesId" class="flex items-center py-2">
<ui-checkbox v-model="selectedMatchUsage.itunesId" />
<div class="flex-grow ml-4">
<ui-text-input-with-label v-model="selectedMatch.itunesId" type="number" :disabled="!selectedMatchUsage.itunesId" label="iTunes ID" />
<p v-if="mediaMetadata.itunesId" class="text-xs ml-1 text-white text-opacity-60">Currently: {{ mediaMetadata.itunesId || '' }}</p>
</div>
</div>
<div v-if="selectedMatch.feedUrl" class="flex items-center py-2">
<ui-checkbox v-model="selectedMatchUsage.feedUrl" />
<div class="flex-grow ml-4">
<ui-text-input-with-label v-model="selectedMatch.feedUrl" :disabled="!selectedMatchUsage.feedUrl" label="RSS Feed URL" />
<p v-if="mediaMetadata.feedUrl" class="text-xs ml-1 text-white text-opacity-60">Currently: {{ mediaMetadata.feedUrl || '' }}</p>
</div>
</div>
<div v-if="selectedMatch.itunesPageUrl" class="flex items-center py-2">
<ui-checkbox v-model="selectedMatchUsage.itunesPageUrl" />
<div class="flex-grow ml-4">
<ui-text-input-with-label v-model="selectedMatch.itunesPageUrl" :disabled="!selectedMatchUsage.itunesPageUrl" label="iTunes Page URL" />
<p v-if="mediaMetadata.itunesPageUrl" class="text-xs ml-1 text-white text-opacity-60">Currently: {{ mediaMetadata.itunesPageUrl || '' }}</p>
</div>
</div>
<div v-if="selectedMatch.releaseDate" class="flex items-center py-2">
<ui-checkbox v-model="selectedMatchUsage.releaseDate" />
<div class="flex-grow ml-4">
<ui-text-input-with-label v-model="selectedMatch.releaseDate" :disabled="!selectedMatchUsage.releaseDate" label="Release Date" />
<p v-if="mediaMetadata.releaseDate" class="text-xs ml-1 text-white text-opacity-60">Currently: {{ mediaMetadata.releaseDate || '' }}</p>
</div>
</div>
<div class="flex items-center justify-end py-2"> <div class="flex items-center justify-end py-2">
<ui-btn color="success" type="submit">Update</ui-btn> <ui-btn color="success" type="submit">Update</ui-btn>
</div> </div>
@ -148,7 +178,12 @@ export default {
series: true, series: true,
volumeNumber: true, volumeNumber: true,
asin: true, asin: true,
isbn: true isbn: true,
// Podcast specific
itunesPageUrl: true,
itunesId: true,
feedUrl: true,
releaseDate: true
} }
} }
}, },
@ -173,6 +208,7 @@ export default {
return this.$store.getters['getBookCoverAspectRatio'] return this.$store.getters['getBookCoverAspectRatio']
}, },
providers() { providers() {
if (this.isPodcast) return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers return this.$store.state.scanners.providers
}, },
searchTitleLabel() { searchTitleLabel() {
@ -185,6 +221,12 @@ export default {
}, },
mediaMetadata() { mediaMetadata() {
return this.media.metadata || {} return this.media.metadata || {}
},
mediaType() {
return this.libraryItem ? this.libraryItem.mediaType : null
},
isPodcast() {
return this.mediaType == 'podcast'
} }
}, },
methods: { methods: {
@ -196,6 +238,7 @@ export default {
} }
}, },
getSearchQuery() { getSearchQuery() {
if (this.isPodcast) return `term=${this.searchTitle}`
var searchQuery = `provider=${this.provider}&fallbackTitleOnly=1&title=${this.searchTitle}` var searchQuery = `provider=${this.provider}&fallbackTitleOnly=1&title=${this.searchTitle}`
if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}` if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}`
return searchQuery return searchQuery
@ -214,14 +257,27 @@ export default {
this.searchResults = [] this.searchResults = []
this.isProcessing = true this.isProcessing = true
this.lastSearch = searchQuery this.lastSearch = searchQuery
var results = await this.$axios.$get(`/api/search/books?${searchQuery}`).catch((error) => { var searchEntity = this.isPodcast ? 'podcast' : 'books'
var results = await this.$axios.$get(`/api/search/${searchEntity}?${searchQuery}`).catch((error) => {
console.error('Failed', error) console.error('Failed', error)
return [] return []
}) })
results = results.filter((res) => { // console.log('Got search results', results)
results = (results || []).filter((res) => {
return !!res.title return !!res.title
}) })
this.searchResults = results
if (this.isPodcast) {
// Map to match PodcastMetadata keys
results = results.map((res) => {
res.itunesPageUrl = res.pageUrl || null
res.itunesId = res.id || null
res.author = res.artistName || null
return res
})
}
this.searchResults = results || []
this.isProcessing = false this.isProcessing = false
this.hasSearched = true this.hasSearched = true
}, },
@ -239,7 +295,12 @@ export default {
series: true, series: true,
volumeNumber: true, volumeNumber: true,
asin: true, asin: true,
isbn: true isbn: true,
// Podcast specific
itunesPageUrl: true,
itunesId: true,
feedUrl: true,
releaseDate: true
} }
if (this.libraryItem.id !== this.libraryItemId) { if (this.libraryItem.id !== this.libraryItemId) {
@ -255,7 +316,8 @@ export default {
} }
this.searchTitle = this.libraryItem.media.metadata.title this.searchTitle = this.libraryItem.media.metadata.title
this.searchAuthor = this.libraryItem.media.metadata.authorName || '' this.searchAuthor = this.libraryItem.media.metadata.authorName || ''
this.provider = localStorage.getItem('book-provider') || 'google' if (this.isPodcast) this.provider = 'itunes'
else this.provider = localStorage.getItem('book-provider') || 'google'
}, },
selectMatch(match) { selectMatch(match) {
this.selectedMatch = match this.selectedMatch = match
@ -273,7 +335,7 @@ export default {
sequence: volumeNumber sequence: volumeNumber
} }
updatePayload.series = [seriesItem] updatePayload.series = [seriesItem]
} else if (key === 'author') { } else if (key === 'author' && !this.isPodcast) {
var authorItem = { var authorItem = {
id: `new-${Math.floor(Math.random() * 10000)}`, id: `new-${Math.floor(Math.random() * 10000)}`,
name: this.selectedMatch[key] name: this.selectedMatch[key]
@ -281,6 +343,8 @@ export default {
updatePayload.authors = [authorItem] updatePayload.authors = [authorItem]
} else if (key === 'narrator') { } else if (key === 'narrator') {
updatePayload.narrators = [this.selectedMatch[key]] updatePayload.narrators = [this.selectedMatch[key]]
} else if (key === 'itunesId') {
updatePayload.itunesId = Number(this.selectedMatch[key])
} else if (key !== 'volumeNumber') { } else if (key !== 'volumeNumber') {
updatePayload[key] = this.selectedMatch[key] updatePayload[key] = this.selectedMatch[key]
} }

View File

@ -66,7 +66,9 @@ class LibraryItemController {
await this.cacheManager.purgeCoverCache(libraryItem.id) await this.cacheManager.purgeCoverCache(libraryItem.id)
} }
await this.createAuthorsAndSeriesForItemUpdate(mediaPayload) if (libraryItem.isBook) {
await this.createAuthorsAndSeriesForItemUpdate(mediaPayload)
}
var hasUpdates = libraryItem.media.update(mediaPayload) var hasUpdates = libraryItem.media.update(mediaPayload)
if (hasUpdates) { if (hasUpdates) {

View File

@ -147,7 +147,11 @@ class MiscController {
async findCovers(req, res) { async findCovers(req, res) {
var query = req.query var query = req.query
var result = await this.bookFinder.findCovers(query.provider, query.title, query.author || null) var podcast = query.podcast == 1
var result = null
if (podcast) result = await this.podcastFinder.findCovers(query.title)
else result = await this.bookFinder.findCovers(query.provider, query.title, query.author || null)
res.json(result) res.json(result)
} }

View File

@ -13,5 +13,13 @@ class PodcastFinder {
Logger.debug(`[iTunes] Podcast search for "${term}" returned ${results.length} results`) Logger.debug(`[iTunes] Podcast search for "${term}" returned ${results.length} results`)
return results return results
} }
async findCovers(term) {
if (!term) return null
Logger.debug(`[iTunes] Searching for podcast covers with term "${term}"`)
var results = await this.iTunesApi.searchPodcasts(term)
if (!results) return []
return results.map(r => r.cover).filter(r => r)
}
} }
module.exports = PodcastFinder module.exports = PodcastFinder

View File

@ -144,6 +144,8 @@ class LibraryItem {
} }
} }
get isPodcast() { return this.mediaType === 'podcast' }
get isBook() { return this.mediaType === 'book' }
get size() { get size() {
var total = 0 var total = 0
this.libraryFiles.forEach((lf) => total += lf.metadata.size) this.libraryFiles.forEach((lf) => total += lf.metadata.size)

View File

@ -80,7 +80,7 @@ class iTunes {
cleanPodcast(data) { cleanPodcast(data) {
return { return {
id: data.collectionId, id: data.collectionId,
artistId: data.artistId, artistId: data.artistId || null,
title: data.collectionName, title: data.collectionName,
artistName: data.artistName, artistName: data.artistName,
description: stripHtml(data.description || '').result, description: stripHtml(data.description || '').result,