0

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
Community
  • 1
  • 1
ghaberek
  • 257
  • 1
  • 10

2 Answers2

1

You can use the -W option to suppress warnings in python.

python -W ignore my_file.py

Edit: since you've already tried the above, you could try the following.

import warnings
# add the following before you call the function that gives warnings.
warnings.filterwarnings("ignore")
# run your function here
cyberbemon
  • 3,000
  • 11
  • 37
  • 62
  • Sorry, forgot to include that I had already tried that. Running `python -W ignore set_last_modified.py` results in the same `[warn]` lines being printed. – ghaberek Aug 08 '16 at 15:18
  • Unfortunately that has no effect either. It seems that the call to `extractMetadata()` is what's triggering these messages. I placed `warnings.filterwarnings("ignore")` before that line and still got the warnings. – ghaberek Aug 08 '16 at 17:13
1

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
ghaberek
  • 257
  • 1
  • 10
  • This still works, but is slightly different now... `from hachoir.core import config as HachoirConfig` – slooker Oct 17 '19 at 18:11