mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Add library match all back updated to support v2 models
This commit is contained in:
		
							parent
							
								
									ff294867f8
								
							
						
					
					
						commit
						35f3b5863f
					
				@ -10,7 +10,7 @@
 | 
				
			|||||||
    <ui-btn v-show="isHovering && !libraryScan" small color="success" @click.stop="scan">Scan</ui-btn>
 | 
					    <ui-btn v-show="isHovering && !libraryScan" small color="success" @click.stop="scan">Scan</ui-btn>
 | 
				
			||||||
    <ui-btn v-show="isHovering && !libraryScan" small color="bg" class="ml-2" @click.stop="forceScan">Force Re-Scan</ui-btn>
 | 
					    <ui-btn v-show="isHovering && !libraryScan" small color="bg" class="ml-2" @click.stop="forceScan">Force Re-Scan</ui-btn>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <!-- <ui-btn v-show="isHovering && !libraryScan" small color="bg" class="ml-2" @click.stop="matchAll">Match Books</ui-btn> -->
 | 
					    <ui-btn v-show="isHovering && !libraryScan && isBookLibrary" small color="bg" class="ml-2" @click.stop="matchAll">Match Books</ui-btn>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <span v-show="isHovering && !libraryScan && showEdit" class="material-icons text-xl text-gray-300 hover:text-gray-50 ml-4 cursor-pointer" @click.stop="editClick">edit</span>
 | 
					    <span v-show="isHovering && !libraryScan && showEdit" class="material-icons text-xl text-gray-300 hover:text-gray-50 ml-4 cursor-pointer" @click.stop="editClick">edit</span>
 | 
				
			||||||
    <span v-show="!libraryScan && isHovering && showEdit && !isDeleting" class="material-icons text-xl text-gray-300 ml-3" :class="isMain ? 'text-opacity-5 cursor-not-allowed' : 'hover:text-gray-50 cursor-pointer'" @click.stop="deleteClick">delete</span>
 | 
					    <span v-show="!libraryScan && isHovering && showEdit && !isDeleting" class="material-icons text-xl text-gray-300 ml-3" :class="isMain ? 'text-opacity-5 cursor-not-allowed' : 'hover:text-gray-50 cursor-pointer'" @click.stop="deleteClick">delete</span>
 | 
				
			||||||
