Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeNiX HandBrake UI Basic Options AMD #681

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions Collected/Martin_Plugin_001_send_discord_notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const details = () => ({
id: 'Martin_Plugin_001_send_discord_notification',
Stage: 'Post-processing',
Name: 'Send Discord Notification',
Type: 'Video',
Operation: 'Notify',
Description: 'Sends a notification to Discord',
Version: '1.0',
Tags: 'post-processing,configurable',
Inputs: [
{
name: 'discord_webhook_url',
type: 'string',
inputUI: {
type: 'text',
},
tooltip: 'The Discord webhook URL',
},
{
name: 'discord_message',
type: 'string',
defaultValue: 'The file transcoding is finished',
inputUI: {
type: 'text',
},
tooltip: `The message to send to Discord. Use placeholders to use information from the file.
\\nExample:\\n
The file "{name}" has been transcoded to "{format}"
Currently available placeholders are {name} and {format}`,
}
],
});

const plugin = (file, librarySettings, inputs, otherArguments) => {
const lib = require('../methods/lib')();
inputs = lib.loadDefaultValues(inputs, details);

const response = {
file,
removeFromDB: false,
updateDB: false,
processFile: false,
infoLog: '',
};

inputs.discord_message = inputs.discord_message.replace('{name}', file.meta.FileName);
inputs.discord_message = inputs.discord_message.replace('{format}', file.container);

fetch(inputs.discord_webhook_url, {
body: JSON.stringify({
content: inputs.discord_message,
}),
headers: {
"Content-Type": "application/json",
},
method: "POST",
})
.then(function (res) {
console.log('Discord notification sent');
response.infoLog += 'Discord notification sent\n';
})
.catch(function (res) {
console.log('Discord notification failed');
response.infoLog += 'Discord notification failed\n';
});

return response;
};

module.exports.details = details;
module.exports.plugin = plugin;
65 changes: 65 additions & 0 deletions Collected/Martin_Plugin_002_extract_cover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const details = () => ({
id: 'Martin_Plugin_002_extract_cover',
Stage: 'Pre-processing',
Name: 'Extract cover image if existing',
Type: 'Video',
Operation: 'Extraction',
Description: 'If it exist, the cover image is extracted from the file and saved as a separate file. The video file is untouched.',
Version: '1.0',
Tags: 'pre-processing,configurable',
Inputs: [
{
name: 'storage_path',
type: 'string',
inputUI: {
type: 'text',
},
tooltip: 'The path to the storage folder',
},
],
});


const plugin = (file, librarySettings, inputs, otherArguments) => {
const lib = require('../methods/lib')();
inputs = lib.loadDefaultValues(inputs, details);

const response = {
file,
removeFromDB: false,
updateDB: false,
processFile: false,
infoLog: '',
};

const fs = require('fs');
const path = require('path');
const fileName = path.parse(otherArguments.originalLibraryFile.meta.FileName).name;
const coverImagePath = path.join(inputs.storage_path, fileName + '.jpg');
if (fs.existsSync(coverImagePath)) {
response.infoLog += 'Cover image already extracted. Skipping.\n';
return response;
}


for (const stream of file.ffProbeData.streams) {
if (stream.disposition.attached_pic == 1) {
response.processFile = true;
response.preset = `<io> -map 0:v -map -0:V -c copy "${coverImagePath}" -map 0 -c copy `;
response.container = `.` + file.container;
response.handBrakeMode = false;
response.FFmpegMode = true;
response.reQueueAfter = true;
response.infoLog += 'Found cover image in file. Extracting it.\n';
return response;
}
}

response.infoLog += 'No cover image found in file. Skipping.\n';

return response;
};


module.exports.details = details;
module.exports.plugin = plugin;
81 changes: 81 additions & 0 deletions Collected/Martin_Plugin_003_add_cover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const details = () => ({
id: 'Martin_Plugin_003_add_cover',
Stage: 'Pre-processing',
Name: 'Add cover image if available',
Type: 'Video',
Operation: 'Extraction',
Description: 'If an image exist with the same as the video, it will be added to the video file. The image file is untouched.',
Version: '1.0',
Tags: 'pre-processing,configurable',
Inputs: [
{
name: 'storage_path',
type: 'string',
inputUI: {
type: 'text',
},
tooltip: 'The path to the storage folder',
},
],
});


const plugin = (file, librarySettings, inputs, otherArguments) => {
const lib = require('../methods/lib')();
inputs = lib.loadDefaultValues(inputs, details);

const response = {
file,
removeFromDB: false,
updateDB: false,
processFile: false,
infoLog: '',
};

const fs = require('fs');
const path = require('path');
const fileName = path.parse(otherArguments.originalLibraryFile.meta.FileName).name;
const coverImagePath = path.join(inputs.storage_path, fileName + '.jpg');
if (!fs.existsSync(coverImagePath)) {
response.infoLog += 'Cover image not found. Skipping.\n';
return response;
}

// Use execSync to run the ffmpeg command
const execSync = require('child_process').execSync;
const ffmpegPath = otherArguments.ffmpegPath;

// Check if the video file already has a cover image
for (const stream of file.ffProbeData.streams) {
if (stream.disposition.attached_pic == 1) {
response.infoLog += 'Video file already has a cover image. Skipping.\n';
return response;
}
}

response.infoLog += 'Adding cover image to video file\n';

// Add the cover image to the video file
let command;
if (file.container == 'mp4') {
command = `"${ffmpegPath}" -i "${file.file}" -i "${coverImagePath}" -map 0 -map 1 -c copy -disposition:1 attached_pic "${file.file}_temp.${file.container}"`;
} else if (file.container == 'mkv') {
command = `"${ffmpegPath}" -i "${file.file}" -attach "${coverImagePath}" -metadata:s:t mimetype=image/jpeg -c copy "${file.file}_temp.${file.container}"`;
} else {
response.infoLog += 'Video file format not supported. Skipping.\n';
return response;
}
execSync(command);

// Delete the original video file
fs.unlinkSync(file.file);

// Rename the new video file to the original name
fs.renameSync(`${file.file}_temp.${file.container}`, file.file);

return response;
};


module.exports.details = details;
module.exports.plugin = plugin;
4 changes: 4 additions & 0 deletions Collected/ReadMe.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Here I keep an collection of Plugins Found on the Internet
Some are modified some are Original as is.
I kept author info original,
credits go to original authors
Loading