Update to new version

make-only-subtitle-default
supersnellehenk 3 years ago
parent 4daad3596c
commit 5713e2e76a
No known key found for this signature in database

@ -1,5 +1,5 @@
/* eslint-disable no-await-in-loop */
module.exports.dependencies = ['axios', '@cospired/i18n-iso-languages'];
module.exports.dependencies = ['axios@0.27.2', '@cospired/i18n-iso-languages'];
// tdarrSkipTest
const details = () => ({
id: 'Tdarr_Plugin_henk_Keep_Native_Lang_Plus_Eng',
@ -12,7 +12,7 @@ const details = () => ({
'Native' languages are the ones that are listed on imdb. It does an API call to
Radarr, Sonarr to check if the movie/series exists and grabs the IMDB id. As a last resort it
falls back to the IMDB id in the filename.`,
Version: '1.1',
Version: '1.2',
Tags: 'pre-processing,configurable',
Inputs: [
{
@ -140,9 +140,8 @@ const processStreams = (result, file, user_langs) => {
response.infoLog = `${response.infoLog.slice(0, -2)}\n`;
for (let i = 0; i < file.ffProbeData.streams.length; i += 1) {
const stream = file.ffProbeData.streams[i];
// eslint-disable-next-line no-restricted-syntax
for (const stream of file.ffProbeData.streams) {
if (stream.codec_type === 'audio') {
if (!stream.tags) {
response.infoLog += `☒No tags found on audio track ${streamIndex}. Keeping it. \n`;
@ -176,7 +175,7 @@ const tmdbApi = async (filename, api_key, axios) => {
let fileName;
// If filename begins with tt, it's already an imdb id
if (filename) {
if (filename.substr(0, 2) === 'tt') {
if (filename.substring(0, 2) === 'tt') {
fileName = filename;
} else {
const idRegex = /(tt\d{7,8})/;
@ -209,17 +208,7 @@ const parseArrResponse = async (body, filePath, arr) => {
// eslint-disable-next-line default-case
switch (arr) {
case 'radarr':
// filePath = file
for (let i = 0; i < body.length; i += 1) {
if (body[i].movieFile) {
if (body[i].movieFile.relativePath) {
if (body[i].movieFile.relativePath === filePath) {
return body[i];
}
}
}
}
break;
return body.movie;
case 'sonarr':
return body.series;
}
@ -232,6 +221,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => {
inputs = lib.loadDefaultValues(inputs, details);
// eslint-disable-next-line import/no-unresolved
const axios = require('axios').default;
response.container = `.${file.container}`;
let prio = ['radarr', 'sonarr'];
let radarrResult = null;
@ -244,41 +234,44 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => {
}
}
for (let i = 0; i < prio.length; i += 1) {
const fileNameEncoded = encodeURIComponent(file.meta.FileName);
// eslint-disable-next-line no-restricted-syntax
for (const arr of prio) {
let imdbId;
// eslint-disable-next-line default-case
switch (prio[i]) {
switch (arr) {
case 'radarr':
if (tmdbResult) break;
if (inputs.radarr_api_key) {
radarrResult = await parseArrResponse(
await axios
.get(
`http://${inputs.radarr_url}/api/v3/movie?apiKey=${inputs.radarr_api_key}`,
`http://${inputs.radarr_url}/api/v3/parse?apikey=${inputs.radarr_api_key}&title=${fileNameEncoded}`,
)
.then((resp) => resp.data),
file.meta.FileName,
fileNameEncoded,
'radarr',
);
if (radarrResult) {
imdbId = radarrResult.imdbId;
response.infoLog += `Grabbed ID (${imdbId}) from Radarr \n`;
const languages = require('@cospired/i18n-iso-languages');
tmdbResult = { original_language: languages.getAlpha2Code(radarrResult.originalLanguage.name, 'en') };
} else {
response.infoLog += 'Couldn\'t grab ID from Radarr \n';
imdbId = file.meta.FileName;
response.infoLog += "Couldn't grab ID from Radarr \n";
imdbId = fileNameEncoded;
}
tmdbResult = await tmdbApi(imdbId, inputs.api_key, axios);
}
break;
case 'sonarr':
if (tmdbResult) break;
if (inputs.sonarr_api_key) {
sonarrResult = await parseArrResponse(
await axios
.get(
`http://${inputs.sonarr_url}/api/v3/parse?apikey=${inputs.sonarr_api_key}&title=${file.meta.FileName}`,
)
await axios.get(
`http://${inputs.sonarr_url}/api/v3/parse?apikey=${inputs.sonarr_api_key}&title=${fileNameEncoded}`,
)
.then((resp) => resp.data),
file.meta.Directory,
'sonarr',
@ -288,8 +281,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => {
imdbId = sonarrResult.imdbId;
response.infoLog += `Grabbed ID (${imdbId}) from Sonarr \n`;
} else {
response.infoLog += 'Couldn\'t grab ID from Sonarr \n';
imdbId = file.meta.FileName;
response.infoLog += "Couldn't grab ID from Sonarr \n";
imdbId = fileNameEncoded;
}
tmdbResult = await tmdbApi(imdbId, inputs.api_key, axios);
}
@ -319,7 +312,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => {
response.infoLog += '☒No audio tracks to be removed. \n';
}
} else {
response.infoLog += '☒Couldn\'t find the IMDB id of this file. Skipping. \n';
response.infoLog += "☒Couldn't find the IMDB id of this file. Skipping. \n";
}
return response;
};

Loading…
Cancel
Save