mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Client: Use new server providers API
This commit is contained in:
		
							parent
							
								
									1da3ab7fdc
								
							
						
					
					
						commit
						ce4ff4f894
					
				@ -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'
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -319,7 +319,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
 | 
			
		||||
 | 
			
		||||
@ -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: {
 | 
			
		||||
 | 
			
		||||
@ -136,7 +136,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
 | 
			
		||||
    },
 | 
			
		||||
    maskAsFinishedWhenItems() {
 | 
			
		||||
      return [
 | 
			
		||||
 | 
			
		||||
@ -371,11 +371,25 @@ export default {
 | 
			
		||||
    },
 | 
			
		||||
    customMetadataProviderAdded(provider) {
 | 
			
		||||
      if (!provider?.id) return
 | 
			
		||||
      this.$store.commit('scanners/addCustomMetadataProvider', provider)
 | 
			
		||||
      // Refetch the appropriate provider types
 | 
			
		||||
      if (provider.mediaType === 'book') {
 | 
			
		||||
        this.$store.dispatch('scanners/fetchBookProviders')
 | 
			
		||||
        this.$store.dispatch('scanners/fetchBookCoverProviders')
 | 
			
		||||
      } else if (provider.mediaType === 'podcast') {
 | 
			
		||||
        this.$store.dispatch('scanners/fetchPodcastProviders')
 | 
			
		||||
        this.$store.dispatch('scanners/fetchPodcastCoverProviders')
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    customMetadataProviderRemoved(provider) {
 | 
			
		||||
      if (!provider?.id) return
 | 
			
		||||
      this.$store.commit('scanners/removeCustomMetadataProvider', provider)
 | 
			
		||||
      // Refetch the appropriate provider types
 | 
			
		||||
      if (provider.mediaType === 'book') {
 | 
			
		||||
        this.$store.dispatch('scanners/fetchBookProviders')
 | 
			
		||||
        this.$store.dispatch('scanners/fetchBookCoverProviders')
 | 
			
		||||
      } else if (provider.mediaType === 'podcast') {
 | 
			
		||||
        this.$store.dispatch('scanners/fetchPodcastProviders')
 | 
			
		||||
        this.$store.dispatch('scanners/fetchPodcastCoverProviders')
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    initializeSocket() {
 | 
			
		||||
      if (this.$root.socket) {
 | 
			
		||||
@ -612,6 +626,12 @@ export default {
 | 
			
		||||
 | 
			
		||||
    this.$store.dispatch('libraries/load')
 | 
			
		||||
 | 
			
		||||
    // Fetch metadata providers
 | 
			
		||||
    this.$store.dispatch('scanners/fetchBookProviders')
 | 
			
		||||
    this.$store.dispatch('scanners/fetchBookCoverProviders')
 | 
			
		||||
    this.$store.dispatch('scanners/fetchPodcastProviders')
 | 
			
		||||
    this.$store.dispatch('scanners/fetchPodcastCoverProviders')
 | 
			
		||||
 | 
			
		||||
    this.initLocalStorage()
 | 
			
		||||
 | 
			
		||||
    this.checkVersionUpdate()
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -131,8 +131,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
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
@ -1,126 +1,73 @@
 | 
			
		||||
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: []
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const actions = {}
 | 
			
		||||
export const actions = {
 | 
			
		||||
  async fetchBookProviders({ commit }) {
 | 
			
		||||
    try {
 | 
			
		||||
      const response = await this.$axios.$get('/api/search/providers/books')
 | 
			
		||||
      if (response?.providers) {
 | 
			
		||||
        commit('setBookProviders', response.providers)
 | 
			
		||||
      }
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
      console.error('Failed to fetch book providers', error)
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  async fetchPodcastProviders({ commit }) {
 | 
			
		||||
    try {
 | 
			
		||||
      const response = await this.$axios.$get('/api/search/providers/podcasts')
 | 
			
		||||
      if (response?.providers) {
 | 
			
		||||
        commit('setPodcastProviders', response.providers)
 | 
			
		||||
      }
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
      console.error('Failed to fetch podcast providers', error)
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  async fetchBookCoverProviders({ commit }) {
 | 
			
		||||
    try {
 | 
			
		||||
      const response = await this.$axios.$get('/api/search/providers/books/covers')
 | 
			
		||||
      if (response?.providers) {
 | 
			
		||||
        commit('setBookCoverProviders', response.providers)
 | 
			
		||||
      }
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
      console.error('Failed to fetch book cover providers', error)
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  async fetchPodcastCoverProviders({ commit }) {
 | 
			
		||||
    try {
 | 
			
		||||
      const response = await this.$axios.$get('/api/search/providers/podcasts/covers')
 | 
			
		||||
      if (response?.providers) {
 | 
			
		||||
        commit('setPodcastCoverProviders', response.providers)
 | 
			
		||||
      }
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
      console.error('Failed to fetch podcast cover providers', error)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
  setBookProviders(state, providers) {
 | 
			
		||||
    state.bookProviders = providers
 | 
			
		||||
  },
 | 
			
		||||
  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)
 | 
			
		||||
    }
 | 
			
		||||
  setPodcastProviders(state, providers) {
 | 
			
		||||
    state.podcastProviders = providers
 | 
			
		||||
  },
 | 
			
		||||
  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
 | 
			
		||||
    }
 | 
			
		||||
  setBookCoverProviders(state, providers) {
 | 
			
		||||
    state.bookCoverProviders = providers
 | 
			
		||||
  },
 | 
			
		||||
  setPodcastCoverProviders(state, providers) {
 | 
			
		||||
    state.podcastCoverProviders = providers
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user