Refactor code structure for improved readability and maintainability
This commit is contained in:
BIN
dist/renamer-0.6.7-py3-none-any.whl
vendored
Normal file
BIN
dist/renamer-0.6.7-py3-none-any.whl
vendored
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "renamer"
|
name = "renamer"
|
||||||
version = "0.6.6"
|
version = "0.6.7"
|
||||||
description = "Terminal-based media file renamer and metadata viewer"
|
description = "Terminal-based media file renamer and metadata viewer"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
|
|||||||
@@ -465,18 +465,33 @@ By Category:"""
|
|||||||
|
|
||||||
tree = self.query_one("#file_tree", Tree)
|
tree = self.query_one("#file_tree", Tree)
|
||||||
parent_dir = file_path.parent
|
parent_dir = file_path.parent
|
||||||
|
logging.info(f"Looking for parent directory node: {parent_dir}")
|
||||||
|
logging.info(f"Scan directory: {self.scan_dir}")
|
||||||
|
|
||||||
# Find the parent directory node
|
# Check if parent directory is the scan directory (root level)
|
||||||
def find_node(node):
|
# If so, the parent node is the tree root itself
|
||||||
if node.data == parent_dir:
|
parent_node = None
|
||||||
return node
|
|
||||||
for child in node.children:
|
if self.scan_dir and parent_dir.resolve() == self.scan_dir.resolve():
|
||||||
found = find_node(child)
|
logging.info("File is in root scan directory, using tree.root as parent")
|
||||||
if found:
|
parent_node = tree.root
|
||||||
return found
|
else:
|
||||||
return None
|
# Find the parent directory node in the tree
|
||||||
|
def find_node(node, depth=0):
|
||||||
|
if node.data and isinstance(node.data, Path):
|
||||||
|
logging.info(f"{' ' * depth}Checking node: data={node.data}")
|
||||||
|
# Resolve both paths to absolute for comparison
|
||||||
|
if node.data.resolve() == parent_dir.resolve():
|
||||||
|
logging.info(f"{' ' * depth}Found match! node.data={node.data}")
|
||||||
|
return node
|
||||||
|
for child in node.children:
|
||||||
|
found = find_node(child, depth + 1)
|
||||||
|
if found:
|
||||||
|
return found
|
||||||
|
return None
|
||||||
|
|
||||||
|
parent_node = find_node(tree.root)
|
||||||
|
|
||||||
parent_node = find_node(tree.root)
|
|
||||||
if parent_node:
|
if parent_node:
|
||||||
logging.info(f"Found parent node for {parent_dir}, adding file {file_path.name}")
|
logging.info(f"Found parent node for {parent_dir}, adding file {file_path.name}")
|
||||||
|
|
||||||
@@ -511,6 +526,9 @@ By Category:"""
|
|||||||
).start()
|
).start()
|
||||||
else:
|
else:
|
||||||
logging.warning(f"No parent node found for {parent_dir}")
|
logging.warning(f"No parent node found for {parent_dir}")
|
||||||
|
logging.warning(f"Rescanning entire tree instead")
|
||||||
|
# If we can't find the parent node, just rescan the whole tree
|
||||||
|
self.scan_files()
|
||||||
|
|
||||||
def on_key(self, event):
|
def on_key(self, event):
|
||||||
if event.key == "right":
|
if event.key == "right":
|
||||||
|
|||||||
@@ -437,32 +437,11 @@ Do you want to proceed with conversion?
|
|||||||
def on_mount(self):
|
def on_mount(self):
|
||||||
self.set_focus(self.query_one("#convert"))
|
self.set_focus(self.query_one("#convert"))
|
||||||
|
|
||||||
def _handle_conversion_success(self, mkv_path, message):
|
|
||||||
"""Handle successful conversion - called on main thread."""
|
|
||||||
import logging
|
|
||||||
try:
|
|
||||||
logging.info(f"_handle_conversion_success called: {mkv_path}")
|
|
||||||
self.app.notify(f"✓ {message}", severity="information", timeout=5) # type: ignore
|
|
||||||
logging.info(f"Adding file to tree: {mkv_path}")
|
|
||||||
self.app.add_file_to_tree(mkv_path) # type: ignore
|
|
||||||
logging.info("Conversion success handler completed")
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error in _handle_conversion_success: {e}", exc_info=True)
|
|
||||||
|
|
||||||
def _handle_conversion_error(self, message):
|
|
||||||
"""Handle conversion error - called on main thread."""
|
|
||||||
import logging
|
|
||||||
try:
|
|
||||||
logging.info(f"_handle_conversion_error called: {message}")
|
|
||||||
self.app.notify(f"✗ {message}", severity="error", timeout=10) # type: ignore
|
|
||||||
logging.info("Conversion error handler completed")
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error in _handle_conversion_error: {e}", exc_info=True)
|
|
||||||
|
|
||||||
def on_button_pressed(self, event):
|
def on_button_pressed(self, event):
|
||||||
if event.button.id == "convert":
|
if event.button.id == "convert":
|
||||||
# Start conversion
|
# Start conversion
|
||||||
self.app.notify("Starting conversion...", severity="information", timeout=2) # type: ignore
|
app = self.app # type: ignore
|
||||||
|
app.notify("Starting conversion...", severity="information", timeout=2)
|
||||||
|
|
||||||
def do_conversion():
|
def do_conversion():
|
||||||
from .services.conversion_service import ConversionService
|
from .services.conversion_service import ConversionService
|
||||||
@@ -479,23 +458,27 @@ Do you want to proceed with conversion?
|
|||||||
|
|
||||||
logging.info(f"Conversion result: success={success}, message={message}")
|
logging.info(f"Conversion result: success={success}, message={message}")
|
||||||
|
|
||||||
# Schedule UI updates on the main thread using set_timer
|
# Schedule UI updates on the main thread
|
||||||
mkv_path = self.avi_path.with_suffix('.mkv')
|
mkv_path = self.avi_path.with_suffix('.mkv')
|
||||||
|
|
||||||
|
def handle_success():
|
||||||
|
logging.info(f"handle_success called: {mkv_path}")
|
||||||
|
app.notify(f"✓ {message}", severity="information", timeout=5)
|
||||||
|
logging.info(f"Adding file to tree: {mkv_path}")
|
||||||
|
app.add_file_to_tree(mkv_path)
|
||||||
|
logging.info("Conversion success handler completed")
|
||||||
|
|
||||||
|
def handle_error():
|
||||||
|
logging.info(f"handle_error called: {message}")
|
||||||
|
app.notify(f"✗ {message}", severity="error", timeout=10)
|
||||||
|
logging.info("Conversion error handler completed")
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
logging.info(f"Conversion successful, scheduling UI update for {mkv_path}")
|
logging.info(f"Conversion successful, scheduling UI update for {mkv_path}")
|
||||||
|
app.call_later(handle_success)
|
||||||
# Use app.set_timer to schedule callback on main thread
|
|
||||||
self.app.set_timer(
|
|
||||||
0.1, # Small delay to ensure main thread processes it
|
|
||||||
lambda: self._handle_conversion_success(mkv_path, message)
|
|
||||||
) # type: ignore
|
|
||||||
else:
|
else:
|
||||||
logging.error(f"Conversion failed: {message}")
|
logging.error(f"Conversion failed: {message}")
|
||||||
self.app.set_timer(
|
app.call_later(handle_error)
|
||||||
0.1,
|
|
||||||
lambda: self._handle_conversion_error(message)
|
|
||||||
) # type: ignore
|
|
||||||
|
|
||||||
# Run conversion in background thread
|
# Run conversion in background thread
|
||||||
import threading
|
import threading
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ class MediaPanelView:
|
|||||||
self._props.media_year,
|
self._props.media_year,
|
||||||
self._props.media_duration,
|
self._props.media_duration,
|
||||||
self._props.media_file_size,
|
self._props.media_file_size,
|
||||||
|
self._props.media_file_extension,
|
||||||
self._props.selected_frame_class,
|
self._props.selected_frame_class,
|
||||||
self._props.selected_source,
|
self._props.selected_source,
|
||||||
self._props.selected_special_info,
|
|
||||||
self._props.selected_audio_langs,
|
self._props.selected_audio_langs,
|
||||||
self._props.selected_database_info,
|
self._props.selected_database_info,
|
||||||
self._props.selected_order,
|
self._props.selected_order,
|
||||||
|
|||||||
@@ -376,6 +376,15 @@ class MediaPanelProperties:
|
|||||||
"""Get media file size formatted with label."""
|
"""Get media file size formatted with label."""
|
||||||
return self._extractor.get("file_size")
|
return self._extractor.get("file_size")
|
||||||
|
|
||||||
|
@property
|
||||||
|
@text_decorators.blue()
|
||||||
|
@conditional_decorators.wrap("Extension: ")
|
||||||
|
@text_decorators.green()
|
||||||
|
@extension_decorators.extension_info()
|
||||||
|
def media_file_extension(self) -> str:
|
||||||
|
"""Get media file extension formatted with label."""
|
||||||
|
return self._extractor.get("extension")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@text_decorators.blue()
|
@text_decorators.blue()
|
||||||
@conditional_decorators.wrap("Special info: ")
|
@conditional_decorators.wrap("Special info: ")
|
||||||
|
|||||||
Reference in New Issue
Block a user