From 88a0a0737677b88dfab45b74c95aaa2c76516e36 Mon Sep 17 00:00:00 2001 From: Boris Yakubchik Date: Fri, 21 Feb 2020 18:11:01 -0500 Subject: [PATCH 1/7] tags extracted from OS X correctly --- main-support.ts | 27 ++++++++++++++++++++++++++- package-lock.json | 11 +++++++++-- package.json | 1 + 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/main-support.ts b/main-support.ts index e8ecd9a8..699c7a5e 100644 --- a/main-support.ts +++ b/main-support.ts @@ -4,8 +4,14 @@ * There should be no side-effects of running any of them * They should depend only on their inputs and behave exactly * the same way each time they run no matter the outside state + * + * !!!!!!!!!!!! WARNING !!!!!!!!!!!!!!! + * DANGEROUSLY DEPENDS ON `codeRunningOnMac` when extracting metadata + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ +const codeRunningOnMac: boolean = process.platform === 'darwin'; // <---- MAKES MANY FUNCTIONS NOT PURE !!!! + import * as path from 'path'; const fs = require('fs'); @@ -14,6 +20,8 @@ const hasher = require('crypto').createHash; const exec = require('child_process').exec; +const tag = require('osx-tag'); + const ffprobePath = require('@ffprobe-installer/ffprobe').path.replace('app.asar', 'app.asar.unpacked'); import { acceptableFiles } from './main-filenames'; @@ -489,7 +497,24 @@ function extractMetadataForThisONEFile( imageElement.width = origWidth; imageElement.screens = computeNumberOfScreenshots(screenshotSettings, duration); - extractMetaCallback(imageElement); + // !!!! WARNING !!!!!! NOT A PURE FUNCTION ANY MORE !!!!!!!!!!!!!!! + if (codeRunningOnMac) { + tag.getTags(filePath, (tagErr: any, tags: string[]) => { + if (tagErr) { + console.log('tags error!!!'); + extractMetaCallback(imageElement); + } + console.log('tags found:'); + console.log(tags); + if (tags.length) { + imageElement.tags = tags; + } + extractMetaCallback(imageElement); + }); + } else { + extractMetaCallback(imageElement); + } + } }); } diff --git a/package-lock.json b/package-lock.json index a30d4eaa..df901def 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9621,8 +9621,7 @@ "nan": { "version": "2.14.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", - "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", - "dev": true + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" }, "nanomatch": { "version": "1.2.13", @@ -10465,6 +10464,14 @@ "os-tmpdir": "^1.0.0" } }, + "osx-tag": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/osx-tag/-/osx-tag-0.4.1.tgz", + "integrity": "sha512-UrxRN8tGoLWX1wqQzU2hEzKnje1yOvIgyM8E3/N1NokVf749tENJLCWRdf4rnF6VtSWwYZ6AdN7heRWJS3PZWA==", + "requires": { + "nan": "~2.14.0" + } + }, "p-cancelable": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", diff --git a/package.json b/package.json index a2fa9bfc..5d5b2814 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "@ngx-translate/core": "12.1.1", "fuse.js": "3.4.6", "ngx-virtual-scroller": "3.0.2", + "osx-tag": "0.4.1", "trash": "6.1.1" }, "devDependencies": { From dbdcfe35c8680df317e0b6420d0818ed9e966f80 Mon Sep 17 00:00:00 2001 From: Boris Yakubchik Date: Fri, 21 Feb 2020 18:22:48 -0500 Subject: [PATCH 2/7] osx-tag thank you --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a4e64e3a..c5a73854 100644 --- a/README.md +++ b/README.md @@ -60,5 +60,6 @@ This software would not be possible without the tremendous work by other people: - [ngx-translate](https://github.com/ngx-translate/core) - [trash](https://github.com/sindresorhus/trash) - [Fuse.js](https://github.com/krisk/Fuse) + - [osx-tag](https://github.com/keichi/osx-tag) Since becoming open source, this software was made better with the awesome contributions by [cal2195](https://github.com/cal2195) From 9643b1fb7488fc14b341a52cdee361cee6cdabfb Mon Sep 17 00:00:00 2001 From: Boris Yakubchik Date: Sun, 12 Apr 2020 12:39:28 -0400 Subject: [PATCH 3/7] optional dependency --- package-lock.json | 1 + package.json | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index b668f331..f417bd37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10315,6 +10315,7 @@ "version": "0.4.1", "resolved": "https://registry.npmjs.org/osx-tag/-/osx-tag-0.4.1.tgz", "integrity": "sha512-UrxRN8tGoLWX1wqQzU2hEzKnje1yOvIgyM8E3/N1NokVf749tENJLCWRdf4rnF6VtSWwYZ6AdN7heRWJS3PZWA==", + "optional": true, "requires": { "nan": "~2.14.0" } diff --git a/package.json b/package.json index abcb3cdb..4a8b013b 100644 --- a/package.json +++ b/package.json @@ -44,9 +44,11 @@ "@ngx-translate/core": "12.1.2", "fuse.js": "3.4.6", "ngx-virtual-scroller": "4.0.2", - "osx-tag": "0.4.1", "trash": "6.1.1" }, + "optionalDependencies": { + "osx-tag": "0.4.1" + }, "devDependencies": { "@angular-devkit/build-angular": "0.901.0", "@angular/animations": "9.1.0", From e1aaba035139336afb82114c7742e92d98cf062b Mon Sep 17 00:00:00 2001 From: Boris Yakubchik Date: Sun, 12 Apr 2020 12:53:18 -0400 Subject: [PATCH 4/7] try-catch & handle error --- main-support.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main-support.ts b/main-support.ts index b957c6a0..cd50ab12 100644 --- a/main-support.ts +++ b/main-support.ts @@ -20,7 +20,13 @@ const hasher = require('crypto').createHash; const exec = require('child_process').exec; -const tag = require('osx-tag'); +let tag = undefined; + +try { + tag = require('osx-tag'); +} catch (e) { + console.log('osx-tag will not be used'); +} const ffprobePath = require('@ffprobe-installer/ffprobe').path.replace('app.asar', 'app.asar.unpacked'); @@ -499,7 +505,7 @@ function extractMetadataForThisONEFile( imageElement.screens = computeNumberOfScreenshots(screenshotSettings, duration); // !!!! WARNING !!!!!! NOT A PURE FUNCTION ANY MORE !!!!!!!!!!!!!!! - if (codeRunningOnMac) { + if (codeRunningOnMac && tag !== undefined) { tag.getTags(filePath, (tagErr: any, tags: string[]) => { if (tagErr) { console.log('tags error!!!'); From 5366071fefe83f619d8d9ffccbee7c530e76db49 Mon Sep 17 00:00:00 2001 From: Boris Yakubchik Date: Sun, 12 Apr 2020 13:35:59 -0400 Subject: [PATCH 5/7] use native mdls instead of npm osx-tag --- README.md | 1 - main-support.ts | 54 +++++++++++++++++++++++++++++------------------ package-lock.json | 12 ++--------- package.json | 3 --- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 3df8430e..40630b98 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,5 @@ This software would not be possible without the tremendous work by other people: - [ngx-translate](https://github.com/ngx-translate/core) - [trash](https://github.com/sindresorhus/trash) - [Fuse.js](https://github.com/krisk/Fuse) - - [osx-tag](https://github.com/keichi/osx-tag) Since becoming open source, this software was made better with the awesome contributions by [cal2195](https://github.com/cal2195) diff --git a/main-support.ts b/main-support.ts index cd50ab12..69a19b48 100644 --- a/main-support.ts +++ b/main-support.ts @@ -20,14 +20,6 @@ const hasher = require('crypto').createHash; const exec = require('child_process').exec; -let tag = undefined; - -try { - tag = require('osx-tag'); -} catch (e) { - console.log('osx-tag will not be used'); -} - const ffprobePath = require('@ffprobe-installer/ffprobe').path.replace('app.asar', 'app.asar.unpacked'); import { acceptableFiles } from './main-filenames'; @@ -505,19 +497,15 @@ function extractMetadataForThisONEFile( imageElement.screens = computeNumberOfScreenshots(screenshotSettings, duration); // !!!! WARNING !!!!!! NOT A PURE FUNCTION ANY MORE !!!!!!!!!!!!!!! - if (codeRunningOnMac && tag !== undefined) { - tag.getTags(filePath, (tagErr: any, tags: string[]) => { - if (tagErr) { - console.log('tags error!!!'); - extractMetaCallback(imageElement); - } - console.log('tags found:'); - console.log(tags); - if (tags.length) { - imageElement.tags = tags; - } - extractMetaCallback(imageElement); - }); + if (codeRunningOnMac) { + + const foundTags: string[] = readTags(filePath); + console.log('tags:', foundTags); + + if (foundTags && foundTags.length) { + imageElement.tags = foundTags; + } + extractMetaCallback(imageElement); } else { extractMetaCallback(imageElement); } @@ -526,6 +514,30 @@ function extractMetadataForThisONEFile( }); } +function readTags(filename): string[] { + + console.log('reading', filename); + + const cmdArr = ['mdls', '-raw', '-name', 'kMDItemUserTags', '"' + filename + '"']; + const cmd = cmdArr.join(' '); + + let foundTags: string[] = undefined; + + exec(cmd, function (error, stdout, stderr) { + if (error) { console.error(error); } + if (stderr) { console.log(stderr); } + if (stdout) { + const tagz: string[] = stdout.toString().split(','); + console.log('Tags in file "' + filename + '": ' + tagz); + + foundTags = tagz; + } + + }); + + return foundTags; +} + // =========================================================================================== // Other supporting methods // =========================================================================================== diff --git a/package-lock.json b/package-lock.json index f417bd37..2fdd5109 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9472,7 +9472,8 @@ "nan": { "version": "2.14.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", - "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", + "dev": true }, "nanomatch": { "version": "1.2.13", @@ -10311,15 +10312,6 @@ "os-tmpdir": "^1.0.0" } }, - "osx-tag": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/osx-tag/-/osx-tag-0.4.1.tgz", - "integrity": "sha512-UrxRN8tGoLWX1wqQzU2hEzKnje1yOvIgyM8E3/N1NokVf749tENJLCWRdf4rnF6VtSWwYZ6AdN7heRWJS3PZWA==", - "optional": true, - "requires": { - "nan": "~2.14.0" - } - }, "p-cancelable": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", diff --git a/package.json b/package.json index 4a8b013b..574f7072 100644 --- a/package.json +++ b/package.json @@ -46,9 +46,6 @@ "ngx-virtual-scroller": "4.0.2", "trash": "6.1.1" }, - "optionalDependencies": { - "osx-tag": "0.4.1" - }, "devDependencies": { "@angular-devkit/build-angular": "0.901.0", "@angular/animations": "9.1.0", From 1562038039f6f5b2cf8fdcc3101d9bd36e915080 Mon Sep 17 00:00:00 2001 From: Boris Yakubchik Date: Sun, 27 Mar 2022 19:48:51 -0400 Subject: [PATCH 6/7] re-add osx-tag dependency --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 42dab9af..8914a886 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,8 @@ "zone.js": "0.11.4" }, "optionalDependencies": { - "dmg-license": "1.0.10" + "dmg-license": "1.0.10", + "osx-tag": "0.4.5" }, "browserslist": [ "chrome 98" From 8cf4a1a6f150da964865c90885ff3c43e6d015bf Mon Sep 17 00:00:00 2001 From: Boris Yakubchik Date: Sun, 27 Mar 2022 19:51:21 -0400 Subject: [PATCH 7/7] sike --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 8914a886..42dab9af 100644 --- a/package.json +++ b/package.json @@ -95,8 +95,7 @@ "zone.js": "0.11.4" }, "optionalDependencies": { - "dmg-license": "1.0.10", - "osx-tag": "0.4.5" + "dmg-license": "1.0.10" }, "browserslist": [ "chrome 98"