Metadata-Version: 2.1
Name: libgen-api-modern
Version: 1.0.0
Summary: Search Library Genesis. This library enables you to search Library Genesis programmatically.
License: MIT
Keywords: libgen,library genesis,library,genesis,search,download,books,articles,non-fiction,fiction,sci-tech,sci-mag,scientific,magazines
Author: Johnnie
Author-email: johnnie610@duck.com
Requires-Python: >=3.9,<4.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Dist: aiohttp (>=3.12.0,<4.0.0)
Requires-Dist: requests (>=2.32.3,<3.0.0)
Requires-Dist: rich (>=14.0.0,<15.0.0)
Project-URL: Repository, https://github.com/Johnnie610/libgen-api-modern
Description-Content-Type: text/markdown

# Libgen API Modern

Libgen-API-Modern is a lightweight, simple, and blazingly fast Python library for interacting with Library Genesis. It provides both synchronous and asynchronous methods to search for and resolve download links for books, all with a modern and elegant interface.

This library focuses exclusively on the modern Libgen web interface, ensuring high performance and reliability without the need for fallbacks to older, less structured APIs.

## Features

- **Blazingly Fast:** Optimized for speed with efficient HTML parsing and direct API interaction.
- **Async & Sync:** Provides both `async` and `sync` functions to fit any project architecture.
- **Simple & Elegant API:** A clean and minimal set of functions (`search_async`, `search_sync`).
- **Direct Download Link Resolution:** Intelligently parses mirror pages to find the most direct and reliable download links.
- **Robust Data Models:** Search results are returned as `BookData` objects for consistent and predictable data handling.
- **Minimal Dependencies:** Built with `aiohttp`, `requests`, and `rich` to keep the library lightweight.
- **Versatile CLI:** A powerful command-line tool for searching, downloading, and interactive sessions.

## Installation

```bash
pip install libgen-api-modern
```

## Usage as a Library

The core functions are `search_async` and `search_sync`. Both return a list of `BookData` objects.

### Asynchronous Example

```python
import asyncio
from libgen import search_async, LibgenError

async def main():
    try:
        results = await search_async("the art of war")
        if not results:
            print("No results found.")
            return

        for book in results:
            print(f"Title: {book.title}")
            print(f"Authors: {', '.join(book.authors) if book.authors else 'N/A'}")
            if book.download_links and book.download_links.get_link:
                print(f"Direct Download: {book.download_links.get_link}")
            print("-" * 40)

    except LibgenError as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    asyncio.run(main())
```

### Synchronous Example

```python
from libgen import search_sync, LibgenError

try:
    results = search_sync("the art of war")
    if not results:
        print("No results found.")
    else:
        for book in results:
            print(f"Title: {book.title}")
            print(f"Authors: {', '.join(book.authors) if book.authors else 'N/A'}")
            if book.download_links and book.download_links.get_link:
                print(f"Direct Download: {book.download_links.get_link}")
            print("-" * 40)
except LibgenError as e:
    print(f"An error occurred: {e}")
```

## Usage as a Command-Line Tool

The CLI offers three main commands.

### Search

```bash
libgen search "the art of war"
```

### Download

Download a file directly from a known Libgen mirror URL.

```bash
libgen download "MIRROR_URL" --output "mybook.pdf"
```

### Interactive Mode

For repeated searches and downloads in a single session.

```bash
libgen interactive
```

## License

This project is licensed under the **MIT License**.
