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 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 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 });
|
||||
}
|
||||
|
||||
function cacheWrapKitsuId(key, method) {
|
||||
return cacheWrap(remoteCache, `${KITSU_ID_PREFIX}:${key}`, method, { ttl: GLOBAL_TTL });
|
||||
}
|
||||
|
||||
function cacheWrapMetadata(id, method) {
|
||||
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 nameToImdb = require('name-to-imdb');
|
||||
const bing = require('nodejs-bing');
|
||||
const { cacheWrapImdbId, cacheWrapMetadata } = require('./cache');
|
||||
const { cacheWrapImdbId, cacheWrapKitsuId, cacheWrapMetadata } = require('./cache');
|
||||
const { Type } = require('./types');
|
||||
|
||||
const CINEMETA_URL = 'https://v3-cinemeta.strem.io';
|
||||
@@ -39,12 +39,14 @@ function _requestMetadata(url) {
|
||||
videos: (body.meta.videos || [])
|
||||
.map((video) => video.imdbSeason
|
||||
? {
|
||||
name: video.name,
|
||||
season: video.season,
|
||||
episode: video.episode,
|
||||
imdbSeason: video.imdbSeason,
|
||||
imdbEpisode: video.imdbEpisode
|
||||
}
|
||||
: {
|
||||
name: video.name,
|
||||
season: video.season,
|
||||
episode: video.episode,
|
||||
kitsuId: video.kitsu_id,
|
||||
@@ -105,7 +107,7 @@ async function getKitsuId(info) {
|
||||
const season = info.season > 1 ? ` S${info.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 })
|
||||
.then((response) => {
|
||||
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) {
|
||||
switch (country) {
|
||||
case 'USA':
|
||||
|
||||
Reference in New Issue
Block a user