mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-25 02:57:22 +00:00
Kobo metadata return correct layout format for fixed layout
This commit is contained in:
parent
1a6579312f
commit
4eaa9413f9
25
cps/epub.py
25
cps/epub.py
@ -21,6 +21,7 @@ import zipfile
|
|||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from . import isoLanguages
|
from . import isoLanguages
|
||||||
|
from . import config
|
||||||
from .helper import split_authors
|
from .helper import split_authors
|
||||||
from .constants import BookMeta
|
from .constants import BookMeta
|
||||||
|
|
||||||
@ -39,6 +40,30 @@ def extractCover(zipFile, coverFile, coverpath, tmp_file_name):
|
|||||||
image.close()
|
image.close()
|
||||||
return tmp_cover_name
|
return tmp_cover_name
|
||||||
|
|
||||||
|
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):
|
def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
|
||||||
ns = {
|
ns = {
|
||||||
|
@ -49,6 +49,7 @@ import requests
|
|||||||
|
|
||||||
|
|
||||||
from . import config, logger, kobo_auth, db, calibre_db, helper, shelf as shelf_lib, ub, csrf, kobo_sync_status
|
from . import config, logger, kobo_auth, db, calibre_db, helper, shelf as shelf_lib, ub, csrf, kobo_sync_status
|
||||||
|
from .epub import get_epub_layout
|
||||||
from .constants import sqlalchemy_version2
|
from .constants import sqlalchemy_version2
|
||||||
from .helper import get_download_link
|
from .helper import get_download_link
|
||||||
from .services import SyncToken as SyncToken
|
from .services import SyncToken as SyncToken
|
||||||
@ -455,6 +456,8 @@ def get_metadata(book):
|
|||||||
continue
|
continue
|
||||||
for kobo_format in KOBO_FORMATS[book_data.format]:
|
for kobo_format in KOBO_FORMATS[book_data.format]:
|
||||||
# log.debug('Id: %s, Format: %s' % (book.id, kobo_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(
|
download_urls.append(
|
||||||
{
|
{
|
||||||
"Format": kobo_format,
|
"Format": kobo_format,
|
||||||
|
Loading…
Reference in New Issue
Block a user