mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Reformat using black
This commit is contained in:
+14
-6
@@ -325,7 +325,7 @@ class HandlerDialog(QDialog):
|
||||
)
|
||||
|
||||
# 3. If still no nav_item, check for NCX or fallback to NAV HTML in all ITEM_DOCUMENTs
|
||||
ncx_constant = getattr(epub, 'ITEM_NCX', None)
|
||||
ncx_constant = getattr(epub, "ITEM_NCX", None)
|
||||
if not nav_item and ncx_constant is not None:
|
||||
ncx_items = list(self.book.get_items_of_type(ncx_constant))
|
||||
if ncx_items:
|
||||
@@ -337,13 +337,15 @@ class HandlerDialog(QDialog):
|
||||
for item in self.book.get_items_of_type(ebooklib.ITEM_DOCUMENT):
|
||||
try:
|
||||
html_content = item.get_content().decode("utf-8", errors="ignore")
|
||||
if '<nav' in html_content and 'epub:type="toc"' in html_content:
|
||||
if "<nav" in html_content and 'epub:type="toc"' in html_content:
|
||||
soup = BeautifulSoup(html_content, "html.parser")
|
||||
nav_tag = soup.find("nav", attrs={"epub:type": "toc"})
|
||||
if nav_tag:
|
||||
nav_item = item
|
||||
nav_type = "html"
|
||||
logging.info(f"Found NAV HTML with TOC in: {item.get_name()}")
|
||||
logging.info(
|
||||
f"Found NAV HTML with TOC in: {item.get_name()}"
|
||||
)
|
||||
break
|
||||
except Exception as e:
|
||||
continue
|
||||
@@ -533,7 +535,9 @@ class HandlerDialog(QDialog):
|
||||
pass
|
||||
# Fallback: if slice_html is empty, try to get the whole file's text
|
||||
if not slice_html.strip() and current_doc_html:
|
||||
logging.warning(f"No content found for src '{current_src}', using full file as fallback.")
|
||||
logging.warning(
|
||||
f"No content found for src '{current_src}', using full file as fallback."
|
||||
)
|
||||
slice_html = current_doc_html
|
||||
if slice_html.strip():
|
||||
slice_soup = BeautifulSoup(slice_html, "html.parser")
|
||||
@@ -637,7 +641,9 @@ class HandlerDialog(QDialog):
|
||||
|
||||
if src:
|
||||
base_href, fragment = src.split("#", 1) if "#" in src else (src, None)
|
||||
doc_key, doc_idx = self._find_doc_key(base_href, doc_order, doc_order_decoded)
|
||||
doc_key, doc_idx = self._find_doc_key(
|
||||
base_href, doc_order, doc_order_decoded
|
||||
)
|
||||
if not doc_key:
|
||||
logging.warning(
|
||||
f"Navigation entry '{title}' points to '{base_href}', which is not in the spine or document list (even after basename fallback)."
|
||||
@@ -724,7 +730,9 @@ class HandlerDialog(QDialog):
|
||||
fragment = None
|
||||
if src:
|
||||
base_href, fragment = src.split("#", 1) if "#" in src else (src, None)
|
||||
doc_key, doc_idx = self._find_doc_key(base_href, doc_order, doc_order_decoded)
|
||||
doc_key, doc_idx = self._find_doc_key(
|
||||
base_href, doc_order, doc_order_decoded
|
||||
)
|
||||
if doc_key is not None:
|
||||
position = find_position_func(doc_key, fragment)
|
||||
entry_data = {
|
||||
|
||||
@@ -434,8 +434,8 @@ class ConversionThread(QThread):
|
||||
)
|
||||
# Only check for files with allowed extensions (extension without dot, case-insensitive)
|
||||
clash = any(
|
||||
os.path.splitext(fname)[0] == f"{base_name}{suffix}" and
|
||||
os.path.splitext(fname)[1][1:].lower() in allowed_exts
|
||||
os.path.splitext(fname)[0] == f"{base_name}{suffix}"
|
||||
and os.path.splitext(fname)[1][1:].lower() in allowed_exts
|
||||
for fname in os.listdir(parent_dir)
|
||||
)
|
||||
if not os.path.exists(chapters_out_dir_candidate) and not clash:
|
||||
@@ -680,7 +680,9 @@ class ConversionThread(QThread):
|
||||
continue
|
||||
# Open chapter subtitle file for incremental writing if needed
|
||||
chapter_subtitle_file = None
|
||||
chapter_srt_index = 1 # Initialize SRT numbering for this chapter file
|
||||
chapter_srt_index = (
|
||||
1 # Initialize SRT numbering for this chapter file
|
||||
)
|
||||
if self.subtitle_mode != "Disabled":
|
||||
subtitle_format = getattr(self, "subtitle_format", "srt")
|
||||
file_extension = "ass" if "ass" in subtitle_format else "srt"
|
||||
|
||||
@@ -32,11 +32,13 @@ os.environ["MIOPEN_CONV_PRECISE_ROCM_TUNING"] = "0"
|
||||
# Reset sleep states
|
||||
atexit.register(prevent_sleep_end)
|
||||
|
||||
|
||||
# Also handle signals (Ctrl+C, kill, etc.)
|
||||
def _cleanup_sleep(signum, frame):
|
||||
prevent_sleep_end()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
signal.signal(signal.SIGINT, _cleanup_sleep)
|
||||
signal.signal(signal.SIGTERM, _cleanup_sleep)
|
||||
|
||||
@@ -50,6 +52,7 @@ if sys.stderr is None:
|
||||
if platform.system() == "Darwin" and platform.processor() == "arm":
|
||||
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
|
||||
|
||||
|
||||
# Custom message handler to filter out specific Qt warnings
|
||||
def qt_message_handler(mode, context, message):
|
||||
if "Wayland does not support QWindow::requestActivate()" in message:
|
||||
|
||||
+11
-3
@@ -74,24 +74,32 @@ def get_user_config_path():
|
||||
if os.path.exists(custom_dir):
|
||||
config_dir = custom_dir
|
||||
else:
|
||||
config_dir = user_config_dir("abogen", appauthor=False, roaming=True, ensure_exists=True)
|
||||
config_dir = user_config_dir(
|
||||
"abogen", appauthor=False, roaming=True, ensure_exists=True
|
||||
)
|
||||
else:
|
||||
# Windows and fallback case
|
||||
config_dir = user_config_dir("abogen", appauthor=False, roaming=True, ensure_exists=True)
|
||||
config_dir = user_config_dir(
|
||||
"abogen", appauthor=False, roaming=True, ensure_exists=True
|
||||
)
|
||||
|
||||
return os.path.join(config_dir, "config.json")
|
||||
|
||||
|
||||
# Define cache path
|
||||
def get_user_cache_path(folder=None):
|
||||
from platformdirs import user_cache_dir
|
||||
|
||||
cache_dir = user_cache_dir("abogen", appauthor=False, opinion=True, ensure_exists=True)
|
||||
cache_dir = user_cache_dir(
|
||||
"abogen", appauthor=False, opinion=True, ensure_exists=True
|
||||
)
|
||||
if folder:
|
||||
cache_dir = os.path.join(cache_dir, folder)
|
||||
# Ensure the directory exists
|
||||
os.makedirs(cache_dir, exist_ok=True)
|
||||
return cache_dir
|
||||
|
||||
|
||||
_sleep_procs = {"Darwin": None, "Linux": None} # Store sleep prevention processes
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user