Skip to content

Commit

Permalink
Merge remote-tracking branch 'fixed_layout/kobo-sync-detect-fixed-lay…
Browse files Browse the repository at this point in the history
…out'

# Conflicts:
#	cps/kobo.py
  • Loading branch information
OzzieIsaacs committed Feb 25, 2023
2 parents 162ac73 + 7ae9f89 commit a414db0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cps/epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from lxml import etree

from . import isoLanguages, cover
from . import config
from .helper import split_authors
from .constants import BookMeta

Expand All @@ -41,6 +42,30 @@ def _extract_cover(zip_file, cover_file, cover_path, tmp_file_name):
cf = zip_file.read(zip_cover_path)
return cover.cover_processing(tmp_file_name, cf, extension)

def get_epub_layout(book, book_data):
ns = {
'n': 'urn:oasis:names:tc:opendocument:xmlns:container',
'pkg': 'http://www.idpf.org/2007/opf',
}

file_path = os.path.normpath(os.path.join(config.config_calibre_dir, book.path, book_data.name + "." + book_data.format.lower()))

epubZip = zipfile.ZipFile(file_path)

txt = epubZip.read('META-INF/container.xml')
tree = etree.fromstring(txt)
cfname = tree.xpath('n:rootfiles/n:rootfile/@full-path', namespaces=ns)[0]
cf = epubZip.read(cfname)
tree = etree.fromstring(cf)
p = tree.xpath('/pkg:package/pkg:metadata', namespaces=ns)[0]

layout = p.xpath('pkg:meta[@property="rendition:layout"]/text()', namespaces=ns)

if len(layout) == 0:
return None
else:
return layout[0]


def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
ns = {
Expand Down
3 changes: 3 additions & 0 deletions cps/kobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

from . import config, logger, kobo_auth, db, calibre_db, helper, shelf as shelf_lib, ub, csrf, kobo_sync_status
from . import isoLanguages
from .epub import get_epub_layout
from .constants import sqlalchemy_version2, COVER_THUMBNAIL_SMALL
from .helper import get_download_link
from .services import SyncToken as SyncToken
Expand Down Expand Up @@ -459,6 +460,8 @@ def get_metadata(book):
continue
for kobo_format in KOBO_FORMATS[book_data.format]:
# log.debug('Id: %s, Format: %s' % (book.id, kobo_format))
if get_epub_layout(book, book_data) == 'pre-paginated':
kobo_format = 'EPUB3FL'
download_urls.append(
{
"Format": kobo_format,
Expand Down

0 comments on commit a414db0

Please sign in to comment.