mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Code to get db info for book given its absolute path
This commit is contained in:
parent
ba99cb7971
commit
ca0949aa23
26
src/calibre/gui2/viewer/integration.py
Normal file
26
src/calibre/gui2/viewer/integration.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
from polyglot.functools import lru_cache
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize=2)
|
||||||
|
def get_book_library_details(absolute_path_to_ebook):
|
||||||
|
absolute_path_to_ebook = os.path.abspath(os.path.expanduser(absolute_path_to_ebook))
|
||||||
|
base = os.path.dirname(absolute_path_to_ebook)
|
||||||
|
m = re.search(r' \((\d+)\)$', os.path.basename(base))
|
||||||
|
if m is None:
|
||||||
|
return
|
||||||
|
book_id = int(m.group(1))
|
||||||
|
library_dir = os.path.dirname(os.path.dirname(base))
|
||||||
|
dbpath = os.path.join(library_dir, 'metadata.db')
|
||||||
|
dbpath = os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH') or dbpath
|
||||||
|
if not os.path.exists(dbpath):
|
||||||
|
return None
|
||||||
|
return {'dbpath': dbpath, 'book_id': book_id, 'fmt': absolute_path_to_ebook.rpartition('.')[-1].upper()}
|
Loading…
x
Reference in New Issue
Block a user