forked from al1b/Calibre-KiPEO
-
Notifications
You must be signed in to change notification settings - Fork 1
/
reshaper.py
26 lines (20 loc) · 927 Bytes
/
reshaper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from calibre_plugins.kipeo.libpyarabicshaping import pyarabicshaping
from io import open
from calibre.ebooks.oeb.polish.container import OEB_DOCS
def reshape_book(container, verbose=False):
for name, media_type in container.mime_map.items():
if media_type in OEB_DOCS:
if(verbose):
print('processing ' + name)
# read file content
oed_doc_file_name = container.name_to_abspath(name)
oeb_doc_file = open(oed_doc_file_name, 'r', encoding='utf-8')
oeb_doc_content = oeb_doc_file.read()
oeb_doc_file.close()
# reshape and write the file
oeb_doc_file = container.open(name, 'w')
oeb_doc_content = pyarabicshaping.arabic_shape(oeb_doc_content)
oeb_doc_file.write(oeb_doc_content)
oeb_doc_file.close()
# flag files as dirty
container.dirty(name)