This commit is contained in:
nose
2025-12-06 00:10:19 -08:00
parent 5482ee5586
commit f29709d951
20 changed files with 1353 additions and 419 deletions

View File

@@ -293,13 +293,7 @@ class LocalStorageProvider(SearchProvider):
class LibGenProvider(SearchProvider):
"""Search provider for Library Genesis books."""
# Define fields to display (note: LibGen doesn't have API field mapping like OpenLibrary)
# These are extracted from the book dict directly
RESULT_FIELDS = [
("title", "Title", None),
("author", "Author(s)", None),
("year", "Year", None),
]
RESULT_FIELDS: List[Tuple[str, str, Optional[Any]]] = [] # columns built manually
def __init__(self, config: Dict[str, Any] = None):
super().__init__(config)
@@ -363,15 +357,22 @@ class LibGenProvider(SearchProvider):
search_results = []
for idx, book in enumerate(books, 1):
# Build columns dynamically from RESULT_FIELDS
columns = self.build_columns_from_doc(book, idx)
title = book.get("title", "Unknown")
author = book.get("author", "Unknown")
year = book.get("year", "Unknown")
pages = book.get("pages") or book.get("pages_str") or ""
extension = book.get("extension", "") or book.get("ext", "")
filesize = book.get("filesize_str", "Unknown")
isbn = book.get("isbn", "")
mirror_url = book.get("mirror_url", "")
# Columns: Title, Author, Pages, Ext
columns = [
("Title", title),
("Author", author),
("Pages", str(pages)),
("Ext", str(extension)),
]
# Build detail with author and year
detail = f"By: {author}"
@@ -1077,12 +1078,7 @@ class OpenLibraryProvider(SearchProvider):
"""Search provider for OpenLibrary."""
# Define fields to request from API and how to display them
RESULT_FIELDS = [
("title", "Title", None),
("author_name", "Author", lambda x: ", ".join(x) if isinstance(x, list) else x),
("first_publish_year", "Year", None),
("status", "Status", None),
]
RESULT_FIELDS: List[Tuple[str, str, Optional[Any]]] = [] # columns built manually
def __init__(self, config: Dict[str, Any] = None):
super().__init__(config)
@@ -1146,10 +1142,25 @@ class OpenLibraryProvider(SearchProvider):
return []
# Default to title/general search
requested_fields = [
"title",
"author_name",
"first_publish_year",
"number_of_pages_median",
"isbn",
"oclc_numbers",
"lccn",
"language",
"key",
"edition_key",
"ebook_access",
"ia",
"has_fulltext",
]
params = {
"q": query_clean,
"limit": limit,
"fields": f"{self.get_api_fields_string()},isbn,oclc_numbers,lccn,number_of_pages_median,language,key,ebook_access,ia,has_fulltext",
"fields": ",".join(requested_fields),
}
response = requests.get(search_url, params=params, timeout=9)
@@ -1158,16 +1169,18 @@ class OpenLibraryProvider(SearchProvider):
search_results = []
for idx, doc in enumerate(data.get("docs", []), 1):
# Extract OLID first (needed for metadata)
olid = doc.get("key", "").split("/")[-1]
# Prefer edition_key (books/OLxxxM). Fallback to work key.
edition_keys = doc.get("edition_key") or []
olid = ""
if isinstance(edition_keys, list) and edition_keys:
olid = str(edition_keys[0]).strip()
if not olid:
olid = doc.get("key", "").split("/")[-1]
# Determine status/availability
status, archive_id = self._derive_status(doc)
doc["status"] = status
# Build columns dynamically from RESULT_FIELDS (now includes status)
columns = self.build_columns_from_doc(doc, idx)
# Extract additional metadata
title = doc.get("title", "Unknown")
authors = doc.get("author_name", ["Unknown"])
@@ -1183,6 +1196,13 @@ class OpenLibraryProvider(SearchProvider):
language = languages[0] if languages else ""
author_str = ", ".join(authors) if authors else "Unknown"
# Columns: Title, Author, Pages
columns = [
("Title", title),
("Author", author_str),
("Pages", str(pages or "")),
]
# Build detail with author and year
detail = f"By: {author_str}"