mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
adds kitsu mapping for horrible subs WIP
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user