mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Auto adding: Run onimport filetype plugins before reading metadata. Matches behavior of manual adding. Fixes #1945889 [Metadata wrong for auto-added books](https://bugs.launchpad.net/calibre/+bug/1945889)
This commit is contained in:
parent
573693a052
commit
645cf5eff9
@ -232,6 +232,8 @@ def opf_metadata(opfpath):
|
|||||||
|
|
||||||
def forked_read_metadata(path, tdir):
|
def forked_read_metadata(path, tdir):
|
||||||
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
||||||
|
from calibre.ebooks.metadata.worker import run_import_plugins
|
||||||
|
path = run_import_plugins((path,), os.getpid(), tdir)[0]
|
||||||
with lopen(path, 'rb') as f:
|
with lopen(path, 'rb') as f:
|
||||||
fmt = os.path.splitext(path)[1][1:].lower()
|
fmt = os.path.splitext(path)[1][1:].lower()
|
||||||
f.seek(0, 2)
|
f.seek(0, 2)
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||||
|
# License: GPLv3 Copyright: 2009, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import os
|
||||||
__license__ = 'GPL v3'
|
import shutil
|
||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
import os, shutil, errno
|
|
||||||
|
|
||||||
from calibre.customize.ui import run_plugins_on_import
|
from calibre.customize.ui import run_plugins_on_import
|
||||||
from calibre.ebooks.metadata.meta import metadata_from_formats
|
from calibre.ebooks.metadata.meta import metadata_from_formats
|
||||||
@ -65,15 +62,11 @@ def run_import_plugins(paths, group_id, tdir):
|
|||||||
# reading metadata from filename is not broken
|
# reading metadata from filename is not broken
|
||||||
name = os.path.splitext(os.path.basename(path))[0]
|
name = os.path.splitext(os.path.basename(path))[0]
|
||||||
ext = os.path.splitext(nfp)[1]
|
ext = os.path.splitext(nfp)[1]
|
||||||
path = os.path.join(tdir, '%s' % group_id, name + ext)
|
path = os.path.join(tdir, str(group_id), name + ext)
|
||||||
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||||
try:
|
try:
|
||||||
os.mkdir(os.path.dirname(path))
|
os.replace(nfp, path)
|
||||||
except EnvironmentError as err:
|
except OSError:
|
||||||
if err.errno != errno.EEXIST:
|
|
||||||
raise
|
|
||||||
try:
|
|
||||||
os.rename(nfp, path)
|
|
||||||
except EnvironmentError:
|
|
||||||
shutil.copyfile(nfp, path)
|
shutil.copyfile(nfp, path)
|
||||||
final_paths.append(path)
|
final_paths.append(path)
|
||||||
return final_paths
|
return final_paths
|
||||||
|
Loading…
x
Reference in New Issue
Block a user