mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 23:48:15 -07:00
* Add new tests * Add tdarrSkipTest logic * Add Tdarr_Plugin_00td_action_add_audio_stream_codec test * Add Tdarr_Plugin_00td_action_handbrake_basic_options test * Add Tdarr_Plugin_00td_action_handbrake_ffmpeg_custom test * Add Tdarr_Plugin_00td_action_keep_one_audio_stream test * Fix lint * Fix reorder streams bug * Add Tdarr_Plugin_00td_action_re_order_all_streams_v2 test * Add Tdarr_Plugin_00td_action_remux_container test * Add Tdarr_Plugin_00td_action_standardise_audio_stream_codecs test * Lint * Add Tdarr_Plugin_00td_filter_by_bitrate test * Add Tdarr_Plugin_00td_filter_by_resolution test * Add Tdarr_Plugin_00td_filter_by_size test * Log all errors together, use chalk * Add Tdarr_Plugin_075a_FFMPEG_HEVC_Generic test * Add Tdarr_Plugin_075a_Transcode_Customisable test * Add Tdarr_Plugin_075b_FFMPEG_HEVC_Generic_Video_Audio_Only test * Add Tdarr_Plugin_075c_FFMPEG_HEVC_Generic_Video_Audio_Only_CRF20 test * Add Tdarr_Plugin_075d_FFMPEG_HEVC_GPU_Generic_Video_Audio_Only_CRF20 test * Add Tdarr_Plugin_076a_re_order_audio_streams test * Add chalk * Add Tdarr_Plugin_076b_re_order_subtitle_streams * Add Tdarr_Plugin_077b_HandBrake_NVENC_264_Configurable test * Add Tdarr_Plugin_a8hc_HaveAGitGat_HandBrake_H264_VeryFast1080p30 test * Add Tdarr_Plugin_a9hc_HaveAGitGat_HandBrake_H264_Fast1080p30 test * Add Tdarr_Plugin_a9hd_FFMPEG_Transcode_Specific_Audio_Stream_Codecs test * Update qsv to vaapi (will handle input at later date) * Add Tdarr_Plugin_a9he_New_file_size_check test * useCloneDeep * Add Tdarr_Plugin_a37x_Drawmonster_MP4_No_Title_Meta test * Add Tdarr_Plugin_A47j_FFMPEG_NVENC_HEVC_Video_Only test * Add Tdarr_Plugin_b38x_Nosirus_h265_aac_no_meta test * Add Tdarr_Plugin_b39x_the1poet_surround_sound_to_ac3 test * Add Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC test * Add Tdarr_Plugin_c0r1_SetDefaultAudioStream test * Lint * Add Tdarr_Plugin_d5d3_iiDrakeii_FFMPEG_NVENC_Tiered_MKV test * Add Tdarr_Plugin_d5d4_iiDrakeii_Not_A_Video_Mjpeg_Fix test * Add Tdarr_Plugin_da11_Dallas_FFmpeg_Presets_H264_MP4 test * Tdarr_Plugin_DOOM_NVENC_Tiered_MKV_CleanAll test * Remove logging * Add Tdarr_Plugin_drdd_standardise_all_in_one test * Add Tdarr_Plugin_e3jc_Tharic_H.264_MKV_480p30_No_Subs_No_Title_Meta test * Add Tdarr_Plugin_e3jd_Tharic_H.264_MKV_720p30_No_Subs_No_Title_Meta test * Add Tdarr_Plugin_e3je_Tharic_H.264_MKV_1080p30_No_Subs_No_Title_Meta test * Add Tdarr_Plugin_e5c3_CnT_Keep_Preferred_Audio test * Add Tdarr_Plugin_ER01_Transcode audio and video with HW (PC and Mac) test * Add Tdarr_Plugin_fd5T_Sparticus_4K_AC3_No_Subs test * Add Tdarr_Plugin_Greg_MP3_FFMPEG_CPU test * Add Tdarr_Plugin_henk_Add_Specific_Audio_Codec test * Add Tdarr_Plugin_hk75_Drawmonster_MP4_AAC_No_Subs_No_metaTitle test * Add Tdarr_Plugin_hk76_GilbN_MP4_AAC_No_metaTitle test * Add outputModify func * Base tests on linux for now * Add Tdarr_Plugin_jeons001_Downmix_to_stereo_and_apply_DRC test * Add Tdarr_Plugin_lmg1_Reorder_Streams test * Add Tdarr_Plugin_MC93_Migz1FFMPEG test * Add Tdarr_Plugin_MC93_Migz1FFMPEG_CPU test * Add Tdarr_Plugin_MC93_Migz1Remux test * Add Tdarr_Plugin_MC93_Migz2CleanTitle test * Add Tdarr_Plugin_MC93_Migz2CleanTitle test * Add Tdarr_Plugin_MC93_Migz3CleanAudio test * Add Tdarr_Plugin_MC93_Migz4CleanSubs test * Add Tdarr_Plugin_MC93_Migz5ConvertAudio test * Add Tdarr_Plugin_MC93_Migz6OrderStreams test * Add Tdarr_Plugin_MC93_MigzImageRemoval test * Add Tdarr_Plugin_MP01_MichPasCleanSubsAndAudioCodecs test * Add Tdarr_Plugin_Mthr_VaapiHEVCTranscode test * Add Tdarr_Plugin_nc7x_Drawmonster_No_Title_Meta test * Add Tdarr_Plugin_r002_rootuser_FFMPEG_HQ_HEVC_MKV_Animation test * Add Tdarr_Plugin_raf4_Floorpie_FFmpeg_Tiered_HEVC_MKV test * Add Tdarr_Plugin_s7x8_winsome_h265 test
222 lines
7.4 KiB
JavaScript
222 lines
7.4 KiB
JavaScript
// tdarrSkipTest
|
|
const details = () => ({
|
|
id: 'Tdarr_Plugin_goof1_URL_Plex_Refresh',
|
|
Stage: 'Post-processing',
|
|
Name: 'Refresh Plex via URL',
|
|
Type: 'Video',
|
|
Operation: 'Transcode',
|
|
Description: `Refreshes folder containing the current file in Plex so changes are picked up properly
|
|
without the use of external applications or other dockers`,
|
|
Version: '1.0',
|
|
Tags: '3rd party,post-processing,configurable',
|
|
|
|
Inputs: [
|
|
{
|
|
name: 'Url_Protocol',
|
|
type: 'string',
|
|
defaultValue: 'http',
|
|
inputUI: {
|
|
type: 'dropdown',
|
|
options: [
|
|
'http',
|
|
'https',
|
|
],
|
|
},
|
|
tooltip: `
|
|
Specified the type of request to make, http:// or https://
|
|
\\nExample:\\n
|
|
http
|
|
\\nExample:\\n
|
|
https`,
|
|
},
|
|
{
|
|
name: 'Plex_Url',
|
|
type: 'string',
|
|
defaultValue: 'localhost',
|
|
inputUI: {
|
|
type: 'text',
|
|
},
|
|
tooltip: `
|
|
Enter the IP address/URL for Plex.
|
|
\\nExample:\\n
|
|
192.168.0.10
|
|
\\nExample:\\n
|
|
subdomain.domain.tld`,
|
|
},
|
|
{
|
|
name: 'Plex_Port',
|
|
type: 'number',
|
|
defaultValue: 32400,
|
|
inputUI: {
|
|
type: 'text',
|
|
},
|
|
tooltip: `
|
|
The port required to access Plex on the network (may not be required if used with reverse proxy)
|
|
\\nExample:\\n
|
|
32400`,
|
|
},
|
|
{
|
|
name: 'Plex_Token',
|
|
type: 'string',
|
|
defaultValue: '',
|
|
inputUI: {
|
|
type: 'text',
|
|
},
|
|
tooltip: `
|
|
Auth token that is used to authenticate this commend on the Plex server. \\n
|
|
Instructions for retrieving the token can be found here. \\n\\n
|
|
https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/
|
|
\\nExample:\\n
|
|
ssQ_eXYYH3hxq3dviDdR`,
|
|
},
|
|
{
|
|
name: 'Library_Key',
|
|
type: 'string',
|
|
defaultValue: '1',
|
|
inputUI: {
|
|
type: 'text',
|
|
},
|
|
tooltip: `
|
|
Library key for the library in Plex where this content is displayed. \\n
|
|
This number lets Plex know which library contains the current path needing a refresh. \\n
|
|
See the below page under the 'Listing Defined Libraries' heading to find the key. \\n
|
|
|
|
https://support.plex.tv/articles/201638786-plex-media-server-url-commands/ \\n
|
|
|
|
*Note* If this number is wrong everything will behave as though it's
|
|
working great but the folder will simply not be scanned. \\n\\n
|
|
|
|
\\nExample:\\n
|
|
29`,
|
|
},
|
|
{
|
|
name: 'Plex_Path',
|
|
type: 'string',
|
|
defaultValue: '',
|
|
inputUI: {
|
|
type: 'text',
|
|
},
|
|
tooltip: `
|
|
If the Plex path is not the same as the local path you may need to sub parts of the path. \\n
|
|
Here is where you would enter the path that Plex uses to find the file. \\n
|
|
You would only enter the part of the path that is different. \\n\\n
|
|
If your TDarr path is: \\n
|
|
/media/local/tv/The Best Show Evaaaarr/Season 2/The Best Show Evaaaarr - S02E31 - Heck Yea HDTV-720p.mp4\\n\\n
|
|
|
|
And the Plex path to the file is: \\n
|
|
/data/tv/The Best Show Evaaaarr/Season 2/The Best Show Evaaaarr - S02E31 - Heck Yea HDTV-720p.mp4 \\n
|
|
then part you would enter here is:
|
|
\\nExample:\\n
|
|
/data/`,
|
|
},
|
|
{
|
|
name: 'Tdarr_Path',
|
|
type: 'string',
|
|
defaultValue: '',
|
|
inputUI: {
|
|
type: 'text',
|
|
},
|
|
tooltip: `
|
|
If the Plex path is not the same as the local path you may need to sub parts of the path. \\n
|
|
Here is where you would enter the path that Plex uses to find the file. \\n
|
|
You would only enter the part of the path that is different. \\n
|
|
If your TDarr path is: \\n
|
|
/media/local/tv/The Best Show Evaaaarr/Season 2/The Best Show Evaaaarr - S02E31 - Heck Yea HDTV-720p.mp4 \\n\\n
|
|
|
|
And the Plex path to the file is:\\n
|
|
/data/tv/The Best Show Evaaaarr/Season 2/The Best Show Evaaaarr - S02E31 - Heck Yea HDTV-720p.mp4\\n
|
|
then part you would enter here is:
|
|
\\nExample:\\n
|
|
/media/local/`,
|
|
},
|
|
],
|
|
});
|
|
|
|
function checkReply(response, statusCode, urlNoToken) {
|
|
if (statusCode === 200) {
|
|
response.infoLog += '☒ Above shown folder scanned in Plex! \n';
|
|
} else if (statusCode === 401) {
|
|
response.infoLog += 'Plex replied that the token was not authorized on this server \n';
|
|
} else if (statusCode === 404) {
|
|
response.infoLog += `404 Plex not found, http/https is set properly? The URL used was
|
|
${urlNoToken}[redacted] \n`;
|
|
} else {
|
|
response.infoLog += `There was an issue reaching Plex. The URL used was
|
|
${urlNoToken}[redacted] \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 http = require('http');
|
|
const https = require('https');
|
|
|
|
const response = {
|
|
file,
|
|
removeFromDB: false,
|
|
updateDB: false,
|
|
processFile: false,
|
|
infoLog: '',
|
|
};
|
|
|
|
const type = inputs.Url_Protocol;
|
|
const url = inputs.Plex_Url;
|
|
const port = inputs.Plex_Port;
|
|
const token = inputs.Plex_Token;
|
|
const key = inputs.Library_Key;
|
|
const plexPath = inputs.Plex_Path;
|
|
const tdarrPath = inputs.Tdarr_Path;
|
|
|
|
if (!type || !url || !token || !key) {
|
|
throw new Error('Url_Protocol, Plex_Url, Plex_Token, and Library_Key are all required');
|
|
}
|
|
|
|
let filePath = file.file.substring(0, file.file.lastIndexOf('/'));
|
|
|
|
if ((tdarrPath && !plexPath) || (tdarrPath && plexPath)) {
|
|
// tdarr: /local/tv && plex: ''/tv || tdarr: /local/tv && plex: /data/tv
|
|
filePath = filePath.replace(tdarrPath, plexPath);
|
|
} else if (!tdarrPath && plexPath) {
|
|
// tdarr: ''/tv && plex: /data/tv
|
|
filePath = filePath.replace(/^/, plexPath);
|
|
}
|
|
|
|
response.infoLog += `Attempting to update Plex path ${filePath} in library ${key}\n`;
|
|
|
|
const portIfUsed = port ? `:${port}` : '';
|
|
const urlNoToken = `${type}://${url}${portIfUsed}/library/sections/${key}/refresh?`
|
|
+ `path=${encodeURIComponent(filePath)}&X-Plex-Token=`;
|
|
|
|
if (type === 'http') {
|
|
await new Promise((resolve) => {
|
|
http.get(urlNoToken + token, (res) => {
|
|
checkReply(response, res.statusCode, urlNoToken);
|
|
resolve();
|
|
}).on('error', (e) => {
|
|
response.infoLog += `We have encountered an error: ${e}`;
|
|
resolve();
|
|
});
|
|
});
|
|
return response;
|
|
} if (type === 'https') {
|
|
await new Promise((resolve) => {
|
|
https.get(urlNoToken + token, { rejectUnauthorized: false }, (res) => {
|
|
checkReply(response, res.statusCode, urlNoToken);
|
|
resolve();
|
|
}).on('error', (e) => {
|
|
response.infoLog += `We have encountered an error: ${e}`;
|
|
resolve();
|
|
});
|
|
});
|
|
return response;
|
|
}
|
|
response.infoLog += `Plex could not be updated, \n
|
|
the Url_Protocol can only be http or https. ${type} is not valid \n`;
|
|
return response;
|
|
};
|
|
|
|
module.exports.details = details;
|
|
module.exports.plugin = plugin;
|