audiobookshelf/server/finders/PodcastFinder.js

31 lines
967 B
JavaScript
Raw Normal View History

const Logger = require('../Logger')
const iTunes = require('../providers/iTunes')
class PodcastFinder {
constructor() {
this.iTunesApi = new iTunes()
}
2024-02-17 20:24:49 +01:00
/**
*
* @param {string} term
* @param {{country:string}} options
* @returns {Promise<import('../providers/iTunes').iTunesPodcastSearchResult[]>}
*/
async search(term, options = {}) {
if (!term) return null
Logger.debug(`[iTunes] Searching for podcast with term "${term}"`)
2024-02-17 20:24:49 +01:00
const results = await this.iTunesApi.searchPodcasts(term, options)
Logger.debug(`[iTunes] Podcast search for "${term}" returned ${results.length} results`)
return results
}
2022-04-14 01:13:39 +02:00
async findCovers(term) {
if (!term) return null
Logger.debug(`[iTunes] Searching for podcast covers with term "${term}"`)
var results = await this.iTunesApi.searchPodcasts(term)
if (!results) return []
return results.map(r => r.cover).filter(r => r)
}
}
module.exports = new PodcastFinder()