algoo / preview-generator

generates previews of files with cache management
https://pypi.org/project/preview-generator/
MIT License
228 stars 50 forks source link

preview of file pptm not working with Tracim #170

Open PhilippeAccorsi opened 4 years ago

PhilippeAccorsi commented 4 years ago

at present

I try to generate a preview of pptm file but no preview is created. I can see this kind of error in Tracim:

2020-01-16 10:50:27 INFO  [PreviewGenerator:21][b'uWSGIWorker2Core0'] New Preview builder of class<class 'preview_generator.preview.builder.office__libreoffice.OfficePreviewBuilderLibreoffice'>
2020-01-16 10:50:27 WARNI [tracim:46][b'uWSGIWorker2Core0'] [ContentApi] Unknown Preview_Generator Exception Occured : unable to found input extension from mimetype
2020-01-16 10:50:27 WARNI [tracim:46][b'uWSGIWorker2Core0'] [ContentApi] Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/marshmallow/utils.py", line 334, in _get_value_for_key
    return obj[key]
TypeError: 'ContentInContext' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./tracim_backend/lib/core/content.py", line 2008, in get_preview_page_nb
    nb_pages = self.preview_manager.get_page_nb(file_path, file_ext=file_extension)
  File "/usr/local/lib/python3.5/dist-packages/preview_generator/manager.py", line 128, in get_page_nb
    page_nb = builder.get_page_number(file_path, preview_name, self.cache_path, mimetype)
  File "/usr/local/lib/python3.5/dist-packages/preview_generator/preview/builder/document_generic.py", line 175, in get_page_number
    mimetype=mimetype,
  File "/usr/local/lib/python3.5/dist-packages/preview_generator/preview/builder/document_generic.py", line 147, in build_pdf_preview
    mimetype=mimetype,
  File "/usr/local/lib/python3.5/dist-packages/preview_generator/preview/builder/office__libreoffice.py", line 66, in _convert_to_pdf
    file_content, input_extension, cache_path, output_filepath, mimetype
  File "/usr/local/lib/python3.5/dist-packages/preview_generator/preview/builder/office__libreoffice.py", line 84, in convert_office_document_to_pdf
    raise InputExtensionNotFound("unable to found input extension from mimetype")  # nopep8
preview_generator.exception.InputExtensionNotFound: unable to found input extension from mimetype
2020-01-16 10:50:27 INFO  [PreviewGenerator:21][b'uWSGIWorker2Core0'] New Preview builder of class<class 'preview_generator.preview.builder.office__libreoffice.OfficePreviewBuilderLibreoffice'>
2020-01-16 10:50:27 INFO  [PreviewGenerator:21][b'uWSGIWorker2Core0'] New Preview builder of class<class 'preview_generator.preview.builder.office__libreoffice.OfficePreviewBuilderLibreoffice'>
[pid: 750|app: 0|req: 98781/140951] 127.0.0.1 () {46 vars in 965 bytes} [Thu Jan 16 10:50:27 2020] GET /api/v2/workspaces/17/files/11630 => generated 968 bytes in 77 msecs (HTTP/1.1 200) 1 headers in 51 bytes (1 switches on core 0)
[pid: 749|app: 0|req: 42171/140952] 127.0.0.1 () {46 vars in 1008 bytes} [Thu Jan 16 10:50:27 2020] GET /api/v2/workspaces/17/contents?namespaces_filter=upload => generated 2 bytes in 49 msecs (HTTP/1.1 200) 1 headers in 51 bytes (1 switches on core 0)
2020-01-16 10:50:27 INFO  [PreviewGenerator:21][b'uWSGIWorker2Core0'] New Preview builder of class<class 'preview_generator.preview.builder.office__libreoffice.OfficePreviewBuilderLibreoffice'>
2020-01-16 10:50:27 WARNI [tracim:46][b'uWSGIWorker2Core0'] [ContentApi] Unknown Preview_Generator Exception Occured : unable to found input extension from mimetype
2020-01-16 10:50:27 WARNI [tracim:46][b'uWSGIWorker2Core0'] [ContentApi] Traceback (most recent call last):
  File "./tracim_backend/lib/core/content.py", line 1040, in get_jpg_preview_path
    if page_number >= self.preview_manager.get_page_nb(file_path, file_ext=file_extension):
  File "/usr/local/lib/python3.5/dist-packages/preview_generator/manager.py", line 128, in get_page_nb
    page_nb = builder.get_page_number(file_path, preview_name, self.cache_path, mimetype)
  File "/usr/local/lib/python3.5/dist-packages/preview_generator/preview/builder/document_generic.py", line 175, in get_page_number
    mimetype=mimetype,
  File "/usr/local/lib/python3.5/dist-packages/preview_generator/preview/builder/document_generic.py", line 147, in build_pdf_preview
    mimetype=mimetype,
  File "/usr/local/lib/python3.5/dist-packages/preview_generator/preview/builder/office__libreoffice.py", line 66, in _convert_to_pdf
    file_content, input_extension, cache_path, output_filepath, mimetype
  File "/usr/local/lib/python3.5/dist-packages/preview_generator/preview/builder/office__libreoffice.py", line 84, in convert_office_document_to_pdf
    raise InputExtensionNotFound("unable to found input extension from mimetype")  # nopep8
