mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
updates the package structure and updates initial horriblesubs scraper WIP
This commit is contained in:
@@ -2,52 +2,46 @@ const needle = require('needle');
|
||||
const nameToImdb = require('name-to-imdb');
|
||||
const bing = require('nodejs-bing');
|
||||
const { cacheWrapImdbId, cacheWrapMetadata } = require('./cache');
|
||||
const { Type } = require('./types');
|
||||
|
||||
const CINEMETA_URL = 'https://v3-cinemeta.strem.io';
|
||||
const KITSU_URL = 'https://anime-kitsu.now.sh';
|
||||
|
||||
function getMetadata(imdbId, type) {
|
||||
return cacheWrapMetadata(imdbId,
|
||||
() => needle('get', `${CINEMETA_URL}/meta/${type}/${imdbId}.json`, { open_timeout: 60000 })
|
||||
.then((response) => {
|
||||
const body = response.body;
|
||||
if (body && body.meta && body.meta.name) {
|
||||
return {
|
||||
imdbId: imdbId,
|
||||
title: body.meta.name,
|
||||
year: body.meta.year,
|
||||
genres: body.meta.genres,
|
||||
totalEpisodes: body.meta.videos && body.meta.videos
|
||||
.filter(video => video.season > 0).length,
|
||||
episodeCount: body.meta.videos && Object.values(body.meta.videos
|
||||
.filter((entry) => entry.season !== 0)
|
||||
.sort((a, b) => a.season - b.season)
|
||||
.reduce((map, next) => {
|
||||
map[next.season] = map[next.season] + 1 || 1;
|
||||
return map;
|
||||
}, {}))
|
||||
};
|
||||
} else {
|
||||
throw new Error('No search results');
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
throw new Error(`failed cinemeta query ${imdbId} due: ${error.message}`);
|
||||
}));
|
||||
}
|
||||
|
||||
function getKitsuMetadata(kitsuId) {
|
||||
const key = kitsuId.startsWith('kitsu:') ? kitsuId : `kitsu:${kitsuId}`;
|
||||
function getMetadata(id, type = Type.SERIES ) {
|
||||
const key = id.match(/^\d+$/) ? `kitsu:${id}` : id;
|
||||
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
|
||||
kitsuId: body.kitsu_id,
|
||||
imdbId: body.imdb_id,
|
||||
title: body.meta.name,
|
||||
year: body.meta.year,
|
||||
genres: body.meta.genres,
|
||||
videos: body.meta.videos && body.meta.videos
|
||||
.map((video) => video.imdbSeason
|
||||
? {
|
||||
episode: video.episode,
|
||||
imdbSeason: video.imdbSeason,
|
||||
imdbEpisode: video.imdbEpisode
|
||||
}
|
||||
: {
|
||||
season: video.season,
|
||||
episode: video.episode,
|
||||
kitsuId: video.kitsu_id,
|
||||
kitsuEpisode: video.kitsuEpisode,
|
||||
released: video.released
|
||||
}
|
||||
),
|
||||
episodeCount: body.meta.videos && Object.values(body.meta.videos
|
||||
.filter((entry) => entry.season !== 0)
|
||||
.sort((a, b) => a.season - b.season)
|
||||
.reduce((map, next) => {
|
||||
map[next.season] = map[next.season] + 1 || 1;
|
||||
return map;
|
||||
}, {}))
|
||||
};
|
||||
} else {
|
||||
throw new Error('No search results');
|
||||
@@ -101,4 +95,4 @@ async function getKitsuId(title) {
|
||||
}));
|
||||
}
|
||||
|
||||
module.exports = { escapeTitle, getMetadata, getImdbId, getKitsuMetadata, getKitsuId };
|
||||
module.exports = { escapeTitle, getMetadata, getImdbId, getKitsuId };
|
||||
|
||||
Reference in New Issue
Block a user