Reformat using black

This commit is contained in:
Deniz Şafak
2025-07-30 02:31:49 +03:00
parent 1fe5a73c98
commit e60a1f7e42
4 changed files with 35 additions and 14 deletions
+14 -6
View File
@@ -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 # 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: if not nav_item and ncx_constant is not None:
ncx_items = list(self.book.get_items_of_type(ncx_constant)) ncx_items = list(self.book.get_items_of_type(ncx_constant))
if ncx_items: if ncx_items:
@@ -337,13 +337,15 @@ class HandlerDialog(QDialog):
for item in self.book.get_items_of_type(ebooklib.ITEM_DOCUMENT): for item in self.book.get_items_of_type(ebooklib.ITEM_DOCUMENT):
try: try:
html_content = item.get_content().decode("utf-8", errors="ignore") 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") soup = BeautifulSoup(html_content, "html.parser")
nav_tag = soup.find("nav", attrs={"epub:type": "toc"}) nav_tag = soup.find("nav", attrs={"epub:type": "toc"})
if nav_tag: if nav_tag:
nav_item = item nav_item = item
nav_type = "html" 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 break
except Exception as e: except Exception as e:
continue continue
@@ -533,7 +535,9 @@ class HandlerDialog(QDialog):
pass pass
# Fallback: if slice_html is empty, try to get the whole file's text # Fallback: if slice_html is empty, try to get the whole file's text
if not slice_html.strip() and current_doc_html: 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 slice_html = current_doc_html
if slice_html.strip(): if slice_html.strip():
slice_soup = BeautifulSoup(slice_html, "html.parser") slice_soup = BeautifulSoup(slice_html, "html.parser")
@@ -637,7 +641,9 @@ class HandlerDialog(QDialog):
if src: if src:
base_href, fragment = src.split("#", 1) if "#" in src else (src, None) 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: if not doc_key:
logging.warning( logging.warning(
f"Navigation entry '{title}' points to '{base_href}', which is not in the spine or document list (even after basename fallback)." 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 fragment = None
if src: if src:
base_href, fragment = src.split("#", 1) if "#" in src else (src, None) 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: if doc_key is not None:
position = find_position_func(doc_key, fragment) position = find_position_func(doc_key, fragment)
entry_data = { entry_data = {
+7 -5
View File
@@ -434,8 +434,8 @@ class ConversionThread(QThread):
) )
# Only check for files with allowed extensions (extension without dot, case-insensitive) # Only check for files with allowed extensions (extension without dot, case-insensitive)
clash = any( clash = any(
os.path.splitext(fname)[0] == f"{base_name}{suffix}" and os.path.splitext(fname)[0] == f"{base_name}{suffix}"
os.path.splitext(fname)[1][1:].lower() in allowed_exts and os.path.splitext(fname)[1][1:].lower() in allowed_exts
for fname in os.listdir(parent_dir) for fname in os.listdir(parent_dir)
) )
if not os.path.exists(chapters_out_dir_candidate) and not clash: if not os.path.exists(chapters_out_dir_candidate) and not clash:
@@ -485,8 +485,8 @@ class ConversionThread(QThread):
merged_out_file = None merged_out_file = None
ffmpeg_proc = None ffmpeg_proc = None
metadata_options = ( metadata_options = (
self._extract_and_add_metadata_tags_to_ffmpeg_cmd() self._extract_and_add_metadata_tags_to_ffmpeg_cmd()
) )
# Prepare ffmpeg command for m4b output # Prepare ffmpeg command for m4b output
cmd = [ cmd = [
"ffmpeg", "ffmpeg",
@@ -680,7 +680,9 @@ class ConversionThread(QThread):
continue continue
# Open chapter subtitle file for incremental writing if needed # Open chapter subtitle file for incremental writing if needed
chapter_subtitle_file = None 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": if self.subtitle_mode != "Disabled":
subtitle_format = getattr(self, "subtitle_format", "srt") subtitle_format = getattr(self, "subtitle_format", "srt")
file_extension = "ass" if "ass" in subtitle_format else "srt" file_extension = "ass" if "ass" in subtitle_format else "srt"
+3
View File
@@ -32,11 +32,13 @@ os.environ["MIOPEN_CONV_PRECISE_ROCM_TUNING"] = "0"
# Reset sleep states # Reset sleep states
atexit.register(prevent_sleep_end) atexit.register(prevent_sleep_end)
# Also handle signals (Ctrl+C, kill, etc.) # Also handle signals (Ctrl+C, kill, etc.)
def _cleanup_sleep(signum, frame): def _cleanup_sleep(signum, frame):
prevent_sleep_end() prevent_sleep_end()
sys.exit(0) sys.exit(0)
signal.signal(signal.SIGINT, _cleanup_sleep) signal.signal(signal.SIGINT, _cleanup_sleep)
signal.signal(signal.SIGTERM, _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": if platform.system() == "Darwin" and platform.processor() == "arm":
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
# Custom message handler to filter out specific Qt warnings # Custom message handler to filter out specific Qt warnings
def qt_message_handler(mode, context, message): def qt_message_handler(mode, context, message):
if "Wayland does not support QWindow::requestActivate()" in message: if "Wayland does not support QWindow::requestActivate()" in message:
+11 -3
View File
@@ -74,24 +74,32 @@ def get_user_config_path():
if os.path.exists(custom_dir): if os.path.exists(custom_dir):
config_dir = custom_dir config_dir = custom_dir
else: 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: else:
# Windows and fallback case # 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") return os.path.join(config_dir, "config.json")
# Define cache path # Define cache path
def get_user_cache_path(folder=None): def get_user_cache_path(folder=None):
from platformdirs import user_cache_dir 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: if folder:
cache_dir = os.path.join(cache_dir, folder) cache_dir = os.path.join(cache_dir, folder)
# Ensure the directory exists # Ensure the directory exists
os.makedirs(cache_dir, exist_ok=True) os.makedirs(cache_dir, exist_ok=True)
return cache_dir return cache_dir
_sleep_procs = {"Darwin": None, "Linux": None} # Store sleep prevention processes _sleep_procs = {"Darwin": None, "Linux": None} # Store sleep prevention processes