-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tdarr_Plugin_yodog_add_to_radarr_or_sonarr.js
196 lines (171 loc) · 6.25 KB
/
Tdarr_Plugin_yodog_add_to_radarr_or_sonarr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
module.exports.dependencies = ['axios'];
const details = () => ({
id: 'Tdarr_Plugin_yodog_add_to_radarr_or_sonarr',
Stage: 'Post-processing',
Name: 'Add media to Radarr and/or Sonarr',
Type: 'Video',
Operation: 'Transcode',
Description: 'This plugin will try to add the media to Radarr and Sonarr. It will not fail your stack if unsuccessful.',
Version: '2024.02.11.0343',
Tags: '3rd party,post-processing,configurable',
Inputs: [
{
name: 'radarr_enabled',
type: 'boolean',
defaultValue: false,
inputUI: {type: 'dropdown', options: ['false', 'true']},
tooltip: 'try to use radarr',
},
{
name: 'radarr_server',
type: 'string',
defaultValue: '192.168.100.39',
inputUI: {type: 'text'},
tooltip: `
Enter the server address \\n
Example: 192.168.100.39
`,
},
{
name: 'radarr_port',
type: 'string',
defaultValue: '7878',
inputUI: {type: 'text'},
tooltip: `
Enter the port Radarr is using \\n
Example: 7878
`,
},
{
name: 'radarr_api_key',
type: 'string',
defaultValue: '066e4929b5bb4cda8e46e4fbe2e82b9e',
inputUI: {type: 'text'},
tooltip: `
Enter the Radarr API key \\n
Example: 066e4929b5bb4cda8e46e4fbe2e82b9e
`,
},
{
name: 'sonarr_enabled',
type: 'boolean',
defaultValue: false,
inputUI: {type: 'dropdown', options: ['false', 'true']},
tooltip: 'try to use sonarr',
},
{
name: 'sonarr_server',
type: 'string',
defaultValue: '192.168.100.39',
inputUI: {type: 'text'},
tooltip: `
Enter the server address \\n
Example: 192.168.100.39
`,
},
{
name: 'sonarr_port',
type: 'string',
defaultValue: '8989',
inputUI: {type: 'text'},
tooltip: `
Enter the port sonarr is using \\n
Example: 8989
`,
},
{
name: 'sonarr_api_key',
type: 'string',
defaultValue: 'd5ea862d129449c6a6557f632142152a',
inputUI: {type: 'text'},
tooltip: `
Enter the sonarr API key \\n
Example: d5ea862d129449c6a6557f632142152a
`,
},
],
});
const mylog = [];
const response = {
processFile: false,
infoLog: ''
};
const plugin = async (file, librarySettings, inputs, otherArguments) => {
// ---
// plugin libs and required npm packages
// ---
const lib = require('../methods/lib')();
inputs = lib.loadDefaultValues(inputs, details);
const axios = require('axios').default;
// ---
// setup
// ---
const fileNameEncoded = encodeURIComponent(file.meta.FileName);
const radarr_url_srch = `http://${inputs.radarr_server}:${inputs.radarr_port}/api/v3/parse?apikey=${inputs.radarr_api_key}&title=${fileNameEncoded}`;
const sonarr_url_srch = `http://${inputs.sonarr_server}:${inputs.sonarr_port}/api/v3/parse?apikey=${inputs.sonarr_api_key}&title=${fileNameEncoded}`;
const radarr_url_post = `http://${inputs.radarr_server}:${inputs.radarr_port}/api/v3/command?apikey=${inputs.radarr_api_key}`;
const sonarr_url_post = `http://${inputs.sonarr_server}:${inputs.sonarr_port}/api/v3/command?apikey=${inputs.sonarr_api_key}`;
// ---
// lets start the radarr flow if enabled
// ---
if (inputs.radarr_enabled) {
mylog.push('radarr -> enabled in the plugin config');
radarrResult = await axios.get(radarr_url_srch).then((resp) => resp).catch((error) => error);
console.log('radarrResult', radarrResult);
if (radarrResult.data.movie) {
movieId = radarrResult.data.movie.id;
movieTitle = radarrResult.data.movie.title;
mylog.push(`radarr -> found movie with id ${movieId} and title ${movieTitle}`);
await axios.post(radarr_url_post, {name: 'RefreshMovie', movieIds: [movieId]})
.then((response) => {
mylog.push(`radarr -> ${response.data.commandName} ${movieId} ${response.data.status}`);
console.log('response -->', response);
})
.catch((error) => {
mylog.push(`radarr -> could not update movie id ${movieId}`);
console.log('error -->', error);
});
}
else {
mylog.push(`radarr -> movie not found`);
}
}
else {
mylog.push('radarr -> disabled in the plugin config');
}
// ---
// now the sonnar flow if enabled
// ---
if (inputs.sonarr_enabled) {
mylog.push('sonnar -> enabled in the plugin config');
sonarrResult = (await axios.get(sonarr_url_srch).then((resp) => resp.data));
console.log('sonarrResult', sonarrResult);
if (sonarrResult.series) {
seriesId = sonarrResult.series.id;
seriesTitle = sonarrResult.series.title;
mylog.push(`sonarr -> found series with id ${seriesId} and title ${seriesTitle}`);
await axios.post(sonarr_url_post, {name: 'RefreshSeries', seriesId: seriesId})
.then((response) => {
mylog.push(`sonarr -> ${response.data.commandName} ${seriesId} ${response.data.status}`);
console.log('response -->', response);
})
.catch((error) => {
mylog.push(`sonarr -> could not update series id ${seriesId}`);
console.log('error -->', error);
});
}
else {
mylog.push(`sonarr -> series not found`);
}
}
else {
mylog.push('sonnar -> disabled in the plugin config');
}
// ---
// return the response and we are done
// ---
response.infoLog += mylog.join('\n');
return response;
};
module.exports.details = details;
module.exports.plugin = plugin;