updates id search input arguments

This commit is contained in:
TheBeastLT
2020-03-03 20:36:10 +01:00
parent 30d1a60d00
commit cbfcea65f8
8 changed files with 30 additions and 33 deletions

View File

@@ -77,19 +77,21 @@ function escapeTitle(title, hyphenEscape = true) {
.trim();
}
async function getImdbId(info) {
const key = `${info.name}_${info.year}_${info.type}`;
async function getImdbId(info, type) {
const name = escapeTitle(info.title).toLowerCase();
const year = info.year || info.date && info.date.slice(0, 4);
const key = `${name}_${year}_${type}`;
return cacheWrapImdbId(key,
() => new Promise((resolve, reject) => {
nameToImdb(info, function (err, res) {
nameToImdb({ name, year, type }, function (err, res) {
if (res) {
resolve(res);
} else {
reject(err || new Error('failed imdbId search'));
}
});
}).catch(() => bing.web(`${info.name} ${info.year || ''} ${info.type} imdb`)
}).catch(() => bing.web(`${name} ${year || ''} ${type} imdb`)
.then(results => results
.map((result) => result.link)
.find(result => result.includes('imdb.com/title/')))
@@ -98,8 +100,10 @@ async function getImdbId(info) {
}
async function getKitsuId(info) {
const title = info.season > 1 ? `${info.name} S${info.season}` : info.name;
const query = title.replace(/[;]+/g, ' ').replace(/[,%']+/g, '');
const title = escapeTitle(info.title).toLowerCase().replace(/[;]+/g, ' ').replace(/[,%']+/g, '');
const season = info.season > 1 ? ` S${info.season}` : '';
const query = `${title}${season}`;
return cacheWrapImdbId(query,
() => needle('get', `${KITSU_URL}/catalog/series/kitsu-anime-list/search=${query}.json`, { open_timeout: 60000 })
.then((response) => {
@@ -112,4 +116,4 @@ async function getKitsuId(info) {
}));
}
module.exports = { escapeTitle, getMetadata, getImdbId, getKitsuId };
module.exports = { getMetadata, getImdbId, getKitsuId };

View File

@@ -1,23 +1,22 @@
const { parse } = require('parse-torrent-title');
const { Type } = require('./types');
const repository = require('./repository');
const { getImdbId, getKitsuId, escapeTitle } = require('./metadata');
const { getImdbId, getKitsuId } = require('./metadata');
const { parseTorrentFiles } = require('./torrentFiles');
async function createTorrentEntry(torrent) {
const titleInfo = parse(torrent.title);
const searchTitle = escapeTitle(titleInfo.title).toLowerCase();
if (titleInfo.seasons && torrent.type === Type.MOVIE) {
// sometimes series torrent might be put into movies category
torrent.type = Type.SERIES;
}
if (!torrent.imdbId && torrent.type !== Type.ANIME) {
torrent.imdbId = await getImdbId({ name: searchTitle, year: titleInfo.year, type: torrent.type })
torrent.imdbId = await getImdbId(titleInfo, torrent.type)
.catch(() => undefined);
}
if (!torrent.kitsuId && torrent.type === Type.ANIME) {
torrent.kitsuId = await getKitsuId({ name: searchTitle, season: titleInfo.season })
torrent.kitsuId = await getKitsuId(titleInfo)
.catch(() => undefined);
}

View File

@@ -283,12 +283,7 @@ function assignKitsuOrImdbEpisodes(files, metadata) {
function findMovieImdbId(title) {
const parsedTitle = typeof title === 'string' ? parse(title) : title;
const searchQuery = {
name: escapeTitle(parsedTitle.title).toLowerCase(),
year: parsedTitle.year,
type: Type.MOVIE
};
return getImdbId(searchQuery).catch((error) => undefined);
return getImdbId(parsedTitle, Type.MOVIE).catch(() => undefined);
}
function div100(episode) {