Search code examples
pythonhachoir-parser

Suppress warnings in Hachoir


I'm using hachior-parser to grab the duration of a large set of video files. (I'm resetting the "Last modified" date based on the file's timestamp, plus its duration.) I'm using code adapted from this question.

The problem I'm running into is that hachior reports four warnings for each file, and this is cluttering up my output. I still get my duration from the file, so I'd like to know how to suppress these warnings in the output, if possible.

Python isn't really my strong suit, so I'm not sure where to look and the documentation for hachior seems pretty sparse on the error reporting. I'd prefer not to resort to grepping the lines from the output of my script.

Edit: Running python -W ignore set_last_modified.py results in the same [warn] lines being printed.

[warn] [/headers/stream[2]/stream_fmt] Can't get field "stream_hdr" from /headers/stream[2]
[warn] [/headers/stream[2]/stream_fmt] [Autofix] Fix parser error: stop parser, add padding
[warn] [/headers/stream[3]/stream_fmt] Can't get field "stream_hdr" from /headers/stream[3]
[warn] [/headers/stream[3]/stream_fmt] [Autofix] Fix parser error: stop parser, add padding

Solution

  • I found the solution by checking the issues page for the project on BitBucket.

    https://bitbucket.org/haypo/hachoir/issues/54/control-log-level-whith-the-python-api

    from hachoir_core import config as HachoirConfig
    HachoirConfig.quiet = True