@ -48,12 +48,18 @@ export default {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    libraryScan() {
 | 
					    libraryScan() {
 | 
				
			||||||
      return this.$store.getters['scanners/getLibraryScan'](this.library.id)
 | 
					      return this.$store.getters['scanners/getLibraryScan'](this.library.id)
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    mediaType() {
 | 
				
			||||||
 | 
					      return this.library.mediaType
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    isBookLibrary() {
 | 
				
			||||||
 | 
					      return this.mediaType === 'book'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    matchAll() {
 | 
					    matchAll() {
 | 
				
			||||||
      this.$axios
 | 
					      this.$axios
 | 
				
			||||||
        .$post(`/api/libraries/${this.library.id}/matchbooks`)
 | 
					        .$post(`/api/libraries/${this.library.id}/matchall`)
 | 
				
			||||||
        .then(() => {
 | 
					        .then(() => {
 | 
				
			||||||
          console.log('Starting scan for matches')
 | 
					          console.log('Starting scan for matches')
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
				
			|||||||
@ -200,6 +200,9 @@ class Db {
 | 
				
			|||||||
  getLibraryItem(id) {
 | 
					  getLibraryItem(id) {
 | 
				
			||||||
    return this.libraryItems.find(li => li.id === id)
 | 
					    return this.libraryItems.find(li => li.id === id)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  getLibraryItemsInLibrary(libraryId) {
 | 
				
			||||||
 | 
					    return this.libraryItems.filter(li => li.libraryId === libraryId)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  getPlaybackSession(id) {
 | 
					  getPlaybackSession(id) {
 | 
				
			||||||
    return this.sessionsDb.select((pb) => pb.id == id).then((results) => {
 | 
					    return this.sessionsDb.select((pb) => pb.id == id).then((results) => {
 | 
				
			||||||
      if (results.data.length) {
 | 
					      if (results.data.length) {
 | 
				
			||||||
 | 
				
			|||||||
@ -546,12 +546,12 @@ class LibraryController {
 | 
				
			|||||||
    res.json(Object.values(authors))
 | 
					    res.json(Object.values(authors))
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async matchBooks(req, res) {
 | 
					  async matchAll(req, res) {
 | 
				
			||||||
    if (!req.user.isRoot) {
 | 
					    if (!req.user.isRoot) {
 | 
				
			||||||
      Logger.error(`[LibraryController] Non-root user attempted to match library books`, req.user)
 | 
					      Logger.error(`[LibraryController] Non-root user attempted to match library items`, req.user)
 | 
				
			||||||
      return res.sendStatus(403)
 | 
					      return res.sendStatus(403)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.scanner.matchLibraryBooks(req.library)
 | 
					    this.scanner.matchLibraryItems(req.library)
 | 
				
			||||||
    res.sendStatus(200)
 | 
					    res.sendStatus(200)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -247,7 +247,7 @@ class LibraryItemController {
 | 
				
			|||||||
    var libraryItem = req.libraryItem
 | 
					    var libraryItem = req.libraryItem
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var options = req.body || {}
 | 
					    var options = req.body || {}
 | 
				
			||||||
    var matchResult = await this.scanner.quickMatchBook(libraryItem, options)
 | 
					    var matchResult = await this.scanner.quickMatchLibraryItem(libraryItem, options)
 | 
				
			||||||
    res.json(matchResult)
 | 
					    res.json(matchResult)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -65,7 +65,7 @@ class ApiRouter {
 | 
				
			|||||||
    this.router.get('/libraries/:id/search', LibraryController.middleware.bind(this), LibraryController.search.bind(this))
 | 
					    this.router.get('/libraries/:id/search', LibraryController.middleware.bind(this), LibraryController.search.bind(this))
 | 
				
			||||||
    this.router.get('/libraries/:id/stats', LibraryController.middleware.bind(this), LibraryController.stats.bind(this))
 | 
					    this.router.get('/libraries/:id/stats', LibraryController.middleware.bind(this), LibraryController.stats.bind(this))
 | 
				
			||||||
    this.router.get('/libraries/:id/authors', LibraryController.middleware.bind(this), LibraryController.getAuthors.bind(this))
 | 
					    this.router.get('/libraries/:id/authors', LibraryController.middleware.bind(this), LibraryController.getAuthors.bind(this))
 | 
				
			||||||
    this.router.post('/libraries/:id/matchbooks', LibraryController.middleware.bind(this), LibraryController.matchBooks.bind(this))
 | 
					    this.router.post('/libraries/:id/matchall', LibraryController.middleware.bind(this), LibraryController.matchAll.bind(this))
 | 
				
			||||||
    this.router.get('/libraries/:id/scan', LibraryController.middleware.bind(this), LibraryController.scan.bind(this)) // Root only
 | 
					    this.router.get('/libraries/:id/scan', LibraryController.middleware.bind(this), LibraryController.scan.bind(this)) // Root only
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.router.post('/libraries/order', LibraryController.reorder.bind(this))
 | 
					    this.router.post('/libraries/order', LibraryController.reorder.bind(this))
 | 
				
			||||||
 | 
				
			|||||||
@ -616,7 +616,7 @@ class Scanner {
 | 
				
			|||||||
    return false
 | 
					    return false
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async quickMatchBook(libraryItem, options = {}) {
 | 
					  async quickMatchLibraryItem(libraryItem, options = {}) {
 | 
				
			||||||
    var provider = options.provider || 'google'
 | 
					    var provider = options.provider || 'google'
 | 
				
			||||||
    var searchTitle = options.title || libraryItem.media.metadata.title
 | 
					    var searchTitle = options.title || libraryItem.media.metadata.title
 | 
				
			||||||
    var searchAuthor = options.author || libraryItem.media.metadata.authorName
 | 
					    var searchAuthor = options.author || libraryItem.media.metadata.authorName
 | 
				
			||||||
@ -698,49 +698,55 @@ class Scanner {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // TODO: Redo quick match full library
 | 
					  async matchLibraryItems(library) {
 | 
				
			||||||
  async matchLibraryBooks(library) {
 | 
					    if (library.mediaType === 'podcast') {
 | 
				
			||||||
    // if (this.isLibraryScanning(library.id)) {
 | 
					      Logger.error(`[Scanner] matchLibraryItems: Match all not supported for podcasts yet`)
 | 
				
			||||||
    //   Logger.error(`[Scanner] Already scanning ${library.id}`)
 | 
					      return
 | 
				
			||||||
    //   return
 | 
					    }
 | 
				
			||||||
    // }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // const provider = library.provider || 'google'
 | 
					    if (this.isLibraryScanning(library.id)) {
 | 
				
			||||||
    // var audiobooksInLibrary = this.db.audiobooks.filter(ab => ab.libraryId === library.id)
 | 
					      Logger.error(`[Scanner] matchLibraryItems: Already scanning ${library.id}`)
 | 
				
			||||||
    // if (!audiobooksInLibrary.length) {
 | 
					      return
 | 
				
			||||||
    //   return
 | 
					    }
 | 
				
			||||||
    // }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // var libraryScan = new LibraryScan()
 | 
					    var itemsInLibrary = this.db.getLibraryItemsInLibrary(library.id)
 | 
				
			||||||
    // libraryScan.setData(library, null, 'match')
 | 
					    if (!itemsInLibrary.length) {
 | 
				
			||||||
    // this.librariesScanning.push(libraryScan.getScanEmitData)
 | 
					      Logger.error(`[Scanner] matchLibraryItems: Library has no items ${library.id}`)
 | 
				
			||||||
    // this.emitter('scan_start', libraryScan.getScanEmitData)
 | 
					      return
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Logger.info(`[Scanner] Starting library match books scan ${libraryScan.id} for ${libraryScan.libraryName}`)
 | 
					    const provider = library.provider
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // for (let i = 0; i < audiobooksInLibrary.length; i++) {
 | 
					    var libraryScan = new LibraryScan()
 | 
				
			||||||
    //   var audiobook = audiobooksInLibrary[i]
 | 
					    libraryScan.setData(library, null, 'match')
 | 
				
			||||||
    //   Logger.debug(`[Scanner] Quick matching "${audiobook.title}" (${i + 1} of ${audiobooksInLibrary.length})`)
 | 
					    this.librariesScanning.push(libraryScan.getScanEmitData)
 | 
				
			||||||
    //   var result = await this.quickMatchBook(audiobook, { provider })
 | 
					    this.emitter('scan_start', libraryScan.getScanEmitData)
 | 
				
			||||||
    //   if (result.warning) {
 | 
					 | 
				
			||||||
    //     Logger.warn(`[Scanner] Match warning ${result.warning} for audiobook "${audiobook.title}"`)
 | 
					 | 
				
			||||||
    //   } else if (result.updated) {
 | 
					 | 
				
			||||||
    //     libraryScan.resultsUpdated++
 | 
					 | 
				
			||||||
    //   }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //   if (this.cancelLibraryScan[libraryScan.libraryId]) {
 | 
					    Logger.info(`[Scanner] matchLibraryItems: Starting library match scan ${libraryScan.id} for ${libraryScan.libraryName}`)
 | 
				
			||||||
    //     Logger.info(`[Scanner] Library match scan canceled for "${libraryScan.libraryName}"`)
 | 
					 | 
				
			||||||
    //     delete this.cancelLibraryScan[libraryScan.libraryId]
 | 
					 | 
				
			||||||
    //     var scanData = libraryScan.getScanEmitData
 | 
					 | 
				
			||||||
    //     scanData.results = false
 | 
					 | 
				
			||||||
    //     this.emitter('scan_complete', scanData)
 | 
					 | 
				
			||||||
    //     this.librariesScanning = this.librariesScanning.filter(ls => ls.id !== library.id)
 | 
					 | 
				
			||||||
    //     return
 | 
					 | 
				
			||||||
    //   }
 | 
					 | 
				
			||||||
    // }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // this.librariesScanning = this.librariesScanning.filter(ls => ls.id !== library.id)
 | 
					    for (let i = 0; i < itemsInLibrary.length; i++) {
 | 
				
			||||||
    // this.emitter('scan_complete', libraryScan.getScanEmitData)
 | 
					      var libraryItem = itemsInLibrary[i]
 | 
				
			||||||
 | 
					      Logger.debug(`[Scanner] matchLibraryItems: Quick matching "${libraryItem.media.metadata.title}" (${i + 1} of ${itemsInLibrary.length})`)
 | 
				
			||||||
 | 
					      var result = await this.quickMatchLibraryItem(libraryItem, { provider })
 | 
				
			||||||
 | 
					      if (result.warning) {
 | 
				
			||||||
 | 
					        Logger.warn(`[Scanner] matchLibraryItems: Match warning ${result.warning} for library item "${libraryItem.media.metadata.title}"`)
 | 
				
			||||||
 | 
					      } else if (result.updated) {
 | 
				
			||||||
 | 
					        libraryScan.resultsUpdated++
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (this.cancelLibraryScan[libraryScan.libraryId]) {
 | 
				
			||||||
 | 
					        Logger.info(`[Scanner] matchLibraryItems: Library match scan canceled for "${libraryScan.libraryName}"`)
 | 
				
			||||||
 | 
					        delete this.cancelLibraryScan[libraryScan.libraryId]
 | 
				
			||||||
 | 
					        var scanData = libraryScan.getScanEmitData
 | 
				
			||||||
 | 
					        scanData.results = false
 | 
				
			||||||
 | 
					        this.emitter('scan_complete', scanData)
 | 
				
			||||||
 | 
					        this.librariesScanning = this.librariesScanning.filter(ls => ls.id !== library.id)
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this.librariesScanning = this.librariesScanning.filter(ls => ls.id !== library.id)
 | 
				
			||||||
 | 
					    this.emitter('scan_complete', libraryScan.getScanEmitData)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
module.exports = Scanner
 | 
					module.exports = Scanner
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user