Lightweight parser for Batoto-style manga sites with CLI and library support
Project description
Batoto Parser
Lightweight parser for Batoto-style manga sites. Provides both a command-line interface and a Python library for:
- 📚 Listing/browsing manga
- 🔍 Searching manga
- 📖 Fetching manga details (metadata + chapters)
- 🖼️ Retrieving chapter pages (with encrypted image URL decryption)
Features
- CLI Tool: Easy-to-use command-line interface with rich output
- Python Library: Import and use in your own projects
- Flexible: Works with any Batoto-style manga site
- Fast: Efficient parsing with minimal dependencies
- Typed: Full type hints for better IDE support
Requirements
- Python 3.8+
- Node.js (required for chapter page decryption)
Installing Node.js (Linux)
Debian/Ubuntu:
sudo apt update && sudo apt install -y nodejs
Fedora/RHEL:
sudo dnf install nodejs
Arch Linux:
sudo pacman -S nodejs
Installation
From PyPI (recommended)
pip install batoto-parser
From source
git clone https://github.com/yourusername/batoto-parser.git
cd batoto-parser
pip install -e .
Development installation
pip install -e ".[dev]"
CLI Usage
After installation, the batoto-parser command will be available:
List/Browse Manga
# Browse first page
batoto-parser list
# Browse specific page
batoto-parser list --page 2
# Search for manga
batoto-parser list --query "one piece"
# Save results to file
batoto-parser list --page 1 --output results.json
# Use different domain
batoto-parser list --domain custom-site.com
Get Manga Details
# By path
batoto-parser details /series/Some-Manga
# By full URL
batoto-parser details https://bato.to/series/Some-Manga
# Save to file
batoto-parser details /series/Some-Manga --output manga.json
Get Chapter Pages
# Get image URLs for a chapter
batoto-parser pages /reader/12345
# Save to file
batoto-parser pages /reader/12345 --output chapter.json
Options
All commands support:
--domain, -d: Specify domain (default: bato.to)--output, -O: Save output to file instead of stdout--pretty/--compact: Pretty-print or compact JSON output--help: Show detailed help
Library Usage
Use batoto-parser as a library in your Python projects:
from batoto_parser import BatoToParser, MangaLoaderContext
# Initialize
ctx = MangaLoaderContext()
parser = BatoToParser(ctx, domain="bato.to")
# List manga
mangas = parser.get_list(page=1)
for manga in mangas:
print(f"{manga.title}: {manga.public_url}")
# Search
results = parser.get_list(page=1, query="one piece")
# Get details
detailed_manga = parser.get_details(mangas[0])
print(f"Chapters: {detailed_manga.chapterCount}")
# Get chapter pages (requires Node.js)
pages = parser.get_pages("/reader/12345")
for page in pages:
print(f"Page {page.pageNumber}: {page.imageUrl}")
See examples/example_usage.py for more examples.
Project Structure
batoto-parser/
├── src/
│ └── batoto_parser/
│ ├── __init__.py # Package exports
│ ├── __version__.py # Version info
│ ├── cli.py # CLI interface (Typer)
│ ├── parser.py # Main parser logic
│ ├── context.py # HTTP session & JS eval
│ ├── utils.py # Crypto & utility functions
│ └── models.py # Data models
├── tests/ # Test suite
├── examples/ # Usage examples
└── pyproject.toml # Package configuration
API Reference
Core Classes
-
BatoToParser: Main parser classget_list(page, order, query): List/search mangaget_details(manga): Get detailed manga infoget_pages(chapter_url): Get chapter image URLs
-
MangaLoaderContext: HTTP session manager with JS evaluation -
Manga: Manga data model -
MangaChapter: Chapter data model -
MangaPage: Page data model
Utility Functions
generate_uid(url): Generate unique ID from URLdecrypt_batoto(encrypted, password): Decrypt Batoto image URLsevp_bytes_to_key(...): OpenSSL key derivation
Development
Setup
# Clone repository
git clone https://github.com/mehrinshamim/batoto-parser.git
cd batoto-parser
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install with dev dependencies
pip install -e ".[dev]"
Testing
# Run tests
pytest
# With coverage
pytest --cov=batoto_parser --cov-report=html
# Run only unit tests (skip integration tests)
pytest -m "not integration"
Code Quality
# Format code
black src/ tests/
# Lint
ruff check src/ tests/
# Type check
mypy src/
Troubleshooting
"Cannot evaluate batoPass" error
Ensure Node.js is installed and available on your PATH:
node --version # Should show version number
Empty results
If parsing returns empty results, the site layout may have changed. Check:
- Site is accessible
- Selectors in
parser.pymatch current HTML structure
Network errors
Add timeouts or retries in context.py for unstable connections.
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer
This tool is for educational purposes only. Please respect the websites' terms of service and robots.txt. The authors are not responsible for misuse of this tool.
Changelog
0.1.0 (2024-XX-XX)
- Initial release
- CLI tool with list, details, and pages commands
- Library API for programmatic access
- Support for custom domains
- Rich terminal output
- Full test suite
Acknowledgments
- Built with Typer for CLI
- Rich for beautiful terminal output
- BeautifulSoup for HTML parsing
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file batoto_parser-0.1.0.tar.gz.
File metadata
- Download URL: batoto_parser-0.1.0.tar.gz
- Upload date:
- Size: 27.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
467dbd60a77705680bc497090f8f6ec779af4c1051848277da813ca9c16909c5
|
|
| MD5 |
a30839b8d86eb4c552b8b522fae8478e
|
|
| BLAKE2b-256 |
f55d27589867f63a0c72dac44c56fe1f129d5756a588ad9025c64c9dd833c683
|
File details
Details for the file batoto_parser-0.1.0-py3-none-any.whl.
File metadata
- Download URL: batoto_parser-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e27dbc9f042b0d2bfc01264fb0ae0d423f308865afc00b3494b573eb2e55236
|
|
| MD5 |
fb9ac3272ea5b2035a2efc02bd28fd0c
|
|
| BLAKE2b-256 |
ee12ec9a8dd6f96e57d160867a48aa63984a6752bccc2fc347dbcc59eca8baaf
|