View Single Post
Old 01-15-2017, 08:45 AM   #60
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,743
Karma: 24031403
Join Date: Dec 2010
Device: Kindle PW2
@slowsmile: The built-in epub_zip_up_book_contents() function has absolutely no problems with non-ASCII file names.

I've written a quick and dirty proof of concept input plugin that demonstrates this feature.

Here's the code:

Spoiler:
Code:
#!/usr/bin/env python
import os, codecs, tkinter.filedialog
from epub_utils import epub_zip_up_book_contents

# DiapDealer's temp folder code
from contextlib import contextmanager
@contextmanager
def make_temp_directory():
    import tempfile
    import shutil
    temp_dir = tempfile.mkdtemp()
    yield temp_dir
    shutil.rmtree(temp_dir)

def run(bk):
    unpacked_epub = tkinter.filedialog.askdirectory(title = 'Select the epub folder.')
    if unpacked_epub is not None and os.path.isfile(os.path.join(unpacked_epub, 'mimetype')):
        with make_temp_directory() as epub_td:
            epub_path = os.path.join(epub_td, 'temp.epub')
            epub_zip_up_book_contents(unpacked_epub, epub_path)
            with codecs.open(epub_path, 'rb') as fp:
                data = fp.read()
            bk.addotherfile('dummy.epub', data)
        return 0
    else:
        print('Folder selection error.')
        return -1

def main():
    print('I reached main when I should not have\n')
    return -1

if __name__ == "__main__":
    sys.exit(main())


To test it unpack the attached test.epub file, which contains two HTML files with accented characters and umlauts (äöüß.xhtml and âîïéêë.xhtml).

Then install the new junk plugin, run it, select the folder that you unpacked test.epub to, and click Yes to import the files.

Note that epubcheck will complain about file names that contain non-ASCII characters and spaces. I.e., even though you could theoretically use file names with non-ASCII characters I'd strongly advise against it.
Attached Files
File Type: zip junk_v0.2.zip (1.0 KB, 812 views)
File Type: epub test.epub (3.2 KB, 917 views)
Doitsu is offline   Reply With Quote