36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
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 };
|