8

I'm working on a site that users uploads videos and audio files, I when uploaded, some common metadata fields must be populated from the file. I have found Hachoir and it seems good, but with a problem, to create a parser for metadata reading, what is required is a filename, rather than a file-like or stream object.

How to use Hachoir with file like objects?

parvus
  • 5,706
  • 6
  • 36
  • 62
Armando Pérez Marqués
  • 5,661
  • 4
  • 28
  • 45

1 Answers1

8

Using Hachoir v3.2.1:

import hachoir.metadata
import hachoir.parser
import hachoir.stream

parser = hachoir.parser.guessParser(hachoir.stream.InputIOStream(file_handle, None, tags=[]))
if parser:
    hachoir_metadata = hachoir.metadata.extractMetadata(parser)
    if hachoir_metadata:
        metadata: Dict[str, str] = hachoir_metadata.exportDictionary()['Metadata']
        print(metadata)
parvus
  • 5,706
  • 6
  • 36
  • 62
Armando Pérez Marqués
  • 5,661
  • 4
  • 28
  • 45