mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 15:38:19 -07:00
Update Sonarr parsing && reformat
This commit is contained in:
parent
197d8e0500
commit
4daad3596c
1 changed files with 50 additions and 30 deletions
|
|
@ -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.01',
|
||||
Version: '1.1',
|
||||
Tags: 'pre-processing,configurable',
|
||||
Inputs: [
|
||||
{
|
||||
|
|
@ -22,7 +22,8 @@ const details = () => ({
|
|||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Input a comma separated list of ISO-639-2 languages. It will still keep English and undefined tracks.'
|
||||
tooltip:
|
||||
'Input a comma separated list of ISO-639-2 languages. It will still keep English and undefined tracks.'
|
||||
+ '(https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes 639-2 column)'
|
||||
+ '\\nExample:\\n'
|
||||
+ 'nld,nor',
|
||||
|
|
@ -34,7 +35,8 @@ const details = () => ({
|
|||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Priority for either Radarr or Sonarr. Leaving it empty defaults to Radarr first.'
|
||||
tooltip:
|
||||
'Priority for either Radarr or Sonarr. Leaving it empty defaults to Radarr first.'
|
||||
+ '\\nExample:\\n'
|
||||
+ 'sonarr',
|
||||
},
|
||||
|
|
@ -45,7 +47,8 @@ const details = () => ({
|
|||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Input your TMDB api (v3) key here. (https://www.themoviedb.org/)',
|
||||
tooltip:
|
||||
'Input your TMDB api (v3) key here. (https://www.themoviedb.org/)',
|
||||
},
|
||||
{
|
||||
name: 'radarr_api_key',
|
||||
|
|
@ -63,7 +66,8 @@ const details = () => ({
|
|||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Input your Radarr url here. (Without http://). Do include the port.'
|
||||
tooltip:
|
||||
'Input your Radarr url here. (Without http://). Do include the port.'
|
||||
+ '\\nExample:\\n'
|
||||
+ '192.168.1.2:7878',
|
||||
},
|
||||
|
|
@ -83,7 +87,8 @@ const details = () => ({
|
|||
inputUI: {
|
||||
type: 'text',
|
||||
},
|
||||
tooltip: 'Input your Sonarr url here. (Without http://). Do include the port.'
|
||||
tooltip:
|
||||
'Input your Sonarr url here. (Without http://). Do include the port.'
|
||||
+ '\\nExample:\\n'
|
||||
+ '192.168.1.2:8989',
|
||||
},
|
||||
|
|
@ -117,7 +122,9 @@ const processStreams = (result, file, user_langs) => {
|
|||
langs.push(languages.alpha2ToAlpha3B(langsTemp));
|
||||
|
||||
// Some console reporting for clarification of what the plugin is using and reporting.
|
||||
response.infoLog += `Original language: ${langsTemp}, Using code: ${languages.alpha2ToAlpha3B(langsTemp)}\n`;
|
||||
response.infoLog += `Original language: ${langsTemp}, Using code: ${languages.alpha2ToAlpha3B(
|
||||
langsTemp,
|
||||
)}\n`;
|
||||
|
||||
if (user_langs) {
|
||||
langs = langs.concat(user_langs);
|
||||
|
|
@ -150,7 +157,10 @@ const processStreams = (result, file, user_langs) => {
|
|||
} else {
|
||||
tracks.remove.push(streamIndex);
|
||||
response.preset += `-map -0:a:${streamIndex} `;
|
||||
tracks.remLangs += `${languages.getName(stream.tags.language, 'en')}, `;
|
||||
tracks.remLangs += `${languages.getName(
|
||||
stream.tags.language,
|
||||
'en',
|
||||
)}, `;
|
||||
}
|
||||
streamIndex += 1;
|
||||
} else {
|
||||
|
|
@ -177,9 +187,14 @@ const tmdbApi = async (filename, api_key, axios) => {
|
|||
}
|
||||
|
||||
if (fileName) {
|
||||
const result = await axios.get(`https://api.themoviedb.org/3/find/${fileName}?api_key=`
|
||||
+ `${api_key}&language=en-US&external_source=imdb_id`)
|
||||
.then((resp) => (resp.data.movie_results.length > 0 ? resp.data.movie_results[0] : resp.data.tv_results[0]));
|
||||
const result = await axios
|
||||
.get(
|
||||
`https://api.themoviedb.org/3/find/${fileName}?api_key=`
|
||||
+ `${api_key}&language=en-US&external_source=imdb_id`,
|
||||
)
|
||||
.then((resp) => (resp.data.movie_results.length > 0
|
||||
? resp.data.movie_results[0]
|
||||
: resp.data.tv_results[0]));
|
||||
|
||||
if (!result) {
|
||||
response.infoLog += '☒No IMDB result was found. \n';
|
||||
|
|
@ -206,18 +221,7 @@ const parseArrResponse = async (body, filePath, arr) => {
|
|||
}
|
||||
break;
|
||||
case 'sonarr':
|
||||
// filePath = directory the file is in
|
||||
for (let i = 0; i < body.length; i += 1) {
|
||||
if (body[i].path) {
|
||||
const sonarrTemp = body[i].path.replace(/\\/g, '/').split('/');
|
||||
const sonarrFolder = sonarrTemp[sonarrTemp.length - 1];
|
||||
const tdarrTemp = filePath.split('/');
|
||||
const tdarrFolder = tdarrTemp[tdarrTemp.length - 2];
|
||||
if (sonarrFolder === tdarrFolder) {
|
||||
return body[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return body.series;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -248,9 +252,13 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => {
|
|||
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}`)
|
||||
await axios
|
||||
.get(
|
||||
`http://${inputs.radarr_url}/api/v3/movie?apiKey=${inputs.radarr_api_key}`,
|
||||
)
|
||||
.then((resp) => resp.data),
|
||||
file.meta.FileName, 'radarr',
|
||||
file.meta.FileName,
|
||||
'radarr',
|
||||
);
|
||||
|
||||
if (radarrResult) {
|
||||
|
|
@ -267,9 +275,13 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => {
|
|||
if (tmdbResult) break;
|
||||
if (inputs.sonarr_api_key) {
|
||||
sonarrResult = await parseArrResponse(
|
||||
await axios.get(`http://${inputs.sonarr_url}/api/series?apikey=${inputs.sonarr_api_key}`)
|
||||
await axios
|
||||
.get(
|
||||
`http://${inputs.sonarr_url}/api/v3/parse?apikey=${inputs.sonarr_api_key}&title=${file.meta.FileName}`,
|
||||
)
|
||||
.then((resp) => resp.data),
|
||||
file.meta.Directory, 'sonarr',
|
||||
file.meta.Directory,
|
||||
'sonarr',
|
||||
);
|
||||
|
||||
if (sonarrResult) {
|
||||
|
|
@ -285,15 +297,23 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => {
|
|||
}
|
||||
|
||||
if (tmdbResult) {
|
||||
const tracks = processStreams(tmdbResult, file, inputs.user_langs ? inputs.user_langs.split(',') : '');
|
||||
const tracks = processStreams(
|
||||
tmdbResult,
|
||||
file,
|
||||
inputs.user_langs ? inputs.user_langs.split(',') : '',
|
||||
);
|
||||
|
||||
if (tracks.remove.length > 0) {
|
||||
if (tracks.keep.length > 0) {
|
||||
response.infoLog += `☑Removing tracks with languages: ${tracks.remLangs.slice(0, -2)}. \n`;
|
||||
response.infoLog += `☑Removing tracks with languages: ${tracks.remLangs.slice(
|
||||
0,
|
||||
-2,
|
||||
)}. \n`;
|
||||
response.processFile = true;
|
||||
response.infoLog += '\n';
|
||||
} else {
|
||||
response.infoLog += '☒Cancelling plugin otherwise all audio tracks would be removed. \n';
|
||||
response.infoLog
|
||||
+= '☒Cancelling plugin otherwise all audio tracks would be removed. \n';
|
||||
}
|
||||
} else {
|
||||
response.infoLog += '☒No audio tracks to be removed. \n';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue