D2R Loot Reader
A Python library for parsing Diablo II: Resurrected item tooltips into structured JSON data.
D2R Loot Reader is a technical tool designed for developers, modders, and enthusiasts building applications for the Diablo II: Resurrected community. It uses advanced OCR (Optical Character Recognition) and fuzzy string matching to convert in-game item tooltips into machine-readable JSON format.
🎯 Use Cases
- Loot Tracking Applications: Build tools to track valuable drops and analyze loot statistics
- Trading Platforms: Create automated item cataloging for trading websites
- Game Enhancement Tools: Develop overlays or assistants that provide item information
- Data Analysis: Extract item data for statistical analysis and game research
🚀 Quick Start
Prerequisites
- Python 3.8+
- Tesseract OCR
Installation
pip install d2r-loot-reader
CLI Command
# Interactive screen capture, OCR and JSON parsing
d2rlootreader capture
Basic Usage
from d2rlootreader.item_parser import ItemParser
# Parse tooltip text lines into structured JSON
lines = [
"Rare Ring",
"Required Level: 15",
"+25 to Life",
"+15% Faster Cast Rate"
]
parser = ItemParser(lines)
item_data = parser.parse_item_lines_to_json()
print(item_data)
📊 Output Format
The parser produces structured JSON following this schema:
{
"quality": "Unique|Set|Rare|Magic|Runeword|Base",
"name": "Fortitude",
"base": "Great Hauberk",
"slot": "Body",
"tier": "Elite",
"requirements": {"strength": 118, "level": 59},
"stats": {"defense": [1596]},
"affixes": [
["#% Chance to cast level # [Skill] when struck", [20, 15, "Chilling Armor"]],
["+#% Faster Cast Rate", [25]],
["+#% Enhanced Damage", [300]],
["+#% Enhanced Defense", [215]],
["+# Defense", [15]],
["+# to Life (Based on Character Level)", [101]],
["Replenish Life +#", [7]],
["+#% to Maximum Lightning Resist", [5]],
["All Resistances +#", [29]],
["Damage Reduced by #", [7]],
["+#% Damage Taken Goes To Mana", [12]],
["+# to Light Radius", [1]],
["Increase Maximum Durability #%", [13]],
["Socketed (#)", [4]]
],
"tooltip": ["Fortitude", "Great Hauberk", "'ElSolDolLo'", "Defense: 1596", ...]
}
🔧 Technical Architecture
Core Components
- OCR Engine: Custom-trained Tesseract model optimized for D2R fonts
- Fuzzy Matching: RapidFuzz-powered intelligent text matching with typo tolerance
- Image Processing: OpenCV-based preprocessing for optimal OCR accuracy
- Data Repository: Comprehensive JSON databases of all D2R items, affixes, and skills
Repository Files
The library includes extensive game data mappings:
affixes.json- All possible item modifiers and their templatesbases.json- Base item types with slots and tiersuniques.json,set.json,runewords.json- Named item databasesmagic.json,rares.json- Prefix/suffix combinationsskills.json,classes.json- Character abilities and class restrictionsrequirements.json,stats.json- Item requirements and base statistics
Intelligent Parsing Features
- Template Matching: Supports complex affix patterns like
"+# to # [Skill] ([Class] Only)" - OCR Error Correction: Handles common misreads (0→O, 1→l, 5→S, etc.)
- Context-Aware Classification: Distinguishes between item types using multiple signals
- Fuzzy Thresholds: Configurable matching sensitivity for various game data types
📸 Image Requirements
For optimal results, captured tooltip images should:
- Start with item name as the first line (crop out shop prices/vendor info)
- Have clear, unobstructed text
- Include the complete tooltip from name to last affix
- Use game's default UI scaling when possible
See example tooltip images in the tests/tooltips/ directory.
🛠️ Advanced Usage
Custom OCR Configuration
from d2rlootreader.screen import capture_screen, preprocess
from d2rlootreader.item_parser import ItemParser
import pytesseract
# Capture and process with custom settings
image = capture_screen()
processed = preprocess(image, mode="adaptive")
# Extract text with custom OCR config
text = pytesseract.image_to_string(processed, lang="d2r", config="--psm 6")
lines = [line.strip() for line in text.splitlines() if line.strip()]
# Parse with debugging
parser = ItemParser(lines)
result = parser.parse_item_lines_to_json()
Interactive Region Selection
from d2rlootreader.region_selector import select_region
# Full-screen overlay for precise tooltip selection
selected_image = select_region()
Batch Processing
import glob
from pathlib import Path
# Process multiple tooltip images
for image_path in glob.glob("tooltips/*.png"):
# Your processing logic here
pass
⚠️ Current Limitations
This is an early-stage tool with known limitations:
- Special Characters: Some Unicode symbols may not parse correctly
- Font Variations: Works best with Large Font Mode enable in game settings
- Supported languages: English language only
Contributions and bug reports are welcome to improve parsing accuracy.
🧪 Development
Setup Development Environment
git clone https://github.com/lucekdudek/d2r-loot-reader.git
cd d2r-loot-reader
pip install -e .[dev]
Code Quality Tools
# Format code
black .
isort .
# Run tests
pytest tests/
Testing with Sample Data
# Test with included tooltip samples
python -m pytest tests/test_item_parser.py -v
📝 Contributing
This project welcomes contributions from the D2R community:
- Item Database Updates: Add missing items, affixes, or skills
- OCR Improvements: Enhance text recognition accuracy
- Parser Logic: Handle edge cases and special item types
- Documentation: Improve guides and examples
📄 License
This project is licensed under the GPL-3.0-or-later license. See the LICENSE file for details.
Third-Party Components
This project includes the custom Tesseract training data from the "horadricapp" project by stephaistos, licensed under the MIT License. The component is located in third_party/horadricapp/ with full attribution and license details.
Metadata
Release files for d2r-loot-reader 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| d2r_loot_reader-0.1.0.tar.gz | 12.9 MB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| d2r_loot_reader-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.7 MB
Release files / d2r_loot_reader-0.1.0.tar.gz
| Download URL | d2r_loot_reader-0.1.0.tar.gz |
|---|---|
| Size | 12.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a6602e00c1474e3fd2a91b51aaeaf9394fab2ba46001d558393585cde04b0b7
|
|
BLAKE2b-256 checksum How to use checksums |
3b06b9aba5c3fd35f6634505c8624bd0033a4569ac02daf2edc26b3b6e817e57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2025.
Transparency logRelease files / d2r_loot_reader-0.1.0-py3-none-any.whl
| Download URL | d2r_loot_reader-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.9 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3cac38d26a1a7bd79e2800576f7dd9bbd451053568e78c6d5bf6ce0556012256
|
|
BLAKE2b-256 checksum How to use checksums |
b7420c6d152098778197b09b3aaa51aa2f33a816ec0e716bf6460b05762eaa49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2025.
Transparency logSecurity for d2r-loot-reader 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for d2r_loot_reader-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.