Tdarr_Plugins/Community/Tdarr_Plugin_z80t_keep_original_date.js
HaveAGitGat 2a0a7e1bfc
Add new tests (#311)
* 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
2022-05-22 18:32:59 +02:00

160 lines
4.6 KiB
JavaScript

module.exports.dependencies = [
'axios',
'path-extra',
'touch',
];
// tdarrSkipTest
const details = () => ({
id: 'Tdarr_Plugin_z80t_keep_original_date',
Stage: 'Post-processing',
Name: 'Keep original file dates and times after transcoding',
Type: 'Video',
Operation: 'Transcode',
Description: 'This plugin copies the original file dates and times to the transcoded file \n\n',
Version: '1.10',
Tags: 'post-processing,dates,date',
Inputs: [{
name: 'server',
type: 'string',
defaultValue: '192.168.1.100',
inputUI: {
type: 'text',
},
tooltip: `IP address or hostname of the server assigned to this node, will be used for API requests.
If you are running nodes within Docker you should use the server IP address rather than the name.
\\nExample:\\n
tdarrserver
\\nExample:\\n
192.168.1.100`,
}, {
name: 'extensions',
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
},
tooltip: `When files are trans-coded the file extension may change,
enter a list of extensions to try and match the original file with in the database after trans-coding.
Default is the list of container types from library settings. The list will be searched in order and
the extension of the original file will always be checked first before the list is used.
\\nExample:\\n
mkv,mp4,avi`,
},
{
name: 'log',
type: 'boolean',
defaultValue: false,
inputUI: {
type: 'dropdown',
options: [
'false',
'true',
],
},
tooltip: `Write log entries to console.log. Default is false.
\\nExample:\\n
true`,
},
],
});
// 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);
// eslint-disable-next-line import/no-unresolved
const axios = require('axios');
// eslint-disable-next-line import/no-unresolved
const touch = require('touch');
// eslint-disable-next-line import/no-unresolved
const path = require('path-extra');
function log(msg) {
if (inputs.log === true) {
// eslint-disable-next-line no-console
console.log(msg);
}
}
async function getFileData(filePath, extensions, server) {
const originalExtension = path.extname(filePath).split('.')[1];
if (extensions.indexOf(originalExtension) > -1) {
extensions.splice(extensions.indexOf(originalExtension), 1);
}
extensions.unshift(originalExtension);
let httpResponse = null;
for (let i = 0; i < extensions.length; i += 1) {
const fileName = path.replaceExt(filePath, `.${extensions[i]}`);
log(`Fetching file object for ${fileName}...`);
// eslint-disable-next-line no-await-in-loop
httpResponse = await axios.post(`http://${server}:8265/api/v2/search-db`, {
data: {
string: fileName,
lessThanGB: 10000,
greaterThanGB: 0,
},
});
if (httpResponse.status === 200) {
if (httpResponse.data.length > 0) {
log(`Got response for ${fileName}`);
return httpResponse;
}
log(`Response for ${fileName} is empty`);
} else {
log(`API request for ${filePath} failed.`);
}
}
log('Could not get file info from API, giving up.');
return httpResponse;
}
const responseData = {
file,
removeFromDB: false,
updateDB: false,
infoLog: '',
};
try {
if (!inputs.server || inputs.server.trim() === '') {
responseData.infoLog += 'Tdarr server name/IP not configured in library transcode options\n';
return responseData;
}
log('Waiting 5 seconds...');
let { extensions } = inputs;
if (!extensions || extensions.trim() === '') {
extensions = librarySettings.containerFilter;
}
extensions = extensions.split(',');
await new Promise((resolve) => setTimeout(resolve, 5000));
const response = await getFileData(file._id, extensions, inputs.server);
if (response.data.length > 0) {
log('Changing date...');
touch.sync(file._id, { time: Date.parse(response.data[0].statSync.mtime), force: true });
log('Done.');
responseData.infoLog += 'File timestamps updated or match original file\n';
return responseData;
}
responseData.infoLog += `Could not find file using API using ${inputs.server}\n`;
return responseData;
} catch (err) {
log(err);
}
return responseData;
};
module.exports.details = details;
module.exports.plugin = plugin;