dfdfdf
This commit is contained in:
@@ -24,9 +24,9 @@ import json
|
||||
# Add parent directory to path for imports
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
# Import cmdlets system to call get-tag
|
||||
# Import cmdlet system to call get-tag
|
||||
try:
|
||||
from cmdlets import get as get_cmdlet
|
||||
from cmdlet import get as get_cmdlet
|
||||
except ImportError:
|
||||
get_cmdlet = None
|
||||
|
||||
@@ -353,10 +353,10 @@ class DownloadModal(ModalScreen):
|
||||
|
||||
# Import cmdlet system
|
||||
if not get_cmdlet:
|
||||
logger.error("cmdlets module not available")
|
||||
logger.error("cmdlet module not available")
|
||||
self.app.call_from_thread(
|
||||
self.app.notify,
|
||||
"Cmdlets system unavailable",
|
||||
"cmdlet system unavailable",
|
||||
title="Error",
|
||||
severity="error"
|
||||
)
|
||||
@@ -1323,10 +1323,10 @@ class DownloadModal(ModalScreen):
|
||||
|
||||
# Call get-tag cmdlet to scrape URL
|
||||
if not get_cmdlet:
|
||||
logger.error("cmdlets module not available")
|
||||
logger.error("cmdlet module not available")
|
||||
self.app.call_from_thread(
|
||||
self.app.notify,
|
||||
"cmdlets module not available",
|
||||
"cmdlet module not available",
|
||||
title="Error",
|
||||
severity="error"
|
||||
)
|
||||
@@ -1563,13 +1563,13 @@ class DownloadModal(ModalScreen):
|
||||
"""
|
||||
# Import cmdlet system
|
||||
if not get_cmdlet:
|
||||
error_msg = "cmdlets module not available"
|
||||
error_msg = "cmdlet module not available"
|
||||
logger.error(error_msg)
|
||||
if worker:
|
||||
worker.append_stdout(f"❌ ERROR: {error_msg}\n")
|
||||
self.app.call_from_thread(
|
||||
self.app.notify,
|
||||
"Cmdlets system unavailable",
|
||||
"cmdlet system unavailable",
|
||||
title="Error",
|
||||
severity="error"
|
||||
)
|
||||
|
||||
@@ -14,9 +14,9 @@ import asyncio
|
||||
|
||||
# Add parent directory to path for imports
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
from config import load_config
|
||||
from config import load_config, resolve_output_dir
|
||||
from result_table import ResultTable
|
||||
from Provider.registry import get_search_provider
|
||||
from ProviderCore.registry import get_search_provider
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -236,7 +236,7 @@ class SearchModal(ModalScreen):
|
||||
selected_row = self.results_table.cursor_row
|
||||
if 0 <= selected_row < len(self.current_results):
|
||||
result = self.current_results[selected_row]
|
||||
if result.get("source") == "openlibrary":
|
||||
if getattr(result, "table", "") == "openlibrary":
|
||||
asyncio.create_task(self._download_book(result))
|
||||
else:
|
||||
logger.warning("[search-modal] Download only supported for OpenLibrary results")
|
||||
@@ -330,49 +330,29 @@ class SearchModal(ModalScreen):
|
||||
logger.info(f"[search-modal] Populated tags textarea from result")
|
||||
|
||||
async def _download_book(self, result: Any) -> None:
|
||||
"""Download a book from OpenLibrary using unified downloader."""
|
||||
"""Download a book from OpenLibrary using the provider."""
|
||||
if getattr(result, "table", "") != "openlibrary":
|
||||
logger.warning("[search-modal] Download only supported for OpenLibrary results")
|
||||
return
|
||||
|
||||
try:
|
||||
from Provider.unified_book_downloader import UnifiedBookDownloader
|
||||
from config import load_config
|
||||
|
||||
# Convert SearchResult to dict if needed
|
||||
if hasattr(result, 'to_dict'):
|
||||
result_dict = result.to_dict()
|
||||
# Ensure raw_data is populated for downloader
|
||||
if 'raw_data' not in result_dict and result.full_metadata:
|
||||
result_dict['raw_data'] = result.full_metadata
|
||||
else:
|
||||
result_dict = result
|
||||
|
||||
logger.info(f"[search-modal] Starting download for: {result_dict.get('title')}")
|
||||
|
||||
config = load_config()
|
||||
downloader = UnifiedBookDownloader(config=config)
|
||||
|
||||
# Get download options for this book
|
||||
options = downloader.get_download_options(result_dict)
|
||||
|
||||
if not options['methods']:
|
||||
logger.warning(f"[search-modal] No download methods available for: {result_dict.get('title')}")
|
||||
# Could show a modal dialog here
|
||||
output_dir = resolve_output_dir(config)
|
||||
|
||||
provider = get_search_provider("openlibrary", config=config)
|
||||
if not provider:
|
||||
logger.error("[search-modal] Provider not available: openlibrary")
|
||||
return
|
||||
|
||||
# For now, use the first available method (we could show a dialog to choose)
|
||||
method = options['methods'][0]
|
||||
logger.info(f"[search-modal] Using download method: {method.get('label')}")
|
||||
|
||||
# Perform the download
|
||||
success, message = await downloader.download_book(method)
|
||||
|
||||
if success:
|
||||
logger.info(f"[search-modal] Download successful: {message}")
|
||||
# Could show success dialog
|
||||
|
||||
title = getattr(result, "title", "")
|
||||
logger.info(f"[search-modal] Starting download for: {title}")
|
||||
|
||||
downloaded = await asyncio.to_thread(provider.download, result, output_dir)
|
||||
if downloaded:
|
||||
logger.info(f"[search-modal] Download successful: {downloaded}")
|
||||
else:
|
||||
logger.warning(f"[search-modal] Download failed: {message}")
|
||||
# Could show error dialog
|
||||
|
||||
downloader.close()
|
||||
|
||||
logger.warning(f"[search-modal] Download failed for: {title}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[search-modal] Download error: {e}", exc_info=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user