preview_generator.exception.InputExtensionNotFound: unable to found input extension from mimetype

Expected

More information:

I can't add my file on this issue but if you give me an email, I can send you directly the file if necessary.

PhilippeAccorsi commented 4 years ago

File type visible in Tracim: Type : application/vnd.ms-powerpoint.presentation.macroEnabled.12

inkhey commented 4 years ago

Issue is related to bad non-lowercase mimetype support in python standard lib : https://bugs.python.org/issue39441

inkhey commented 4 years ago

According to the issue of lowercase these type of file should not work correctly on preview_generator:

    "application/vnd.ms-excel.sheet.binary.macroEnabled.12": "xlsb",
    "application/vnd.ms-excel.sheet.macroEnabled.12": "xlsm",
    "application/vnd.ms-excel.template.macroEnabled.12": "xltm",
    "application/vnd.ms-powerpoint.presentation.macroEnabled.12": "pptm",
    "application/vnd.ms-powerpoint.slide.macroEnabled.12": "sldm",
    "application/vnd.ms-powerpoint.slideshow.macroEnabled.12": "ppsm",
    "application/vnd.ms-powerpoint.template.macroEnabled.12": "potm",
    "application/vnd.ms-word.document.macroEnabled.12": "docm",
    "application/vnd.ms-word.template.macroEnabled.12": "dotm",
inkhey commented 4 years ago

On my system, theses mimetypes contains uppercase and could not be correctly supported by preview_generator with current code:


application/batch-SMTP
application/vnd.3M.Post-it-Notes
application/vnd.hp-HPGL
application/vnd.hp-PCL
application/vnd.hp-PCLXL
application/vnd.ibm.MiniPay
application/vnd.ms-excel.addin.macroEnabled.12                  xlam
application/vnd.ms-excel.sheet.binary.macroEnabled.12               xlsb
application/vnd.ms-excel.sheet.macroEnabled.12                  xlsm
application/vnd.ms-excel.template.macroEnabled.12               xltm
application/vnd.ms-powerpoint.addin.macroEnabled.12             ppam
application/vnd.ms-powerpoint.presentation.macroEnabled.12          pptm
application/vnd.ms-powerpoint.slide.macroEnabled.12             sldm
application/vnd.ms-powerpoint.slideshow.macroEnabled.12             ppsm
application/vnd.ms-powerpoint.template.macroEnabled.12              potm
application/vnd.ms-word.document.macroEnabled.12                docm
application/vnd.ms-word.template.macroEnabled.12                dotm
application/vnd.novadigm.EDM
application/vnd.novadigm.EDX
application/vnd.novadigm.EXT
application/x-font-pcf              pcf pcf.Z
application/x-mpegURL               m3u8
chemical/x-molconn-Z                b
text/vnd.DMClientScript
text/vnd.IPTC.NewsML
text/vnd.IPTC.NITF
video/MP2T                  ts