Skip to content

Commit

Permalink
Adds a check into the UI if metadata has been updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Agrarvolution committed Feb 23, 2024
1 parent 8e12644 commit 1f159df
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 38 deletions.
109 changes: 82 additions & 27 deletions src/js/ltcCorrection.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const csvVersion = {
};

let lockForm = false;
let failedUpdateCache = [];

$(function () {
onLoaded();
Expand All @@ -59,7 +60,7 @@ $(function () {

const csInterface = new CSInterface();
csInterface.addEventListener(CSInterface.THEME_COLOR_CHANGED_EVENT, onAppThemeColorChanged);
csInterface.addEventListener("com.adobe.csxs.events.agrarvolution.timecodeCorrectionLog", function (e) {
csInterface.addEventListener("com.adobe.csxs.events.agrarvolution.timecodeCorrectionLog", e => {
logger.addLog(e.data.text, e.data.logLevel);
});
csInterface.requestOpenExtension("com.agrarvolution.autoTimecodeCorrection.server", "");
Expand All @@ -69,16 +70,16 @@ $(function () {
settings = loadSettings();
changeSettings(settings);

$('#resetLog').on('click', function (e) {
$('#resetLog').on('click', e => {
logger.clearLog();
});
$('#hideLog').on('click', function (e) {
$('#hideLog').on('click', e => {
$('#logging').prop('checked', false);
settingHandler();
logger.hideLog();
});

$('#reset').on("click", function (e) {
$('#reset').on("click", e => {
e.preventDefault();
changeSettings(defaultSettings);
$('#source')[0].value = "";
Expand All @@ -88,14 +89,14 @@ $(function () {
this.blur();
});

$('input:not(#source, #start)').on("click", function (e) {
$('input:not(#source, #start)').on("click", e => {
if (this.id !== undefined && this.id === 'logging') {
logger.verboseLogging = this.checked;
logger.toggleLog('hidden');
}
settingHandler();
});
$('select').on('change', function (e) {
$('select').on('change', e => {
settingHandler();
})

Expand All @@ -106,7 +107,7 @@ $(function () {
};
}

$('#start').on("click", function (e) {
$('#start').on("click", e => {
e.preventDefault();
if (lockForm) {
return false;
Expand All @@ -127,7 +128,7 @@ $(function () {
}
});

$('#revert').on('click', function (e) {
$('#revert').on('click', e => {
e.preventDefault();
if (lockForm || host !== 'kbrg') {
return false;
Expand All @@ -138,14 +139,28 @@ $(function () {
revertTimecodechanges();
});

$('#csv').on('click', function (e) {
$('#csv').on('click', e => {
e.preventDefault();
if (lockForm || host !== 'kbrg') {
return false;
}
logger.addLog("Exporting timecodes stored in metadata.", Logger.LOG_LEVELS.status);
exportCSV();
});

$('#backToMain').on('click', e => {
$('#statusSection').addClass('hidden');
$('#process').removeClass('hidden');
});

$('#retryFailedUpdates').on('click', e => {
if (failedUpdateCache.length > 0 ) {
logger.addLog('Retrying files that failed to update metadata.', Logger.LOG_LEVELS.status);
timecodeFromArray(failedUpdateCache);
}
$('#backToMain').click();
return true;
});
});

/**
Expand All @@ -160,8 +175,8 @@ function exportCSV() {
};

const csInterface = new CSInterface();
csInterface.evalScript('$.Agrarvolution.timecodeCorrection.exportTimecodeData(' +
JSON.stringify(csObject) + ');', async function (e) {
csInterface.evalScript('$.Agrarvolution.timecodeCorrection.exportTimecodeData(' +
JSON.stringify(csObject) + ');', async e => {
logger.addLog("Timecodes arrived in frontend.", Logger.LOG_LEVELS.status);
try {
e = JSON.parse(e);
Expand Down Expand Up @@ -201,7 +216,7 @@ function revertTimecodechanges() {

const csInterface = new CSInterface();
csInterface.evalScript('$.Agrarvolution.timecodeCorrection.processCEPInput(' +
JSON.stringify(csObject) + ');', function (e) {
JSON.stringify(csObject) + ');', e => {
if (e === 'true') {
logger.addLog("Timecode changes have been reverted. Old values were stored.", Logger.LOG_LEVELS.status);
} else if (e === 'false') {
Expand Down Expand Up @@ -243,7 +258,7 @@ function timecodeFromMetadata() {
};

let csInterface = new CSInterface();
csInterface.evalScript('$.Agrarvolution.timecodeCorrection.processCEPInput(' + JSON.stringify(csObject) + ');', function (e) {
csInterface.evalScript('$.Agrarvolution.timecodeCorrection.processCEPInput(' + JSON.stringify(csObject) + ');', e => {
if (e === 'true') {
logger.addLog("Media has been updated. Process finished. Select the next file to be processed.", Logger.LOG_LEVELS.status);
} else if (e === 'false') {
Expand All @@ -257,19 +272,19 @@ function timecodeFromMetadata() {
* @param {*} file parsed csv
*/
function handleFileLoad(file) {
let timeCodes = [];

try {
timeCodes = checkCSV(file, csvVersion.ttc116);
const timecodes = checkCSV(file, csvVersion.ttc116);
timecodeFromArray(timecodes);
} catch (e) {
logger.addLog(e, Logger.LOG_LEVELS.error);
lockForm = false;
return false;
}
}


function timecodeFromArray(timecodes) {
const tcObject = {
timecodes: timeCodes,
timecodes: timecodes,
searchRecursive: settings.searchRecursive,
searchTarget: settings.searchTarget,
ignoreMediaStart: settings.ignoreMediaStart,
Expand All @@ -279,23 +294,31 @@ function handleFileLoad(file) {
logging: logger.verboseLogging
};

logger.addLog("Media to be updated: " + JSON.stringify(timeCodes), Logger.LOG_LEVELS.info);
logger.addLog("Media to be updated: " + JSON.stringify(timecodes), Logger.LOG_LEVELS.info);

let csInterface = new CSInterface();
const csInterface = new CSInterface();
csInterface.evalScript('$', function (result) {
logger.addLog(result, Logger.LOG_LEVELS.info);
});

csInterface.evalScript('$.Agrarvolution.timecodeCorrection.processCEPInput(' + JSON.stringify(tcObject) + ');', function (e) {
if (e === 'true') {
logger.addLog("Media has been updated. Process finished. Select the next file to be processed.", Logger.LOG_LEVELS.status);
$('#source')[0].value = "";
} else if (e === 'false') {
csInterface.evalScript('$.Agrarvolution.timecodeCorrection.processCEPInput(' + JSON.stringify(tcObject) + ');', e => {
if (e === 'false') {
logger.addLog("Media hasn't been updated. Process stopped.", Logger.LOG_LEVELS.status);
} else {
$('#source')[0].value = "";
try {
let status = JSON.parse(e);

logger.addLog(`${status?.processed || 0} ${status.processed === 1 ? "file has" : "files have"} been updated. Process finished. Select the next file to be processed.`, Logger.LOG_LEVELS.status);

updateFileStatus(status?.results);
} catch (e) {
console.log(e);
}
}

lockForm = false;
});
return true;
}

/**
Expand Down Expand Up @@ -433,7 +456,7 @@ function validateTimeCode(timeString, framerate, fileName, rowNumber, column) {
Logger.LOG_LEVELS.info);
return createZeroTimeCode(column !== csvColumnNumbers.duration, framerate);
} else {
return timeString;
return timeString;
}
}

Expand Down Expand Up @@ -509,6 +532,38 @@ function CSVToArray(strData, strDelimiter) {
return (arrData);
}

function updateFileStatus(fileStatus) {
if (fileStatus === undefined) {
return;
}
const tableContent = $('tbody').empty();
failedUpdateCache = [];

for (const file of fileStatus) {
tableContent.append($(`<tr class=${file.isMatching ? 'dataMatch' : 'dataMismatch'}>
<th>${file.filename}</th>
<td>${file?.fileTC?.text}</td>
<td>${file?.audioTC?.text}</td>
<td>${file?.fileTC?.framerate}</td>
<td>${file?.audioTC?.framerate}</td>
</tr>`));

if (!file.isMatching) {
failedUpdateCache.append({
filename: file.filename,
fileTC: file.fileTC.text,
audioTC: file.audioTC.text,
duration: 0,
framerate: file.audioTC.framerate
});
}
}

if (fileStatus.length) {
$('#statusSection').removeClass('hidden');
$('#process').addClass('hidden');
}
}
/**
* Reads settings from the gui.
* @returns {{logging: boolean, searchRecursive: boolean, ignoreMediaStart: boolean, searchTarger: number}}
Expand Down
3 changes: 3 additions & 0 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ function updateThemeWithAppSkinInfo(appSkinInfo) {

let cssStyle = `:root {
--dark-color: ${panelBackgroundColor};
--table-color-bright: ${lightenDarkenColor(panelBackgroundColor, 10)};
--table-highlight-color: ${lightenDarkenColor(panelBackgroundColor, 50)};
--table-highlight-color-bright: ${lightenDarkenColor(panelBackgroundColor, 60)};
--bright-color: ${lightenDarkenColor(panelBackgroundColor, 150)};
--highlight-color: ${toHex(appSkinInfo.systemHighlightColor)};
--font-size: ${appSkinInfo.baseFontSize}px;
Expand Down
9 changes: 7 additions & 2 deletions src/jsx/KBRG/KBRG_TimecodeCorrection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,16 @@ Agrarvolution.timecodeCorrection = {
if (parameters.timecodes) {
var validatedInput = CacheThumbnails.validateTimecodeArray(parameters.timecodes, Agrarvolution.logToCEP, parameters.logTarget, false);
var checkResults = checkCache.compareTimecodes(validatedInput);
return JSON.stringify(checkResults);
return JSON.stringify({
results: checkResults,
processed: processedMedia
});
}

Agrarvolution.logToCEP("Time formats for " + processedMedia + " media thumbnails have been updated.",
Agrarvolution.logLevels.status, parameters.logTarget, parameters.logging);
return true;
return JSON.stringify({
processed: processedMedia
});
}
};
12 changes: 9 additions & 3 deletions src/jsx/KBRG/ThumbnailMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,15 @@ ThumbnailMetadata.prototype.checkMatchingStartTimecodes = function (timecodes) {

return {
filename: this.filename,
isMatching: matchedTimecode.audioTC.toString() === this.timecodeMetadata.startTime.toString(),
fileTC: this.timecodeMetadata.startTime,
audioTC: matchedTimecode.audioTC
isMatching: matchedTimecode.audioTC.convertByFramerate(this.timecodeMetadata.startTime.framerate).toString() === this.timecodeMetadata.startTime.toString(),
fileTC: {
text: this.timecodeMetadata.startTime.toString(),
framerate: this.timecodeMetadata.startTime.framerate
},
audioTC: {
text: matchedTimecode.audioTC.toString(),
framerate: matchedTimecode.audioTC.framerate
}
}
}

Expand Down
20 changes: 17 additions & 3 deletions src/panels/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ body.autotc_gui {
vertical-align: middle;
}

main>section.hidden+section {
border-top: none;
}

main>section:not(:first-child) {
border-top: 1px solid var(--bright-color);
}
Expand Down Expand Up @@ -332,13 +336,14 @@ select::after {
Table layout
*/
table {
--table-border-size: 0.15rem;
text-align: left;
border-collapse: collapse;
width: 100%;
}

thead {
border-bottom: 0.2rem solid;
border-bottom: var(--table-border-size) solid;
}


Expand All @@ -347,22 +352,30 @@ tr {
background-color: var(--dark-color);
}

tr>th:first-child {
border-right: var(--table-border-size) solid;
}


tr:nth-child(2n) {
background-color: var(--table-color-bright);
}
tr:focus:not(:only-of-type), tr:hover:not(:only-of-type) {

tr:focus:not(:only-of-type),
tr:hover:not(:only-of-type) {
background-color: var(--table-highlight-color);
}
tr:nth-child(2n):focus, tr:nth-child(2n):hover {

tr:nth-child(2n):focus,
tr:nth-child(2n):hover {
background-color: var(--table-highlight-color-bright);
}

td,
th {
padding: 0.25rem 0.5rem;
}

td:not(:first-child),
th:not(:first-child) {
text-align: right;
Expand All @@ -376,6 +389,7 @@ tr.misMatch {
--table-highlight-color-bright: rgb(160, 58, 58);
}


/**
* Host exclusive interface parts
*/
Expand Down

0 comments on commit 1f159df

Please sign in to comment.