updates id search input arguments

This commit is contained in:
TheBeastLT
2020-03-03 20:36:10 +01:00
parent 30d1a60d00
commit cbfcea65f8
8 changed files with 30 additions and 33 deletions

View File

@@ -77,19 +77,21 @@ function escapeTitle(title, hyphenEscape = true) {
.trim();
}
async function getImdbId(info) {
const key = `${info.name}_${info.year}_${info.type}`;
async function getImdbId(info, type) {
const name = escapeTitle(info.title).toLowerCase();
const year = info.year || info.date && info.date.slice(0, 4);
const key = `${name}_${year}_${type}`;
return cacheWrapImdbId(key,
() => new Promise((resolve, reject) => {
nameToImdb(info, function (err, res) {
nameToImdb({ name, year, type }, function (err, res) {
if (res) {
resolve(res);
} else {
reject(err || new Error('failed imdbId search'));
}
});
}).catch(() => bing.web(`${info.name} ${info.year || ''} ${info.type} imdb`)
}).catch(() => bing.web(`${name} ${year || ''} ${type} imdb`)
.then(results => results
.map((result) => result.link)
.find(result => result.includes('imdb.com/title/')))
@@ -98,8 +100,10 @@ async function getImdbId(info) {
}
async function getKitsuId(info) {
const title = info.season > 1 ? `${info.name} S${info.season}` : info.name;
const query = title.replace(/[;]+/g, ' ').replace(/[,%']+/g, '');
const title = escapeTitle(info.title).toLowerCase().replace(/[;]+/g, ' ').replace(/[,%']+/g, '');
const season = info.season > 1 ? ` S${info.season}` : '';
const query = `${title}${season}`;
return cacheWrapImdbId(query,
() => needle('get', `${KITSU_URL}/catalog/series/kitsu-anime-list/search=${query}.json`, { open_timeout: 60000 })
.then((response) => {
@@ -112,4 +116,4 @@ async function getKitsuId(info) {
}));
}
module.exports = { escapeTitle, getMetadata, getImdbId, getKitsuId };
module.exports = { getMetadata, getImdbId, getKitsuId };