Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Using Hachoir, how extract metadata for file-like objects?

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?

like image 996
Armando Pérez Marqués Avatar asked Jul 03 '12 00:07

Armando Pérez Marqués


People also ask

How do I use Hachoir metadata in python?

hachoir-metadata has three modes: classic mode: extract metadata, you can use –level=LEVEL to limit quantity of information to display (and not to extract) --type : show on one line the file format and most important informations. --mime : just display file MIME type.

How do I extract metadata from a file?

ExifTool is a powerful tool used to extract metadata of a file. It is used not only on images but some other formats of files like PDF and mp4 etc. It enables us to update and remove metadata of files and gives a lot of information about files.

What is metadata extraction machine learning?

The proposed algorithmic metadata extraction model leverages the capacity of deep learning classification techniques to identify text lines in a given document that discusses metadata information of the proposed algorithmic PC within.


1 Answers

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)
like image 59
Armando Pérez Marqués Avatar answered Jan 02 '23 13:01

Armando Pérez Marqués