View Single Post
Old 01-01-2017, 07:09 PM   #939
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
@Kovid: Yes, that's what is happening. There is a call to "os.path.relpath()" using "EbookIterator.base". This is being done when calculating the page count via the Adobe method. All it is doing is finding what the name of the files would be so that the compressed file size can be found from the epub file

The code involved is below. The appropriate line is in red. I assume with the change in the way the EbookIterator.base is done, the "private" is no longer in the path. As I don't have access to a Mac to test this on, I have no idea what should be here. Or maybe it would be simpler to go back to the OPF and get the names from there as they should match the names in the file.

Code:
def _get_page_count_adobe(iterator, book_path):
    '''
    This algorithm uses the proper adobe count. We look at the compressed size in the
    zip of every file in the spine, and apply the 1024 bytes calculation to that...
    '''
    import math
    from calibre.utils.zipfile import ZipFile

    with ZipFile(book_path, 'r') as zf:
        size_map = dict({(ci.filename, ci.compress_size) for ci in zf.infolist()})

        pages = 0.0
        for i in iterator.opf.spine:
            spath = i.path
            ppath = spath.partition('#')[0]
            if not os.path.exists(spath) and os.path.exists(ppath):
                spath = ppath

            if isosx:
                internal_path = os.path.relpath(spath.replace('/private',''), iterator.base).replace('\\','/')
            else:
                internal_path = os.path.relpath(spath, iterator.base).replace('\\','/')
            if internal_path in size_map:
                pages += math.ceil(size_map[internal_path] / 1024.0)
        zf.close()

    return pages
davidfor is offline   Reply With Quote