Created
January 2, 2024 16:03
-
-
Save PierreDurrr/5e1af7993e15f989b151fded811c5545 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable */ | |
module.exports.dependencies = ['node-fetch@2']; | |
// tdarrSkipTest | |
const details = () => ({ | |
id: "Tdarr_Plugin_henk_notify_radarr_or_sonarr_of_file_change", | |
Stage: "Post-processing", | |
Name: "Notify Radarr or Sonarr of file change", | |
Type: "Video", | |
Operation: "Transcode", | |
Description: `Will force refresh of movie/series. \n\n`, | |
Version: "1.00", | |
Tags: "post-processing,configurable", | |
Inputs: [ | |
{ | |
name: 'arr', | |
type: 'string', | |
defaultValue: 'radarr', | |
inputUI: { | |
type: 'dropdown', | |
options: ['radarr', 'sonarr'], | |
}, | |
tooltip: 'Specify which arr to use.', | |
}, | |
{ | |
name: 'arr_api_key', | |
type: 'string', | |
defaultValue: '', | |
inputUI: { | |
type: 'text', | |
}, | |
tooltip: 'Input your arr api key here.', | |
}, | |
{ | |
name: 'arr_host', | |
type: 'string', | |
defaultValue: 'http://192.168.1.1:7878', | |
inputUI: { | |
type: 'text', | |
}, | |
tooltip: 'Input your arr host here.' | |
+ '\\nExample:\\n' | |
+ 'http://192.168.1.1:7878\\n' | |
+ 'http://192.168.1.1:8989\\n' | |
+ 'https://radarr.domain.com\\n' | |
+ 'https://sonarr.domain.com\\n', | |
} | |
], | |
}); | |
// eslint-disable-next-line no-unused-vars | |
const plugin = async (file, librarySettings, inputs, otherArguments) => { | |
const lib = require('../methods/lib')(); | |
// eslint-disable-next-line no-unused-vars,no-param-reassign | |
inputs = lib.loadDefaultValues(inputs, details); | |
const fetch = require('node-fetch'); | |
const response = { | |
processFile: false, | |
removeFromDB: false, | |
infoLog: "" | |
}; | |
const arrHost = inputs.arr_host.endsWith('/') ? inputs.arr_host.slice(0, -1) : inputs.arr_host; | |
const headers = { | |
'Content-Type': 'application/json', | |
'X-Api-Key': inputs.arr_api_key, | |
'Accept': 'application/json' | |
}; | |
response.infoLog += 'Going to force scan \n'; | |
if (inputs.arr === 'radarr') { | |
response.infoLog += `Refreshing Radarr... \n`; | |
const movie = await fetch(`${arrHost}/api/v3/parse?title=${encodeURIComponent(file.meta.FileName)}`, { | |
method: "GET", | |
headers | |
}); | |
const movieId = (await movie.json()).movie.movieFile.movieId; | |
await fetch(`${arrHost}/api/v3/command`, { | |
method: "POST", | |
headers, | |
body: JSON.stringify({ | |
name: 'RefreshMovie', | |
movieIds: [movieId], | |
}), | |
}); | |
response.infoLog += `✔ Refreshed movie ${movieId} in Radarr. `; | |
return response; | |
} | |
if (inputs.arr === 'sonarr') { | |
response.infoLog += `Refreshing Sonarr... \n`; | |
const series = await fetch(`${arrHost}/api/v3/parse?title=${encodeURIComponent(file.meta.FileName)}`, { | |
method: "GET", | |
headers | |
}); | |
const seriesId = (await series.json()).data.series.id; | |
await fetch(`${arrHost}/api/v3/command`, { | |
method: "POST", | |
headers, | |
body: JSON.stringify({ | |
name: 'RefreshSeries', | |
seriesId, | |
}), | |
}); | |
response.infoLog += `✔ Refreshed series ${seriesId} in Sonarr. `; | |
return response; | |
} | |
response.infoLog += "No arr specified."; | |
return response; | |
}; | |
module.exports.details = details; | |
module.exports.plugin = plugin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment