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

Import all OS X tags attached to video files #370

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
88a0a07
tags extracted from OS X correctly
whyboris Feb 21, 2020
dbdcfe3
osx-tag thank you
whyboris Feb 21, 2020
7959f56
merge master
whyboris Feb 27, 2020
c27a488
merge master
whyboris Mar 3, 2020
300fca5
Merge branch 'os-tags' of https://github.com/whyboris/Video-Hub-App i…
whyboris Mar 3, 2020
eb64e8f
Merge branch 'master' into os-tags
whyboris Mar 25, 2020
cb0b5de
Merge branch 'master' into os-tags
whyboris Apr 12, 2020
9643b1f
optional dependency
whyboris Apr 12, 2020
65b5dd7
Merge branch 'master' of https://github.com/whyboris/Video-Hub-App in…
whyboris Apr 12, 2020
c6b3253
Merge branch 'os-tags' of https://github.com/whyboris/Video-Hub-App i…
whyboris Apr 12, 2020
e1aaba0
try-catch & handle error
whyboris Apr 12, 2020
39149be
Merge branch 'os-tags' of https://github.com/whyboris/Video-Hub-App i…
whyboris Apr 12, 2020
5366071
use native mdls instead of npm osx-tag
whyboris Apr 12, 2020
93914fb
Merge branch 'os-tags' of https://github.com/whyboris/Video-Hub-App i…
whyboris Apr 15, 2020
f561028
Merge branch 'master' into os-tags
whyboris Apr 20, 2020
a521cf7
Merge branch 'os-tags' of https://github.com/whyboris/Video-Hub-App i…
whyboris Apr 23, 2020
4bfdd78
Merge branch 'master' into os-tags
whyboris Apr 24, 2020
00558d0
Merge branch 'master' into os-tags
whyboris May 11, 2020
0e8d393
Merge branch 'master' into os-tags
whyboris May 13, 2020
9bd3c38
Merge branch 'master' into os-tags
whyboris May 17, 2020
600d2fd
Merge branch 'master' into os-tags
whyboris May 19, 2020
3b94ae4
Merge branch 'master' into os-tags
whyboris May 28, 2020
698bb51
Merge branch 'master' into os-tags
whyboris Jun 22, 2020
418f98f
merge main, resolve conflicts
whyboris Jul 26, 2020
fa3d15f
Merge branch 'main' into os-tags
whyboris Aug 10, 2020
640ae0d
merge main
whyboris Oct 11, 2020
7aa7b7b
Merge branch 'main' into os-tags
whyboris Oct 28, 2020
47443af
Merge branch 'main' into os-tags
whyboris Nov 2, 2020
63e7c36
Merge branch 'main' into os-tags
whyboris Nov 29, 2020
2ee41ab
Merge branch 'main' into os-tags
whyboris Feb 7, 2021
c77bc85
Merge branch 'main' into os-tags
whyboris Apr 22, 2021
3e87d04
Merge branch 'main' into os-tags
whyboris Jul 9, 2021
e926e98
Merge branch 'main' into os-tags
whyboris Mar 27, 2022
1562038
re-add osx-tag dependency
whyboris Mar 27, 2022
8cf4a1a
sike
whyboris Mar 27, 2022
96b86a6
merge main, resolve conflicts
whyboris Feb 19, 2023
98c2a22
Merge branch 'main' into os-tags
whyboris Oct 23, 2024
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
51 changes: 51 additions & 0 deletions node/main-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@
* 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');

import type { VhaGlobals } from './main-globals';
import { GLOBALS } from './main-globals'; // TODO -- eliminate dependence on `GLOBALS` in this file!

Expand Down Expand Up @@ -485,7 +495,20 @@ export function extractMetadataAsync(
imageElement.width = origWidth;
imageElement.fps = realFps;


// WIP
if (codeRunningOnMac) {
const foundTags: string[] = readTags(filePath);
console.log('tags:', foundTags);

if (foundTags && foundTags.length) {
imageElement.tags = foundTags;
}
}


hashFileAsync(filePath, fileStat).then((hash) => {

imageElement.hash = hash;
resolve(imageElement);
});
Expand All @@ -497,6 +520,34 @@ export function extractMetadataAsync(
});
}

/**
* If on Mac OS - read the file-system-added file tags and return them
* @param filename
*/
export 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;
}

/**
* Sends progress to Angular App
* @param current number
Expand Down
Loading