mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-08 00:08:14 +01:00
33 lines
904 B
JavaScript
33 lines
904 B
JavaScript
|
const axios = require('axios')
|
||
|
const Logger = require('../Logger')
|
||
|
|
||
|
class iTunes {
|
||
|
constructor() { }
|
||
|
|
||
|
// https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/iTuneSearchAPI/Searching.html
|
||
|
search(options) {
|
||
|
if (!options.term) {
|
||
|
Logger.error('[iTunes] Invalid search options - no term')
|
||
|
return []
|
||
|
}
|
||
|
var query = {
|
||
|
term: options.term,
|
||
|
media: options.media,
|
||
|
entity: options.entity,
|
||
|
lang: options.lang,
|
||
|
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 || []
|
||
|
}).catch((error) => {
|
||
|
Logger.error(`[iTunes] search request error`, error)
|
||
|
return []
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
module.exports = iTunes
|