Differentiate parsing for earlier mobi versionsq
This commit is contained in:
@@ -847,7 +847,7 @@ def process_all_mobi_headers(files, apnxfile, sect, mhlst, K8Boundary, k8only=Fa
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def unpackBook(infile, outdir, apnxfile=None, epubver='2', use_hd=False, dodump=False, dowriteraw=False, dosplitcombos=False):
|
def unpackBook(infile, outdir, apnxfile=None, epubver='2', use_hd=True, dodump=False, dowriteraw=False, dosplitcombos=False):
|
||||||
global DUMP
|
global DUMP
|
||||||
global WRITE_RAW_DATA
|
global WRITE_RAW_DATA
|
||||||
global SPLIT_COMBO_MOBIS
|
global SPLIT_COMBO_MOBIS
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import shutil
|
||||||
import zipfile
|
import zipfile
|
||||||
import collections
|
import collections
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
@@ -32,6 +33,7 @@ class ParseEBook:
|
|||||||
# TODO
|
# TODO
|
||||||
# Maybe also include book description
|
# Maybe also include book description
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
self.filename_copy = filename
|
||||||
self.book = None
|
self.book = None
|
||||||
self.temp_dir = temp_dir
|
self.temp_dir = temp_dir
|
||||||
self.temp_dir_copy = temp_dir
|
self.temp_dir_copy = temp_dir
|
||||||
@@ -54,15 +56,25 @@ class ParseEBook:
|
|||||||
|
|
||||||
new_filename_with_ext = os.path.splitext(
|
new_filename_with_ext = os.path.splitext(
|
||||||
os.path.basename(self.filename))[0] + '.epub'
|
os.path.basename(self.filename))[0] + '.epub'
|
||||||
|
|
||||||
self.filename = os.path.join(
|
self.filename = os.path.join(
|
||||||
self.temp_dir, 'mobi8', new_filename_with_ext)
|
self.temp_dir, 'mobi8', new_filename_with_ext)
|
||||||
|
if not os.path.exists(self.filename):
|
||||||
|
zip_dir = os.path.join(self.temp_dir, 'mobi7')
|
||||||
|
zip_file = os.path.join(
|
||||||
|
self.temp_dir_copy, new_filename_with_ext)
|
||||||
|
self.filename = shutil.make_archive(zip_file, 'zip', zip_dir)
|
||||||
|
|
||||||
self.temp_dir = self.temp_dir_copy
|
self.temp_dir = self.temp_dir_copy
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.book = ebooklib.epub.read_epub(self.filename)
|
self.book = ebooklib.epub.read_epub(self.filename)
|
||||||
except (KeyError, AttributeError, FileNotFoundError):
|
except (KeyError, AttributeError):
|
||||||
print('Cannot parse ' + self.filename)
|
print('Cannot parse ' + self.filename)
|
||||||
return
|
return
|
||||||
|
except FileNotFoundError:
|
||||||
|
print('Intermediate FNF: ' + self.filename_copy)
|
||||||
|
return
|
||||||
|
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
return self.book.title.strip()
|
return self.book.title.strip()
|
||||||
|
Reference in New Issue
Block a user