mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] cache kitsuId search with separate key
This commit is contained in:
@@ -3,6 +3,7 @@ const mangodbStore = require('cache-manager-mongodb');
|
|||||||
|
|
||||||
const GLOBAL_KEY_PREFIX = 'stremio-torrentio';
|
const GLOBAL_KEY_PREFIX = 'stremio-torrentio';
|
||||||
const IMDB_ID_PREFIX = `${GLOBAL_KEY_PREFIX}|imdb_id`;
|
const IMDB_ID_PREFIX = `${GLOBAL_KEY_PREFIX}|imdb_id`;
|
||||||
|
const KITSU_ID_PREFIX = `${GLOBAL_KEY_PREFIX}|kitsu_id`;
|
||||||
const METADATA_PREFIX = `${GLOBAL_KEY_PREFIX}|metadata`;
|
const METADATA_PREFIX = `${GLOBAL_KEY_PREFIX}|metadata`;
|
||||||
const TORRENT_FILES_KEY_PREFIX = `stremio-tpb|files`;
|
const TORRENT_FILES_KEY_PREFIX = `stremio-tpb|files`;
|
||||||
|
|
||||||
@@ -73,9 +74,13 @@ function cacheWrapImdbId(key, method) {
|
|||||||
return cacheWrap(remoteCache, `${IMDB_ID_PREFIX}:${key}`, method, { ttl: GLOBAL_TTL });
|
return cacheWrap(remoteCache, `${IMDB_ID_PREFIX}:${key}`, method, { ttl: GLOBAL_TTL });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cacheWrapKitsuId(key, method) {
|
||||||
|
return cacheWrap(remoteCache, `${KITSU_ID_PREFIX}:${key}`, method, { ttl: GLOBAL_TTL });
|
||||||
|
}
|
||||||
|
|
||||||
function cacheWrapMetadata(id, method) {
|
function cacheWrapMetadata(id, method) {
|
||||||
return cacheWrap(memoryCache, `${METADATA_PREFIX}:${id}`, method, { ttl: GLOBAL_TTL });
|
return cacheWrap(memoryCache, `${METADATA_PREFIX}:${id}`, method, { ttl: GLOBAL_TTL });
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { cacheWrapImdbId, cacheWrapMetadata, retrieveTorrentFiles };
|
module.exports = { cacheWrapImdbId, cacheWrapKitsuId, cacheWrapMetadata, retrieveTorrentFiles };
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const needle = require('needle');
|
const needle = require('needle');
|
||||||
const nameToImdb = require('name-to-imdb');
|
const nameToImdb = require('name-to-imdb');
|
||||||
const bing = require('nodejs-bing');
|
const bing = require('nodejs-bing');
|
||||||
const { cacheWrapImdbId, cacheWrapMetadata } = require('./cache');
|
const { cacheWrapImdbId, cacheWrapKitsuId, cacheWrapMetadata } = require('./cache');
|
||||||
const { Type } = require('./types');
|
const { Type } = require('./types');
|
||||||
|
|
||||||
const CINEMETA_URL = 'https://v3-cinemeta.strem.io';
|
const CINEMETA_URL = 'https://v3-cinemeta.strem.io';
|
||||||
@@ -39,12 +39,14 @@ function _requestMetadata(url) {
|
|||||||
videos: (body.meta.videos || [])
|
videos: (body.meta.videos || [])
|
||||||
.map((video) => video.imdbSeason
|
.map((video) => video.imdbSeason
|
||||||
? {
|
? {
|
||||||
|
name: video.name,
|
||||||
season: video.season,
|
season: video.season,
|
||||||
episode: video.episode,
|
episode: video.episode,
|
||||||
imdbSeason: video.imdbSeason,
|
imdbSeason: video.imdbSeason,
|
||||||
imdbEpisode: video.imdbEpisode
|
imdbEpisode: video.imdbEpisode
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
|
name: video.name,
|
||||||
season: video.season,
|
season: video.season,
|
||||||
episode: video.episode,
|
episode: video.episode,
|
||||||
kitsuId: video.kitsu_id,
|
kitsuId: video.kitsu_id,
|
||||||
@@ -105,7 +107,7 @@ async function getKitsuId(info) {
|
|||||||
const season = info.season > 1 ? ` S${info.season}` : '';
|
const season = info.season > 1 ? ` S${info.season}` : '';
|
||||||
const query = `${title}${season}`;
|
const query = `${title}${season}`;
|
||||||
|
|
||||||
return cacheWrapImdbId(query,
|
return cacheWrapKitsuId(query,
|
||||||
() => needle('get', `${KITSU_URL}/catalog/series/kitsu-anime-list/search=${query}.json`, { open_timeout: 60000 })
|
() => needle('get', `${KITSU_URL}/catalog/series/kitsu-anime-list/search=${query}.json`, { open_timeout: 60000 })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const body = response.body;
|
const body = response.body;
|
||||||
|
|||||||
@@ -227,6 +227,24 @@ function decomposeDateEpisodeFiles(torrent, files, metadata) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function decomposeEpisodeTitleFiles(torrent, files, metadata) {
|
||||||
|
const titleMapping = metadata.videos
|
||||||
|
.reduce((map, video) => {
|
||||||
|
map[video.name.toLowerCase()] = video;
|
||||||
|
return map;
|
||||||
|
}, {});
|
||||||
|
files
|
||||||
|
.filter(file => !file.season)
|
||||||
|
.map(file => {
|
||||||
|
const episodeTitle = file.name.replace(/^.*-\s?(.+)\.\w{1,4}$/, '$1').toLowerCase();
|
||||||
|
const mapping = titleMapping[episodeTitle];
|
||||||
|
if (mapping) {
|
||||||
|
file.season = mapping.season;
|
||||||
|
file.episodes = [mapping.episode];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function getTimeZoneOffset(country) {
|
function getTimeZoneOffset(country) {
|
||||||
switch (country) {
|
switch (country) {
|
||||||
case 'USA':
|
case 'USA':
|
||||||
|
|||||||
Reference in New Issue
Block a user