Change make sure avi files are closed if an error occurs.

Change refactor hachoir scan_index for non RIFF file processing.
This commit is contained in:
JackDandy 2016-10-12 00:52:28 +01:00
parent 5e133bc951
commit 3ce332a5ad
4 changed files with 28 additions and 7 deletions

View file

@ -203,6 +203,8 @@
* Change add rate limit handler for info source
* Change improve security of cached image use
* Change add helper function to validate acceptable image file extension
* Change make sure avi files are closed if an error occurs
* Change refactor hachoir scan_index for non RIFF file processing
### 0.11.16 (2016-10-16 17:30:00 UTC)

View file

@ -270,7 +270,8 @@ def registerExtractor(parser, extractor):
assert issubclass(extractor, RootMetadata)
extractors[parser] = extractor
def extractMetadata(parser, quality=QUALITY_NORMAL, scan_index=True):
def extractMetadata(parser, quality=QUALITY_NORMAL, **kwargs):
"""
Create a Metadata class from a parser. Returns None if no metadata
extractor does exist for the parser class.
@ -280,14 +281,25 @@ def extractMetadata(parser, quality=QUALITY_NORMAL, scan_index=True):
except KeyError:
return None
metadata = extractor(quality)
meta_extract_error = True
try:
metadata.extract(parser, scan_index)
if 'scan_index' in kwargs:
metadata.extract(parser, scan_index=kwargs['scan_index'])
else:
metadata.extract(parser)
meta_extract_error = False
except HACHOIR_ERRORS, err:
error("Error during metadata extraction: %s" % unicode(err))
return None
except Exception, err:
error("Error during metadata extraction: %s" % unicode(err))
if meta_extract_error:
try:
parser.stream._input.close()
except:
pass
return None
if metadata:
metadata.mime_type = parser.mime_type
metadata.endian = endian_name[parser.endian]

View file

@ -23,7 +23,7 @@ class RiffMetadata(MultipleMetadata):
"IDIT": "creation_date",
}
def extract(self, riff, scan_index=True):
def extract(self, riff, **kwargs):
type = riff["type"].value
if type == "WAVE":
self.extractWAVE(riff)
@ -32,7 +32,10 @@ class RiffMetadata(MultipleMetadata):
computeAudioComprRate(self, size*8)
elif type == "AVI ":
if "headers" in riff:
self.extractAVI(riff["headers"], scan_index)
if 'scan_index' in kwargs:
self.extractAVI(riff["headers"], scan_index=kwargs['scan_index'])
else:
self.extractAVI(riff["headers"])
self.extractInfo(riff["headers"])
elif type == "ACON":
self.extractAnim(riff)
@ -142,7 +145,7 @@ class RiffMetadata(MultipleMetadata):
self.width = header["width"].value
self.height = header["height"].value
def extractAVI(self, headers, scan_index=True):
def extractAVI(self, headers, **kwargs):
audio_index = 1
for stream in headers.array("stream"):
if "stream_hdr/stream_type" not in stream:
@ -167,6 +170,7 @@ class RiffMetadata(MultipleMetadata):
self.bit_rate = float(headers["/movie/size"].value) * 8 / timedelta2seconds(self.get('duration'))
# Video has index?
scan_index = (True, kwargs['scan_index'])['scan_index' in kwargs]
if scan_index and "/index" in headers:
self.comment = _("Has audio/video index (%s)") \
% humanFilesize(headers["/index"].size/8)

View file

@ -261,7 +261,10 @@ class Quality:
logger.log(traceback.format_exc(), logger.DEBUG)
if parser:
if '.avi' == filename[-4::].lower():
extract = extractMetadata(parser, scan_index=False)
else:
extract = extractMetadata(parser)
if extract:
try:
height = extract.get('height')