Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ocrd/ocrd/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from urllib.parse import urlparse, unquote
from zipfile import ZipFile

from mimetypes import guess_type
from filetype import guess
import requests
from yaml import safe_load, safe_dump

Expand Down Expand Up @@ -317,7 +319,13 @@ def download(
Path('out').mkdir()
with pushd_popd('out'):
suffixes = ''.join(Path(nth_url_segment(url)).suffixes)
mimetype = EXT_TO_MIME.get(suffixes, 'application/octet-stream')
mimetype = guess(f'../{archive_fname}')
if mimetype is None:
mimetype = guess_type(f'../{archive_fname}')[0]
else:
mimetype = mimetype.mime
if mimetype is None:
mimetype = EXT_TO_MIME.get(suffixes, 'application/octet-stream')
log.info("Extracting %s archive to %s/out" % (mimetype, tempdir))
if mimetype == 'application/zip':
with ZipFile(f'../{archive_fname}', 'r') as zipf:
Expand Down
1 change: 1 addition & 0 deletions ocrd/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pyyaml
Deprecated == 1.2.0
memory-profiler >= 0.58.0
sparklines >= 0.4.2
filetype
2 changes: 1 addition & 1 deletion repo/spec