Adding information from other sources

Started by BrentT, August 07, 2014, 10:55:17 PM

Previous topic - Next topic

BrentT

I have a command like this:

exiftool  -csv -r -filecreatedate -filesize -imagesize -software -gpslatitude -gpslongitude -LastKeywordXMP -createdate -rating -exposuretime -fnumber -focallength -iso %1 %2 %3 %4 %5 %6 %7 %8 %9 >> c:\vb6\Naturalist\Batch\Metadata.txt

This gets me the metadata from the files I want and stores it in metadata.txt.

However, I have additional information from a spreadsheet that I want added to the metadata.txt.

Can I add something like this to the exiftool command?
-supplementtag:Species="Subarctic Bluet" so that the output is this:

SourceFile,FileCreateDate,FileSize,ImageSize,Software,GPSLatitude,GPSLongitude,Species
c:/My Pictures/2014/2014-05-03-C/DCIM11[N4634132W07929876T3FE9F604H012B99].jpg,2014:05:03 14:15:21-04:00,633 kB,1536x2048,VISUALON V2.0,"46 deg 20' 28.75"" N","79 deg 17' 55.53"" W",."SubarcticBluet"

These supplement tags are from a spreadsheet file and will be stored in a database rather than the media files ultimately.

Also is it possible to suppress the line "SourceFile,FileCreateDate,FileSize,ImageSize,Software,GPSLatitude,GPSLongitude,Species" as in my software I want to append file by file in some cases to metadata.txt?

Thanks, Brent

BrentT

Alternatively I could pipe the output from Exiftool to the clipboard and then I'll be able to manipulate the text in my software.  That should work.

BrentT

Piping the data to the clipboard didn't work as I am unable to get the output from Exiftool, but I still can read the results of exiftool, alter it with string manipulation and save it again.

Hayo Baan

Have you already gotten what you need, or do you still need help with something?

By the way, if you're on a mac, it is easy to pipe the output of a program to the clipboard using pbcopy. But alas, I see you are on Windows and I don't know if there is a similar command there  :(
Hayo Baan – Photography
Web: www.hayobaan.nl

StarGeek

Windows vista and up has a Clip command.  XP can download it.   See this article which has the link.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

BrentT

#5
I figured it out.  I used Exiftool as normal to collect all it information I wanted it to extract and put it in a file.  Then I read this file line by line and tack on the parts from the spreadsheet.  The new line is added to a long string.  Then I save the whole string into a new file and I'm done.  It is a bit of a hack but it works.  Here is the code I came up with:

Sub PImportMediaDiary()
  Dim xlApp As Object, wb As Workbook, ws As Worksheet
  Dim t As Long, Metamake As String, StartPoint As Long, EndPoint As Long, FilenameWhole As String
  Dim LineOfFile As String, Metadata As String, Filename() As String
 
  ' Set up reading from spreadsheet
  Set xlApp = New Excel.Application
  Set wb = xlApp.Workbooks.Open("c:\diary.xls")
  Set ws = wb.Worksheets("Sheet4")  'Specify your worksheet name
  StartPoint = ws.Cells(2, 1)
  EndPoint = ws.Cells(1, 1)
  Set ws = wb.Worksheets("Sheet1")
 
  ' Get basic data
  If Dir$(PW.Metadata) <> "" Then Kill PW.Metadata
  Metamake = "exiftool -csv -filecreatedate -filesize -imagesize -software -gpslatitude -gpslongitude -LastKeywordXMP -createdate -rating -exposuretime -fnumber -focallength -iso "
  For t = StartPoint To EndPoint
    FilenameWhole = ws.Cells(t, 1)
    If Len(FilenameWhole) > 4 Then
      If Mid$(FilenameWhole, Len(FilenameWhole) - 3, 1) = "." Then
        Metamake = Metamake + " " + Chr$(34) + FilenameWhole + Chr$(34)
      End If
    End If
    If Len(Metamake) > 8000 Or t = EndPoint Then
      Metamake = Metamake + " >> c:\vb6\Naturalist\Batch\metadata.txt"
      If Dir$(PW.Metamake) <> "" Then Kill PW.Metamake
      Open PW.Metamake For Append As #META
      Print #META, Metamake
      Close #META
      ShellCommand = DefaultDirectory + "\batch\metamake.bat"
      ShellWait ShellCommand
      Metamake = "exiftool -csv -filecreatedate -filesize -imagesize -software -gpslatitude -gpslongitude -LastKeywordXMP -createdate -rating -exposuretime -fnumber -focallength -iso "
     
    End If
  Next
 
  ' Add in other data from the diary
  Open PW.Metadata For Input As #META
  For t = StartPoint To EndPoint
    If EOF(META) Then Exit For
    Line Input #META, LineOfFile
   
    If Mid$(LineOfFile, 2, 1) <> ":" Then
      Metadata = Metadata + Left$(LineOfFile, Len(LineOfFile) - 2) + ",Species,Comment" + Chr$(13) + Chr$(10)
      Line Input #META, LineOfFile
    End If
    Filename() = Split(LineOfFile, ",")
    Do Until Filename(0) = Replace(ws.Cells(t, 1), "\", "/")
      t = t + 1
    Loop
    Metadata = Metadata + Left$(LineOfFile, Len(LineOfFile) - 2) + ","
    If ws.Cells(t, 4) <> "" Then
      Metadata = Metadata + Chr$(34) + ws.Cells(t, 4) + Chr$(34) + ","
    Else
      Metadata = Metadata + ","
    End If
    If ws.Cells(t, 5) <> "" Then
      Metadata = Metadata + Chr$(34) + ws.Cells(t, 5) + Chr$(34) + Chr$(13) + Chr$(10)
    Else
      Metadata = Metadata + Chr$(13) + Chr$(10)
    End If
  Next
  Close #META
  Kill PW.Metadata
  Open PW.Metadata For Append As #META
  Print #META, Metadata
  Close #META
 
  ' Clean up Excel stuff
  xlApp.Quit
  Set ws = Nothing
  Set wb = Nothing
  Set xlApp = Nothing
End Sub

Phil Harvey

Thanks for posting your solution.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).