From 9551f021eccee094398dc5de6da3cbf3b41bebac Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:17:46 +0200 Subject: [PATCH] fix incorrectly relative paths Some dictionaries apparently put the dic and aff file in a sub-directory dictionaries and incorrectly make paths relative to that directory instead of the root, for example: https://github.com/LibreOffice/dictionaries/tree/master/ca --- src/calibre/spell/import_from.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/calibre/spell/import_from.py b/src/calibre/spell/import_from.py index be4be5d98b..58287e8f32 100644 --- a/src/calibre/spell/import_from.py +++ b/src/calibre/spell/import_from.py @@ -158,8 +158,16 @@ def import_from_oxt(source_path, name, dest_dir=None, prefix='dic-'): def import_from_online(directory, name, dest_dir=None, prefix='dic-'): br = browser(timeout=30) def read_file(key): - rp = br.open('/'.join((ONLINE_DICTIONARY_BASE_URL, directory, key))) - return rp.read() + try: + rp = br.open('/'.join((ONLINE_DICTIONARY_BASE_URL, directory, key))) + return rp.read() + except: + # Some dictionaries apparently put the dic and aff file in a + # sub-directory dictionaries and incorrectly make paths relative + # to that directory instead of the root, for example: + # https://github.com/LibreOffice/dictionaries/tree/master/ca + rp = br.open('/'.join((ONLINE_DICTIONARY_BASE_URL, directory, 'dictionaries', key))) + return rp.read() return _import_from_virtual_directory(read_file, name, dest_dir=dest_dir, prefix=prefix)