mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
add torrentio catalogs addon
This commit is contained in:
35
catalogs/lib/metadata.js
Normal file
35
catalogs/lib/metadata.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const axios = require('axios');
|
||||
const { Type } = require('../../addon/lib/types');
|
||||
|
||||
const CINEMETA_URL = 'https://v3-cinemeta.strem.io';
|
||||
const KITSU_URL = 'https://anime-kitsu.strem.fun';
|
||||
const TIMEOUT = 30000;
|
||||
const MAX_SIZE = 50;
|
||||
|
||||
function getMetas(ids, type) {
|
||||
if (!ids.length || !type) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return _requestMetadata(ids, type)
|
||||
.catch((error) => {
|
||||
throw new Error(`failed metadata ${type} query due: ${error.message}`);
|
||||
});
|
||||
}
|
||||
|
||||
function _requestMetadata(ids, type) {
|
||||
const url = _getUrl(ids, type);
|
||||
return axios.get(url, { timeout: TIMEOUT })
|
||||
.then(response => response?.data?.metas || response?.data?.metasDetailed || [])
|
||||
.then(metas => metas.filter(meta => meta));
|
||||
}
|
||||
|
||||
function _getUrl(ids, type) {
|
||||
const joinedIds = ids.slice(0, MAX_SIZE).join(',');
|
||||
if (type === Type.ANIME) {
|
||||
return `${KITSU_URL}/catalog/${type}/kitsu-anime-list/lastVideosIds=${joinedIds}.json`
|
||||
}
|
||||
return `${CINEMETA_URL}/catalog/${type}/last-videos/lastVideosIds=${joinedIds}.json`
|
||||
}
|
||||
|
||||
module.exports = { getMetas };
|
||||
Reference in New Issue
Block a user