Add:iTunes search api metadata provider #381

This commit is contained in:
advplyr 2022-03-06 17:26:35 -06:00
parent 43f48b65f8
commit a907c88f66
5 changed files with 54 additions and 24 deletions

View File

@ -47,9 +47,9 @@
<ui-dropdown v-model="provider" :items="providers" label="Provider" small />
</div>
<div class="w-72 px-1">
<ui-text-input-with-label v-model="searchTitle" :label="provider == 'audible' ? 'Search Title or ASIN' : 'Search Title'" placeholder="Search" />
<ui-text-input-with-label v-model="searchTitle" :label="searchTitleLabel" placeholder="Search" />
</div>
<div class="w-72 px-1">
<div v-show="provider != 'itunes'" class="w-72 px-1">
<ui-text-input-with-label v-model="searchAuthor" label="Author" />
</div>
<ui-btn class="mt-5 ml-1" type="submit">Search</ui-btn>
@ -98,20 +98,6 @@ export default {
showLocalCovers: false,
previewUpload: null,
selectedFile: null,
providers: [
{
text: 'Google Books',
value: 'google'
},
{
text: 'Open Library',
value: 'openlibrary'
},
{
text: 'Audible',
value: 'audible'
}
],
provider: 'google'
}
},
@ -134,6 +120,14 @@ export default {
this.$emit('update:processing', val)
}
},
providers() {
return this.$store.state.scanners.providers
},
searchTitleLabel() {
if (this.provider == 'audible') return 'Search Title or ASIN'
else if (this.provider == 'itunes') return 'Search Term'
return 'Search Title'
},
coverAspectRatio() {
return this.$store.getters['getServerSetting']('coverAspectRatio')
},

View File

@ -6,9 +6,9 @@
<ui-dropdown v-model="provider" :items="providers" label="Provider" small />
</div>
<div class="w-72 px-1">
<ui-text-input-with-label v-model="searchTitle" :label="provider == 'audible' ? 'Search Title or ASIN' : 'Search Title'" placeholder="Search" />
<ui-text-input-with-label v-model="searchTitle" :label="searchTitleLabel" placeholder="Search" />
</div>
<div class="w-72 px-1">
<div v-show="provider != 'itunes'" class="w-72 px-1">
<ui-text-input-with-label v-model="searchAuthor" label="Author" />
</div>
<ui-btn class="mt-5 ml-1" type="submit">Search</ui-btn>
@ -147,6 +147,11 @@ export default {
},
providers() {
return this.$store.state.scanners.providers
},
searchTitleLabel() {
if (this.provider == 'audible') return 'Search Title or ASIN'
else if (this.provider == 'itunes') return 'Search Term'
return 'Search Title'
}
},
methods: {

View File

@ -12,6 +12,10 @@ export const state = () => ({
{
text: 'Audible',
value: 'audible'
},
{
text: 'iTunes',
value: 'itunes'
}
]
})

View File

@ -2,6 +2,7 @@ const OpenLibrary = require('../providers/OpenLibrary')
const LibGen = require('../providers/LibGen')
const GoogleBooks = require('../providers/GoogleBooks')
const Audible = require('../providers/Audible')
const iTunes = require('../providers/iTunes')
const Logger = require('../Logger')
const { levenshteinDistance } = require('../utils/index')
@ -11,6 +12,7 @@ class BookFinder {
this.libGen = new LibGen()
this.googleBooks = new GoogleBooks()
this.audible = new Audible()
this.iTunesApi = new iTunes()
this.verbose = false
}
@ -158,6 +160,10 @@ class BookFinder {
return books
}
async getiTunesAudiobooksResults(title, author) {
return this.iTunesApi.searchAudiobooks(title)
}
async getAudibleResults(title, author) {
var books = await this.audible.search(title, author);
if (this.verbose) Logger.debug(`Audible Book Search Results: ${books.length || 0}`)
@ -175,6 +181,8 @@ class BookFinder {
return this.getGoogleBooksResults(title, author)
} else if (provider === 'audible') {
return this.getAudibleResults(title, author)
} else if (provider === 'itunes') {
return this.getiTunesAudiobooksResults(title, author)
} else if (provider === 'libgen') {
books = await this.getLibGenResults(title, author, maxTitleDistance, maxAuthorDistance)
} else if (provider === 'openlibrary') {

View File

@ -1,6 +1,6 @@
const axios = require('axios')
const Logger = require('../Logger')
const { stripHtml } = require('string-strip-html')
class iTunes {
constructor() { }
@ -18,16 +18,35 @@ class iTunes {
limit: options.limit,
country: options.country
}
console.log('Query', query)
return axios.get('https://itunes.apple.com/search', { params: query }).then((response) => {
var data = response.data
console.log('data', data)
return data.results || []
return response.data.results || []
}).catch((error) => {
Logger.error(`[iTunes] search request error`, error)
return []
})
}
cleanAudiobook(data) {
// Example cover art: https://is1-ssl.mzstatic.com/image/thumb/Music118/v4/cb/ea/73/cbea739b-ff3b-11c4-fb93-7889fbec7390/9781598874983_cover.jpg/100x100bb.jpg
// 100x100bb can be replaced by other values https://github.com/bendodson/itunes-artwork-finder
var cover = data.artworkUrl100 || data.artworkUrl60 || ''
cover = cover.replace('100x100bb', '600x600bb').replace('60x60bb', '600x600bb')
return {
id: data.collectionId,
artistId: data.artistId,
title: data.collectionName,
author: data.artistName,
description: stripHtml(data.description || '').result,
publishYear: data.releaseDate ? data.releaseDate.split('-')[0] : null,
genres: data.primaryGenreName ? [data.primaryGenreName] : [],
cover
}
}
searchAudiobooks(term) {
return this.search({ term, entity: 'audiobook', media: 'audiobook' }).then((results) => {
return results.map(this.cleanAudiobook)
})
}
}
module.exports = iTunes