Updated the python conveter backend to use the new mimetype_only argument of get_mimetype and to accept a mimetype argument from the caller thus skipping mimetype detection at all resulting in another slight speedup
This commit is contained in:
@@ -25,7 +25,7 @@ class ConverterClass(ConverterBase):
|
|||||||
def get_page_count(self, input_filepath):
|
def get_page_count(self, input_filepath):
|
||||||
page_count = 1
|
page_count = 1
|
||||||
|
|
||||||
mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath)
|
mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath, mimetype_only=True)
|
||||||
if mimetype == 'application/pdf':
|
if mimetype == 'application/pdf':
|
||||||
# If file is a PDF open it with slate to determine the page
|
# If file is a PDF open it with slate to determine the page
|
||||||
# count
|
# count
|
||||||
@@ -48,9 +48,12 @@ class ConverterClass(ConverterBase):
|
|||||||
|
|
||||||
return page_count
|
return page_count
|
||||||
|
|
||||||
def convert_file(self, input_filepath, output_filepath, transformations=None, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT):
|
def convert_file(self, input_filepath, output_filepath, transformations=None, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT, **kwargs):
|
||||||
tmpfile = None
|
tmpfile = None
|
||||||
mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath)
|
mimetype = kwargs.get('mimetype', None)
|
||||||
|
if not mimetype:
|
||||||
|
mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath, mimetype_only=True)
|
||||||
|
|
||||||
if mimetype == 'application/pdf' and USE_GHOSTSCRIPT:
|
if mimetype == 'application/pdf' and USE_GHOSTSCRIPT:
|
||||||
# If file is a PDF open it with ghostscript and convert it to
|
# If file is a PDF open it with ghostscript and convert it to
|
||||||
# TIFF
|
# TIFF
|
||||||
|
|||||||
Reference in New Issue
Block a user