Update to new version

This commit is contained in:
supersnellehenk 2023-04-18 22:34:35 +02:00
parent 4daad3596c
commit 5713e2e76a
No known key found for this signature in database

View file

@ -1,5 +1,5 @@
/* eslint-disable no-await-in-loop */ /* 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 // tdarrSkipTest
const details = () => ({ const details = () => ({
id: 'Tdarr_Plugin_henk_Keep_Native_Lang_Plus_Eng', 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 '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 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.`, falls back to the IMDB id in the filename.`,
Version: '1.1', Version: '1.2',
Tags: 'pre-processing,configurable', Tags: 'pre-processing,configurable',
Inputs: [ Inputs: [
{ {
@ -140,9 +140,8 @@ const processStreams = (result, file, user_langs) => {
response.infoLog = `${response.infoLog.slice(0, -2)}\n`; response.infoLog = `${response.infoLog.slice(0, -2)}\n`;
for (let i = 0; i < file.ffProbeData.streams.length; i += 1) { // eslint-disable-next-line no-restricted-syntax
const stream = file.ffProbeData.streams[i]; for (const stream of file.ffProbeData.streams) {
if (stream.codec_type === 'audio') { if (stream.codec_type === 'audio') {
if (!stream.tags) { if (!stream.tags) {
response.infoLog += `☒No tags found on audio track ${streamIndex}. Keeping it. \n`; 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; let fileName;
// If filename begins with tt, it's already an imdb id // If filename begins with tt, it's already an imdb id
if (filename) { if (filename) {
if (filename.substr(0, 2) === 'tt') { if (filename.substring(0, 2) === 'tt') {
fileName = filename; fileName = filename;
} else { } else {
const idRegex = /(tt\d{7,8})/; const idRegex = /(tt\d{7,8})/;
@ -209,17 +208,7 @@ const parseArrResponse = async (body, filePath, arr) => {
// eslint-disable-next-line default-case // eslint-disable-next-line default-case
switch (arr) { switch (arr) {
case 'radarr': case 'radarr':
// filePath = file return body.movie;
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;
case 'sonarr': case 'sonarr':
return body.series; return body.series;
} }
@ -232,6 +221,7 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => {
inputs = lib.loadDefaultValues(inputs, details); inputs = lib.loadDefaultValues(inputs, details);
// eslint-disable-next-line import/no-unresolved // eslint-disable-next-line import/no-unresolved
const axios = require('axios').default; const axios = require('axios').default;
response.container = `.${file.container}`; response.container = `.${file.container}`;
let prio = ['radarr', 'sonarr']; let prio = ['radarr', 'sonarr'];
let radarrResult = null; 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; let imdbId;
// eslint-disable-next-line default-case // eslint-disable-next-line default-case
switch (prio[i]) { switch (arr) {
case 'radarr': case 'radarr':
if (tmdbResult) break; if (tmdbResult) break;
if (inputs.radarr_api_key) { if (inputs.radarr_api_key) {
radarrResult = await parseArrResponse( radarrResult = await parseArrResponse(
await axios await axios
.get( .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), .then((resp) => resp.data),
file.meta.FileName, fileNameEncoded,
'radarr', 'radarr',
); );
if (radarrResult) { if (radarrResult) {
imdbId = radarrResult.imdbId; imdbId = radarrResult.imdbId;
response.infoLog += `Grabbed ID (${imdbId}) from Radarr \n`; 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 { } else {
response.infoLog += 'Couldn\'t grab ID from Radarr \n'; response.infoLog += "Couldn't grab ID from Radarr \n";
imdbId = file.meta.FileName; imdbId = fileNameEncoded;
} }
tmdbResult = await tmdbApi(imdbId, inputs.api_key, axios);
} }
break; break;
case 'sonarr': case 'sonarr':
if (tmdbResult) break; if (tmdbResult) break;
if (inputs.sonarr_api_key) { if (inputs.sonarr_api_key) {
sonarrResult = await parseArrResponse( sonarrResult = await parseArrResponse(
await axios await axios.get(
.get( `http://${inputs.sonarr_url}/api/v3/parse?apikey=${inputs.sonarr_api_key}&title=${fileNameEncoded}`,
`http://${inputs.sonarr_url}/api/v3/parse?apikey=${inputs.sonarr_api_key}&title=${file.meta.FileName}`, )
)
.then((resp) => resp.data), .then((resp) => resp.data),
file.meta.Directory, file.meta.Directory,
'sonarr', 'sonarr',
@ -288,8 +281,8 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => {
imdbId = sonarrResult.imdbId; imdbId = sonarrResult.imdbId;
response.infoLog += `Grabbed ID (${imdbId}) from Sonarr \n`; response.infoLog += `Grabbed ID (${imdbId}) from Sonarr \n`;
} else { } else {
response.infoLog += 'Couldn\'t grab ID from Sonarr \n'; response.infoLog += "Couldn't grab ID from Sonarr \n";
imdbId = file.meta.FileName; imdbId = fileNameEncoded;
} }
tmdbResult = await tmdbApi(imdbId, inputs.api_key, axios); 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'; response.infoLog += '☒No audio tracks to be removed. \n';
} }
} else { } 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; return response;
}; };