From fd4aedd7ecbb1db8959b6ff3f20b94b4312d0630 Mon Sep 17 00:00:00 2001 From: Alexandru Branza Date: Sun, 31 May 2020 16:08:44 +0300 Subject: [PATCH] Always use IMDB ID too When Searching for Subs --- .../Player/components/SubtitleText/actions.js | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/components/Player/components/SubtitleText/actions.js b/src/components/Player/components/SubtitleText/actions.js index 6c43235f..935dd66b 100644 --- a/src/components/Player/components/SubtitleText/actions.js +++ b/src/components/Player/components/SubtitleText/actions.js @@ -5,7 +5,10 @@ import ControlActions from '../Controls/actions'; import subUtil from '../../utils/subtitles'; import ls from 'local-storage'; import _ from 'lodash'; +import nameToImdb from 'name-to-imdb'; +import parseVideo from 'video-name-parser'; import player from '../../utils/player'; +import parser from '../../utils/parser'; class SubtitleActions { @@ -37,6 +40,24 @@ class SubtitleActions { if (itemDesc.path) subQuery.filepath = itemDesc.path + if (itemDesc.byteSize) + subQuery.byteLength = itemDesc.byteSize; + + if (itemDesc.torrentHash) { + subQuery.torrentHash = itemDesc.torrentHash; + subQuery.isFinished = false; + } + + subQuery.cb = subs => { + if (!subs) { + if (!ls.isSet('playerNotifs') || ls('playerNotifs')) + player.notifier.info('Subtitles Not Found', '', 6000); + cb && cb(false); + } else { + this.actions.foundSubs(subs, true, idx, cb); + } + } + if (window.getExtendedDetails) { if (itemDesc.parsed) { @@ -55,23 +76,23 @@ class SubtitleActions { subQuery.query = window.extendedTitle } window.getExtendedDetails = null - } - - if (itemDesc.byteSize) - subQuery.byteLength = itemDesc.byteSize; - - if (itemDesc.torrentHash) { - subQuery.torrentHash = itemDesc.torrentHash; - subQuery.isFinished = false; - } - - subQuery.cb = subs => { - if (!subs) { - if (!ls.isSet('playerNotifs') || ls('playerNotifs')) - player.notifier.info('Subtitles Not Found', '', 6000); - cb && cb(false); - } else { - this.actions.foundSubs(subs, true, idx, cb); + } else if (subQuery.filepath) { + var filename = parser(subQuery.filepath).filename(); + var parsedFilename = parseVideo(filename); + if (parsedFilename) { + nameToImdb(parsedFilename, function(err, res, inf) { + if (res) { + subQuery.imdbid = res; + + if (parsedFilename.type == 'series' && parsedFilename.season && (parsedFilename.episode || []).length) { + subQuery.season = parsedFilename.season + ''; + subQuery.episode = parsedFilename.episode[0] + ''; + } + } + + subUtil.fetchSubs(subQuery); + }) + return } }