barasher / go-exiftool

Golang wrapper for Exiftool : extract as much metadata as possible (EXIF, ...) from files (pictures, pdf, office documents, ...)
GNU General Public License v3.0
245 stars 43 forks source link

Supply custom extraInitArgs #26

Closed shadow431 closed 3 years ago

shadow431 commented 3 years ago

This is probably less of an issue, and more of me being a go noob, so please excuse the ask but I've been running myself in circles and hoping you can help me out.

I want to pass the '-ee' flag to exiftool. I have some files that the date I am looking for only shows with the -ee flag. Bellow is my call to NewExifTool. I get:

s.extraInitArgs undefined (type *exiftool.Exiftool has no field or method extraInitArgs)

Am I doing something wrong, or is this just not an option with go-exiftool?

    et, err := exiftool.NewExiftool(func(s *exiftool.Exiftool) error {
        s.extraInitArgs = append(s.extraInitArgs, "-ee")
        return nil
        })
    if err != nil {
        fmt.Printf("Error initializing %v\n", err)
    }
barasher commented 3 years ago

Hi @shadow431 ! The extraInitArgs is a 'private' attribute (starting with a lower-cased letter) of the Exiftool struct : this attribute can only be accessed (or modified) within the github.com/barasher/go-exiftool package. I didn't want to expose this attribute because it is "risky" towards go-exiftool inner mechanism (ex : if an extra argument changes the exiftool output serialization, go-exiftool won't be able to interpret the results). I rather prefer to add new functional options to go-exiftool that add arguments that are not "harmful" for the library. I can make a few tests to check wether or not your use-case is legit for a new functional options. Is that ok ?

shadow431 commented 3 years ago

That makes sense. I had figured that but kept being told it should work but go kept saying nope lol. If you'd be willing to make some test that would be great, I would really appreciate it.

barasher commented 3 years ago

Based on exiftool's documentation, I did some tests directly with exiftool, with and without the -ee3 parameter but I couldn't find an example where the extraction with -ee3 extracted more medatata than the version without the argument. I tried with a sample AVCHD file, with a PDF embedding JPGs, ... Could you please provide me example that actually works ? What I'm worried about is the exiftool built-in JSON serialization. Thank's a lot !

barasher commented 3 years ago

I found differences when using -ee parameter (without any number) on a PDF file that embeds a JPG picture :

barasher:/tmp$ exiftool p.pdf | sort | uniq | wc -l
18
batasher:/tmp$ exiftool -ee p.pdf | sort | uniq | wc -l
38

Concerning my fear about JSON serialization :

barasher:/tmp$ exiftool -ee p.pdf | grep 'File.*Type.*Extension'
File Type Extension             : pdf
File Type Extension             : jpg
barasher:/tmp$ exiftool -ee -j p.pdf | grep 'File.*Type.*Extension'
  "FileTypeExtension": "pdf",

Unfortunately, exiftool deduplicates when converting to metadata to json.

Could you please tell me more about your use-case ? I'm still interested in :

shadow431 commented 3 years ago

Sorry for the delayed response, it was a very busy weekend.

So at the link bellow is an example its got a small video file from a go pro that is less the a second but you can see the data. There's also two outputs from exiftool one just exiftool <file> the other exiftool -ee <file> mainly in this case I'm looking for "Other Serial Number" which I only get from adding -ee. I have some other examples, but couldn't readily find them. I haven't taken the time yet to look and see what args go-exiftool pass by default and try that with the -ee. I'll do that later today if I get a chance after work.

Mostly these are for files from camera's I no longer have but I still would like to be able to work with them.

https://www.dropbox.com/sh/r9g3z5fi7c7l5zm/AACDXYN8Bq3Yi2arrlxmwqQta?dl=0

barasher commented 3 years ago

Just to tell you that I haven't forgotten this issue, I was a little bit busy these last days.

shadow431 commented 3 years ago

That's fine. I appreciate it. I am able to move forward with the rest of the development for most of my files so I am not blocked on it. Currently I am replacing a python script that got lost and I can no longer find any copies off. In that I ended up using two different libraries with multiple if statements to check file type, and based on type look for different fields and if a field wasn't there try a different library, etc, etc. Later this week I am hoping to run this as is against my whole library again and see what comes back nil and maybe get some better examples.

barasher commented 3 years ago

PR #28

barasher commented 3 years ago

A ExtractEmbedded functionnal option has been integrated and released in v1.5.0.