Merge pull request #4750 from mikiher/providers-api

Add metadata providers API and use them on web client
This commit is contained in:
advplyr 2025-10-21 17:24:11 -05:00 committed by GitHub
commit a92ba564bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 361 additions and 210 deletions

View file

@ -88,7 +88,7 @@ export default {
},
providers() {
if (this.isPodcast) return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers
return this.$store.state.scanners.bookProviders
},
libraryProvider() {
return this.$store.getters['libraries/getLibraryProvider'](this.currentLibraryId) || 'google'
@ -96,6 +96,9 @@ export default {
},
methods: {
init() {
// Fetch providers when modal is shown
this.$store.dispatch('scanners/fetchProviders')
// If we don't have a set provider (first open of dialog) or we've switched library, set
// the selected provider to the current library default provider
if (!this.options.provider || this.lastUsedLibrary != this.currentLibraryId) {
@ -127,8 +130,7 @@ export default {
this.show = false
})
}
},
mounted() {}
}
}
</script>

View file

@ -133,8 +133,8 @@ export default {
}
},
providers() {
if (this.isPodcast) return this.$store.state.scanners.podcastProviders
return [{ text: 'Best', value: 'best' }, ...this.$store.state.scanners.providers, ...this.$store.state.scanners.coverOnlyProviders, { text: 'All', value: 'all' }]
if (this.isPodcast) return this.$store.state.scanners.podcastCoverProviders
return this.$store.state.scanners.bookCoverProviders
},
searchTitleLabel() {
if (this.provider.startsWith('audible')) return this.$strings.LabelSearchTitleOrASIN
@ -438,6 +438,8 @@ export default {
mounted() {
// Setup socket listeners when component is mounted
this.addSocketListeners()
// Fetch providers if not already loaded
this.$store.dispatch('scanners/fetchProviders')
},
beforeDestroy() {
// Cancel any ongoing search when component is destroyed

View file

@ -2,7 +2,7 @@
<div id="match-wrapper" class="w-full h-full overflow-hidden px-2 md:px-4 py-4 md:py-6 relative">
<form @submit.prevent="submitSearch">
<div class="flex flex-wrap md:flex-nowrap items-center justify-start -mx-1">
<div class="w-36 px-1">
<div v-if="providersLoaded" class="w-36 px-1">
<ui-dropdown v-model="provider" :items="providers" :label="$strings.LabelProvider" small />
</div>
<div class="grow md:w-72 px-1">
@ -253,6 +253,7 @@ export default {
hasSearched: false,
selectedMatch: null,
selectedMatchOrig: null,
waitingForProviders: false,
selectedMatchUsage: {
title: true,
subtitle: true,
@ -285,9 +286,19 @@ export default {
handler(newVal) {
if (newVal) this.init()
}
},
providersLoaded(isLoaded) {
// Complete initialization once providers are loaded
if (isLoaded && this.waitingForProviders) {
this.waitingForProviders = false
this.initProviderAndSearch()
}
}
},
computed: {
providersLoaded() {
return this.$store.getters['scanners/areProvidersLoaded']
},
isProcessing: {
get() {
return this.processing
@ -319,7 +330,7 @@ export default {
},
providers() {
if (this.isPodcast) return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers
return this.$store.state.scanners.bookProviders
},
searchTitleLabel() {
if (this.provider.startsWith('audible')) return this.$strings.LabelSearchTitleOrASIN
@ -478,6 +489,24 @@ export default {
this.checkboxToggled()
},
initProviderAndSearch() {
// Set provider based on media type
if (this.isPodcast) {
this.provider = 'itunes'
} else {
this.provider = this.getDefaultBookProvider()
}
// Prefer using ASIN if set and using audible provider
if (this.provider.startsWith('audible') && this.libraryItem.media.metadata.asin) {
this.searchTitle = this.libraryItem.media.metadata.asin
this.searchAuthor = ''
}
if (this.searchTitle) {
this.submitSearch()
}
},
init() {
this.clearSelectedMatch()
this.initSelectedMatchUsage()
@ -495,19 +524,13 @@ export default {
}
this.searchTitle = this.libraryItem.media.metadata.title
this.searchAuthor = this.libraryItem.media.metadata.authorName || ''
if (this.isPodcast) this.provider = 'itunes'
else {
this.provider = this.getDefaultBookProvider()
}
// Prefer using ASIN if set and using audible provider
if (this.provider.startsWith('audible') && this.libraryItem.media.metadata.asin) {
this.searchTitle = this.libraryItem.media.metadata.asin
this.searchAuthor = ''
}
if (this.searchTitle) {
this.submitSearch()
// Wait for providers to be loaded before setting provider and searching
if (this.providersLoaded || this.isPodcast) {
this.waitingForProviders = false
this.initProviderAndSearch()
} else {
this.waitingForProviders = true
}
},
selectMatch(match) {
@ -637,6 +660,10 @@ export default {
this.selectedMatch = null
this.selectedMatchOrig = null
}
},
mounted() {
// Fetch providers if not already loaded
this.$store.dispatch('scanners/fetchProviders')
}
}
</script>

View file

@ -74,7 +74,7 @@ export default {
},
providers() {
if (this.mediaType === 'podcast') return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers
return this.$store.state.scanners.bookProviders
}
},
methods: {
@ -156,6 +156,8 @@ export default {
},
mounted() {
this.init()
// Fetch providers if not already loaded
this.$store.dispatch('scanners/fetchProviders')
}
}
</script>

View file

@ -104,7 +104,6 @@ export default {
},
data() {
return {
provider: null,
useSquareBookCovers: false,
enableWatcher: false,
skipMatchingMediaWithAsin: false,
@ -134,10 +133,6 @@ export default {
isPodcastLibrary() {
return this.mediaType === 'podcast'
},
providers() {
if (this.mediaType === 'podcast') return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers
},
maskAsFinishedWhenItems() {
return [
{

View file

@ -371,11 +371,13 @@ export default {
},
customMetadataProviderAdded(provider) {
if (!provider?.id) return
this.$store.commit('scanners/addCustomMetadataProvider', provider)
// Refresh providers cache
this.$store.dispatch('scanners/refreshProviders')
},
customMetadataProviderRemoved(provider) {
if (!provider?.id) return
this.$store.commit('scanners/removeCustomMetadataProvider', provider)
// Refresh providers cache
this.$store.dispatch('scanners/refreshProviders')
},
initializeSocket() {
if (this.$root.socket) {

View file

@ -247,7 +247,8 @@ export default {
return this.$store.state.serverSettings
},
providers() {
return this.$store.state.scanners.providers
// Use book cover providers for the cover provider dropdown
return this.$store.state.scanners.bookCoverProviders || []
},
dateFormats() {
return this.$store.state.globals.dateFormats
@ -416,6 +417,8 @@ export default {
},
mounted() {
this.initServerSettings()
// Fetch providers if not already loaded (for cover provider dropdown)
this.$store.dispatch('scanners/fetchProviders')
}
}
</script>

View file

@ -155,7 +155,7 @@ export default {
},
providers() {
if (this.selectedLibraryIsPodcast) return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers
return this.$store.state.scanners.bookProviders
},
canFetchMetadata() {
return !this.selectedLibraryIsPodcast && this.fetchMetadata.enabled
@ -394,6 +394,8 @@ export default {
this.setMetadataProvider()
this.setDefaultFolder()
// Fetch providers if not already loaded
this.$store.dispatch('scanners/fetchProviders')
window.addEventListener('dragenter', this.dragenter)
window.addEventListener('dragleave', this.dragleave)
window.addEventListener('dragover', this.dragover)

View file

@ -117,7 +117,6 @@ export const actions = {
const library = data.library
const filterData = data.filterdata
const issues = data.issues || 0
const customMetadataProviders = data.customMetadataProviders || []
const numUserPlaylists = data.numUserPlaylists
dispatch('user/checkUpdateLibrarySortFilter', library.mediaType, { root: true })
@ -131,8 +130,6 @@ export const actions = {
commit('setLibraryIssues', issues)
commit('setLibraryFilterData', filterData)
commit('setNumUserPlaylists', numUserPlaylists)
commit('scanners/setCustomMetadataProviders', customMetadataProviders, { root: true })
commit('setCurrentLibrary', { id: libraryId })
return data
})

View file

@ -1,126 +1,60 @@
export const state = () => ({
providers: [
{
text: 'Google Books',
value: 'google'
},
{
text: 'Open Library',
value: 'openlibrary'
},
{
text: 'iTunes',
value: 'itunes'
},
{
text: 'Audible.com',
value: 'audible'
},
{
text: 'Audible.ca',
value: 'audible.ca'
},
{
text: 'Audible.co.uk',
value: 'audible.uk'
},
{
text: 'Audible.com.au',
value: 'audible.au'
},
{
text: 'Audible.fr',
value: 'audible.fr'
},
{
text: 'Audible.de',
value: 'audible.de'
},
{
text: 'Audible.co.jp',
value: 'audible.jp'
},
{
text: 'Audible.it',
value: 'audible.it'
},
{
text: 'Audible.co.in',
value: 'audible.in'
},
{
text: 'Audible.es',
value: 'audible.es'
},
{
text: 'FantLab.ru',
value: 'fantlab'
}
],
podcastProviders: [
{
text: 'iTunes',
value: 'itunes'
}
],
coverOnlyProviders: [
{
text: 'AudiobookCovers.com',
value: 'audiobookcovers'
}
]
bookProviders: [],
podcastProviders: [],
bookCoverProviders: [],
podcastCoverProviders: [],
providersLoaded: false
})
export const getters = {
checkBookProviderExists: state => (providerValue) => {
return state.providers.some(p => p.value === providerValue)
checkBookProviderExists: (state) => (providerValue) => {
return state.bookProviders.some((p) => p.value === providerValue)
},
checkPodcastProviderExists: state => (providerValue) => {
return state.podcastProviders.some(p => p.value === providerValue)
checkPodcastProviderExists: (state) => (providerValue) => {
return state.podcastProviders.some((p) => p.value === providerValue)
},
areProvidersLoaded: (state) => state.providersLoaded
}
export const actions = {
async fetchProviders({ commit, state }) {
// Only fetch if not already loaded
if (state.providersLoaded) {
return
}
try {
const response = await this.$axios.$get('/api/search/providers')
if (response?.providers) {
commit('setAllProviders', response.providers)
}
} catch (error) {
console.error('Failed to fetch providers', error)
}
},
async refreshProviders({ commit, state }) {
// if providers are not loaded, do nothing - they will be fetched when required (
if (!state.providersLoaded) {
return
}
try {
const response = await this.$axios.$get('/api/search/providers')
if (response?.providers) {
commit('setAllProviders', response.providers)
}
} catch (error) {
console.error('Failed to refresh providers', error)
}
}
}
export const actions = {}
export const mutations = {
addCustomMetadataProvider(state, provider) {
if (provider.mediaType === 'book') {
if (state.providers.some(p => p.value === provider.slug)) return
state.providers.push({
text: provider.name,
value: provider.slug
})
} else {
if (state.podcastProviders.some(p => p.value === provider.slug)) return
state.podcastProviders.push({
text: provider.name,
value: provider.slug
})
}
},
removeCustomMetadataProvider(state, provider) {
if (provider.mediaType === 'book') {
state.providers = state.providers.filter(p => p.value !== provider.slug)
} else {
state.podcastProviders = state.podcastProviders.filter(p => p.value !== provider.slug)
}
},
setCustomMetadataProviders(state, providers) {
if (!providers?.length) return
const mediaType = providers[0].mediaType
if (mediaType === 'book') {
// clear previous values, and add new values to the end
state.providers = state.providers.filter((p) => !p.value.startsWith('custom-'))
state.providers = [
...state.providers,
...providers.map((p) => ({
text: p.name,
value: p.slug
}))
]
} else {
// Podcast providers not supported yet
}
setAllProviders(state, providers) {
state.bookProviders = providers.books || []
state.podcastProviders = providers.podcasts || []
state.bookCoverProviders = providers.booksCovers || []
state.podcastCoverProviders = providers.podcasts || [] // Use same as bookCovers since podcasts use iTunes only
state.providersLoaded = true
}
}
}