updates metadata retrieval exception handling

This commit is contained in:
TheBeastLT
2020-02-25 21:47:57 +01:00
parent 75053fccd0
commit 23880d4fb2
3 changed files with 9 additions and 5 deletions

View File

@@ -9,6 +9,10 @@ const KITSU_URL = 'https://anime-kitsu.now.sh';
const TIMEOUT = 20000;
function getMetadata(id, type = Type.SERIES) {
if (!id) {
return Promise.reject("no valid id provided");
}
const key = id.match(/^\d+$/) ? `kitsu:${id}` : id;
const metaType = type === Type.MOVIE ? Type.MOVIE : Type.SERIES;
return cacheWrapMetadata(key,
@@ -86,10 +90,11 @@ async function getImdbId(info) {
}
});
}).catch(() => bing.web(`${info.name} ${info.year || ''} ${info.type} imdb`)
.then((results) => results
.then(results => results
.map((result) => result.link)
.find(result => result.includes('imdb.com/title/'))
.match(/imdb\.com\/title\/(tt\d+)/)[1])));
.find(result => result.includes('imdb.com/title/')))
.then(result => result && result.match(/imdb\.com\/title\/(tt\d+)/))
.then(match => match && match[1])));
}
async function getKitsuId(info) {