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

bugfix for ffmpegCommandRemoveStreamByProperty removes all streams #688

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var details = function () { return ({
inputUI: {
type: 'text',
},
tooltip: "\n Enter one stream property to check.\n \n \\nExample:\\n\n codec_name\n\n \\nExample:\\n\n tags.language\n ",
tooltip: "\n Enter one stream property to check. \n To resolve 'Subtitle codec 94213 is not supported' error, leave as codec_name.\n \n \\nExample:\\n\n codec_name\n\n \\nExample:\\n\n tags.language\n ",
},
{
label: 'Values To Remove',
Expand All @@ -34,7 +34,7 @@ var details = function () { return ({
inputUI: {
type: 'text',
},
tooltip: "\n Enter values of the property above to remove. For example, if removing by codec_name, could enter ac3,aac:\n \n \\nExample:\\n\n ac3,aac\n ",
tooltip: "\n Enter values of the property above to remove. For example, if removing by codec_name, could enter ac3,aac. \n To resolve 'Subtitle codec 94213 is not supported' error, enter mov_text.\n \n \\nExample:\\n\n ac3,aac\n ",
},
{
label: 'Condition',
Expand Down Expand Up @@ -66,10 +66,13 @@ var plugin = function (args) {
args.inputs = lib.loadDefaultValues(args.inputs, details);
(0, flowUtils_1.checkFfmpegCommandInit)(args);
var propertyToCheck = String(args.inputs.propertyToCheck).trim();
var valuesToRemove = String(args.inputs.valuesToRemove).trim().split(',').map(function (item) { return item.trim(); });
var valuesToRemove = String(args.inputs.valuesToRemove).trim().split(',').map(function (item) { return item.trim().toLowerCase(); });
var condition = String(args.inputs.condition);
args.variables.ffmpegCommand.streams.forEach(function (stream) {
var _a;
// Skip stream index 0, this is the video stream
if (stream.index === 0)
return;
var target = '';
if (propertyToCheck.includes('.')) {
var parts = propertyToCheck.split('.');
Expand All @@ -79,17 +82,23 @@ var plugin = function (args) {
target = stream[propertyToCheck];
}
if (target) {
var prop = String(target).toLowerCase();
for (var i = 0; i < valuesToRemove.length; i += 1) {
var val = valuesToRemove[i].toLowerCase();
var prefix = "Removing stream index ".concat(stream.index, " because ").concat(propertyToCheck, " of ").concat(prop);
if (condition === 'includes' && prop.includes(val)) {
args.jobLog("".concat(prefix, " includes ").concat(val, "\n"));
// eslint-disable-next-line no-param-reassign
stream.removed = true;
}
else if (condition === 'not_includes' && !prop.includes(val)) {
args.jobLog("".concat(prefix, " not_includes ").concat(val, "\n"));
var prop_1 = String(target).toLowerCase();
var prefix_1 = "Removing stream index ".concat(stream.index, " because ").concat(propertyToCheck, " of ").concat(prop_1);
if (condition === 'includes') {
// Check each value individually for an exact match
valuesToRemove.forEach(function (val) {
if (prop_1 === val) {
args.jobLog("".concat(prefix_1, " includes exact match ").concat(val, "\n"));
// eslint-disable-next-line no-param-reassign
stream.removed = true;
}
});
}
else if (condition === 'not_includes') {
// Check the array as a whole for no exact matches
var noneMatch = valuesToRemove.every(function (val) { return prop_1 !== val; });
if (noneMatch) {
args.jobLog("".concat(prefix_1, " does not include any exact matches of [").concat(valuesToRemove.join(', '), "]\n"));
// eslint-disable-next-line no-param-reassign
stream.removed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const details = (): IpluginDetails => ({
},
tooltip:
`
Enter one stream property to check.
Enter one stream property to check.
To resolve 'Subtitle codec 94213 is not supported' error, leave as codec_name.

\\nExample:\\n
codec_name
Expand All @@ -48,7 +49,8 @@ const details = (): IpluginDetails => ({
},
tooltip:
`
Enter values of the property above to remove. For example, if removing by codec_name, could enter ac3,aac:
Enter values of the property above to remove. For example, if removing by codec_name, could enter ac3,aac.
To resolve 'Subtitle codec 94213 is not supported' error, enter mov_text.

\\nExample:\\n
ac3,aac
Expand Down Expand Up @@ -88,10 +90,13 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
checkFfmpegCommandInit(args);

const propertyToCheck = String(args.inputs.propertyToCheck).trim();
const valuesToRemove = String(args.inputs.valuesToRemove).trim().split(',').map((item) => item.trim());
const valuesToRemove = String(args.inputs.valuesToRemove).trim().split(',').map((item) => item.trim().toLowerCase());
const condition = String(args.inputs.condition);

args.variables.ffmpegCommand.streams.forEach((stream) => {
// Skip stream index 0, this is the video stream
if (stream.index === 0) return;

let target = '';
if (propertyToCheck.includes('.')) {
const parts = propertyToCheck.split('.');
Expand All @@ -102,15 +107,21 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {

if (target) {
const prop = String(target).toLowerCase();
for (let i = 0; i < valuesToRemove.length; i += 1) {
const val = valuesToRemove[i].toLowerCase();
const prefix = `Removing stream index ${stream.index} because ${propertyToCheck} of ${prop}`;
if (condition === 'includes' && prop.includes(val)) {
args.jobLog(`${prefix} includes ${val}\n`);
// eslint-disable-next-line no-param-reassign
stream.removed = true;
} else if (condition === 'not_includes' && !prop.includes(val)) {
args.jobLog(`${prefix} not_includes ${val}\n`);
const prefix = `Removing stream index ${stream.index} because ${propertyToCheck} of ${prop}`;
if (condition === 'includes') {
// Check each value individually for an exact match
valuesToRemove.forEach((val) => {
if (prop === val) {
args.jobLog(`${prefix} includes exact match ${val}\n`);
// eslint-disable-next-line no-param-reassign
stream.removed = true;
}
});
} else if (condition === 'not_includes') {
// Check the array as a whole for no exact matches
const noneMatch = valuesToRemove.every((val) => prop !== val);
if (noneMatch) {
args.jobLog(`${prefix} does not include any exact matches of [${valuesToRemove.join(', ')}]\n`);
// eslint-disable-next-line no-param-reassign
stream.removed = true;
}
Expand Down