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

how can I get data using -b flag? #29

Closed squarebrakets closed 3 years ago

squarebrakets commented 3 years ago

I have tried to get pictures from ID3 APIC tags but I get empty value. Any ways to get the binary output?

barasher commented 3 years ago

Hi, This is not possible yet, but I will make some tests asap (probably this weekend). I'll keep you posted. Do you have any sample file that I could rely on for my tests ?

squarebrakets commented 3 years ago

Thank you for you work. I have already found some testable files with APIC tags https://github.com/anars/blank-audio/blob/master/15-seconds-of-silence.mp3

barasher commented 3 years ago

I ran some tests. It seems that exiftool's -b argument is compatible with the -j argument that go-exiftool relies on. Adding this option to go-exiftool shouldn't be that hard. I should be able to integrate this feature this weekend. I you want to make a PR, don't hesitate :)

squarebrakets commented 3 years ago

I tried to do that before making this an issue. It seems that it's out of the scope of my knowledge. Otherwise I'd be happy to.

barasher commented 3 years ago

PR #31

barasher commented 3 years ago

The v1.6.0 release has a new functionnal option (ExtractAllBinaryMetadata) that extracts binary metadata:

e, err := NewExiftool(ExtractAllBinaryMetadata())

Tell me if everything's ok :)

squarebrakets commented 3 years ago

So the problem is the json.Unmarshler converts []byte to base64. Converting back to []byte creates an unnecessary overhead unless if there was way to get []bytes in a straight forward way?

squarebrakets commented 3 years ago

The test fails with other files so I have uploaded a failing test file here https://github.com/squarebrakets/go-exiftool/blob/master/testdata/binary2.mp3 Test using this if you have time :)

barasher commented 3 years ago

Thanks for your feedback, I will have a look probably sunday. But could you please describe me the tests you're talking about, the ones that are failing) ? The first thing that I'll do is trying to reproduce your issue : don't hesitate to share some code

squarebrakets commented 3 years ago

Please have take look at my https://github.com/squarebrakets/go-exiftool/blob/master/exiftool_test.go mvp. Can you make it possible so that my log result matches your test?

barasher commented 3 years ago

You consider that something goes wrong when processing the file you've provided. Tell me

squarebrakets commented 3 years ago

Test:TestExtractAllBinaryMetadata

Expecting result: I get when using default test ./testdata/binary.mp3 PASS Process exiting with code: 0

Testing others TestExtractAllBinaryMetadata using "./testdata/binary2.mp3" And I got this --- FAIL: TestExtractAllBinaryMetadata (1.40s) exiftool_test.go:296: Error Trace: exiftool_test.go:296 Error: Expected nil, but got: &errors.errorString{s:"nothing on stdMergedOut"} Test: TestExtractAllBinaryMetadata exiftool_test.go:298: Error Trace: exiftool_test.go:298 Error: Expected nil, but got: &errors.errorString{s:"key not found"} Test: TestExtractAllBinaryMetadata exiftool_test.go:299: Error Trace: exiftool_test.go:299 Error: Should be true Test: TestExtractAllBinaryMetadata

squarebrakets commented 3 years ago

FYI I provided that test TestExtractBinaryPicture to get my expected []byte result instead of base64 result in your TestExtractAllBinaryMetadata. Hope this makes sense.

squarebrakets commented 3 years ago

I have created a pull request. Hopefully that solves my whole problem. And thanks for your time.

barasher commented 3 years ago

go-exiftool is an Exiftool wrapper.

Here is how it works : go-exiftool builds an argument list for Exiftool that fit go-exiftool's configuration. The output format is JSON (-j argument) and this JSON is then unmarshalled in go-exiftool.

/tmp$ exiftool -b -j  testdata_binary2.mp3
[{
(...)
  "Picture": "base64:iVB(...)",
(...)
}]

The binary values returned by go-exiftool are the ones that are returned by exiftool. So, nothing fails, it works as intended (as I intended). But I agree, base64 encoding is quite verbose.

What you want is another way that "optimize" binary metadata extraction so that you get directly []byte without any 'over-encoding'.

I'll think about it, but I fear it might be "expensive" (long to code). I'll close this issue and add another one, more explicit concerning the objective.