1
+ const chalk = require ( 'chalk' ) ;
2
+ const program = require ( 'commander' ) ;
3
+ const packageJson = require ( '../package.json' ) ;
4
+ const fs = require ( 'fs' ) ;
5
+ const exiftool = require ( 'node-exiftool' )
6
+ const exiftoolBin = require ( 'dist-exiftool' )
7
+ const ep = new exiftool . ExiftoolProcess ( exiftoolBin ) ;
8
+
9
+ program
10
+ . version ( packageJson . version )
11
+ . arguments ( '<image> <datafile>' , 'read exif comment data from an image' )
12
+ . action ( function ( image , datafile ) {
13
+ let newMetaData = fs . readFileSync ( datafile ) . toString ( ) ;
14
+ writeExifData ( image , newMetaData ) ;
15
+ } )
16
+ . parse ( process . argv ) ;
17
+
18
+
19
+
20
+ function writeExifData ( image , comment ) {
21
+ ep
22
+ . open ( )
23
+ // .then((pid) => console.log('Started exiftool process %s', pid))
24
+ . then ( ( ) => ep . readMetadata ( image , [ 'comment' ] ) )
25
+ . then ( ( allExif ) => {
26
+ let [ { Comment : comment } ] = allExif . data || { } ;
27
+ console . log ( chalk . yellow ( '------------- EXISTING DATA -------------' ) ) ;
28
+ console . log ( comment ) ;
29
+ } , ( err ) => {
30
+ console . error ( err ) ;
31
+ process . exit ( 1 ) ;
32
+ } )
33
+ . then ( ( ) => ep . writeMetadata ( image , {
34
+ all : '' ,
35
+ comment
36
+ } , [ 'overwrite_original' ] ) )
37
+ . then ( ( ) => ep . readMetadata ( image , [ 'comment' ] ) )
38
+ . then ( ( allExif ) => {
39
+ let [ { Comment : comment } ] = allExif . data || { } ;
40
+ console . log ( chalk . yellow ( '------------- UPDATED DATA -------------' ) ) ;
41
+ console . log ( comment ) ;
42
+ } , ( err ) => {
43
+ console . error ( err ) ;
44
+ process . exit ( 1 ) ;
45
+ } )
46
+ . then ( ( ) => ep . close ( ) )
47
+ . catch ( console . error )
48
+
49
+ }
0 commit comments