adds kitsu mapping for horrible subs WIP

This commit is contained in:
TheBeastLT
2019-12-30 18:35:02 +01:00
parent e7f46d2adc
commit a73cdb6b54
5 changed files with 10525 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ const bing = require('nodejs-bing');
const { cacheWrapImdbId, cacheWrapMetadata } = require('./cache');
const CINEMETA_URL = 'https://v3-cinemeta.strem.io';
const KITSU_URL = 'https://anime-kitsu.now.sh';
function getMetadata(imdbId, type) {
return cacheWrapMetadata(imdbId,
@@ -35,6 +36,28 @@ function getMetadata(imdbId, type) {
}));
}
function getKitsuMetadata(kitsuId) {
const key = kitsuId.startsWith('kitsu:') ? kitsuId : `kitsu:${kitsuId}`;
return cacheWrapMetadata(key,
() => needle('get', `${KITSU_URL}/meta/series/${key}.json`, { open_timeout: 60000 })
.then((response) => {
const body = response.body;
if (body && body.meta && body.meta.id) {
return {
...body.meta,
videos: undefined,
totalEpisodes: body.meta.videos && body.meta.videos
.filter(video => video.season > 0).length
};
} else {
throw new Error('No search results');
}
})
.catch((error) => {
throw new Error(`failed kitsu query ${kitsuId} due: ${error.message}`);
}));
}
function escapeTitle(title, hyphenEscape = true) {
return title.toLowerCase()
.normalize('NFKD') // normalize non-ASCII characters
@@ -64,4 +87,17 @@ async function getImdbId(info) {
.match(/imdb\.com\/title\/(tt\d+)/)[1])));
}
module.exports = { escapeTitle, getMetadata, getImdbId };
async function getKitsuId(title) {
return cacheWrapImdbId(title,
() => needle('get', `${KITSU_URL}/catalog/series/kitsu-anime-list/search=${title}.json`, { open_timeout: 60000 })
.then((response) => {
const body = response.body;
if (body && body.metas && body.metas.length) {
return body.metas[0].id.replace('kitsu:', '');
} else {
throw new Error('No search results');
}
}));
}
module.exports = { escapeTitle, getMetadata, getImdbId, getKitsuMetadata, getKitsuId };