Add library match all back updated to support v2 models

This commit is contained in:
advplyr 2022-04-20 18:05:09 -05:00
parent ff294867f8
commit 35f3b5863f
6 changed files with 60 additions and 45 deletions

View File

@ -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="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="!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() {
return this.$store.getters['scanners/getLibraryScan'](this.library.id)
},
mediaType() {
return this.library.mediaType
},
isBookLibrary() {
return this.mediaType === 'book'
}
},
methods: {
matchAll() {
this.$axios
.$post(`/api/libraries/${this.library.id}/matchbooks`)
.$post(`/api/libraries/${this.library.id}/matchall`)
.then(() => {
console.log('Starting scan for matches')
})

View File

@ -200,6 +200,9 @@ class Db {
getLibraryItem(id) {
return this.libraryItems.find(li => li.id === id)
}
getLibraryItemsInLibrary(libraryId) {
return this.libraryItems.filter(li => li.libraryId === libraryId)
}
getPlaybackSession(id) {
return this.sessionsDb.select((pb) => pb.id == id).then((results) => {
if (results.data.length) {

View File

@ -546,12 +546,12 @@ class LibraryController {
res.json(Object.values(authors))
}
async matchBooks(req, res) {
async matchAll(req, res) {
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)
}
this.scanner.matchLibraryBooks(req.library)
this.scanner.matchLibraryItems(req.library)
res.sendStatus(200)
}

View File

@ -247,7 +247,7 @@ class LibraryItemController {
var libraryItem = req.libraryItem
var options = req.body || {}
var matchResult = await this.scanner.quickMatchBook(libraryItem, options)
var matchResult = await this.scanner.quickMatchLibraryItem(libraryItem, options)
res.json(matchResult)
}

View File

@ -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/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.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.post('/libraries/order', LibraryController.reorder.bind(this))

View File

@ -616,7 +616,7 @@ class Scanner {
return false
}
async quickMatchBook(libraryItem, options = {}) {
async quickMatchLibraryItem(libraryItem, options = {}) {
var provider = options.provider || 'google'
var searchTitle = options.title || libraryItem.media.metadata.title
var searchAuthor = options.author || libraryItem.media.metadata.authorName
@ -698,49 +698,55 @@ class Scanner {
}
}
// TODO: Redo quick match full library
async matchLibraryBooks(library) {
// if (this.isLibraryScanning(library.id)) {
// Logger.error(`[Scanner] Already scanning ${library.id}`)
// return
// }
async matchLibraryItems(library) {
if (library.mediaType === 'podcast') {
Logger.error(`[Scanner] matchLibraryItems: Match all not supported for podcasts yet`)
return
}
// const provider = library.provider || 'google'
// var audiobooksInLibrary = this.db.audiobooks.filter(ab => ab.libraryId === library.id)
// if (!audiobooksInLibrary.length) {
// return
// }
if (this.isLibraryScanning(library.id)) {
Logger.error(`[Scanner] matchLibraryItems: Already scanning ${library.id}`)
return
}
// var libraryScan = new LibraryScan()
// libraryScan.setData(library, null, 'match')
// this.librariesScanning.push(libraryScan.getScanEmitData)
// this.emitter('scan_start', libraryScan.getScanEmitData)
var itemsInLibrary = this.db.getLibraryItemsInLibrary(library.id)
if (!itemsInLibrary.length) {
Logger.error(`[Scanner] matchLibraryItems: Library has no items ${library.id}`)
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 audiobook = audiobooksInLibrary[i]
// Logger.debug(`[Scanner] Quick matching "${audiobook.title}" (${i + 1} of ${audiobooksInLibrary.length})`)
// var result = await this.quickMatchBook(audiobook, { provider })
// if (result.warning) {
// Logger.warn(`[Scanner] Match warning ${result.warning} for audiobook "${audiobook.title}"`)
// } else if (result.updated) {
// libraryScan.resultsUpdated++
// }
var libraryScan = new LibraryScan()
libraryScan.setData(library, null, 'match')
this.librariesScanning.push(libraryScan.getScanEmitData)
this.emitter('scan_start', libraryScan.getScanEmitData)
// if (this.cancelLibraryScan[libraryScan.libraryId]) {
// 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
// }
// }
Logger.info(`[Scanner] matchLibraryItems: Starting library match scan ${libraryScan.id} for ${libraryScan.libraryName}`)
// this.librariesScanning = this.librariesScanning.filter(ls => ls.id !== library.id)
// this.emitter('scan_complete', libraryScan.getScanEmitData)
for (let i = 0; i < itemsInLibrary.length; i++) {
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