rosu-replay
A Rust library for parsing and writing osu! replay files (.osr format).
This library is a faithful port of the Python osrparse library, providing the same functionality for parsing and manipulating osu! replay files in Rust with improved performance and memory safety.
Features
- 🎮 Parse .osr replay files from disk or memory
- 📊 Extract complete replay metadata including:
- Player information (username, score, combo, etc.)
- Game metadata (mode, mods, timestamp, etc.)
- Hit statistics (300s, 100s, 50s, misses, etc.)
- Replay events (cursor movement, key presses)
- Life bar data over time
- 💾 Write replay files back to .osr format
- 🎯 Support all game modes: osu!standard, osu!taiko, osu!catch, osu!mania
- 🌐 API compatibility for parsing replay data from osu! API v1 responses
- ⚡ High performance with zero-copy parsing where possible
- 🦀 Memory safe Rust implementation
- 📖 Comprehensive documentation and examples
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start
Parsing a Replay File
use Replay;
Working with Replay Events
use ;
let replay = from_path?;
// Iterate through replay events
for in replay.replay_data.iter.enumerate.take
Modifying and Writing Replays
use Replay;
let mut replay = from_path?;
// Modify replay data
replay.username = "Modified Player".to_string;
replay.score = 1000000;
// Write to a new file
replay.write_path?;
Working with API Data
use ;
use ;
// Example: parsing replay data from osu! API v1
let api_response = "base64_encoded_replay_data_from_api";
let decoded_data = STANDARD.decode?;
// Parse the replay events
let events = parse_replay_data?;
for event in events.iter.take
Examples
Check out the examples/ directory for more comprehensive usage examples:
# Run the basic example (requires test.osr in assets/ directory)
# Generate documentation with examples
Game Mode Support
This library supports all osu! game modes:
| Mode | Enum | Description |
|---|---|---|
| osu!standard | GameMode::Std |
Traditional circle-clicking mode |
| osu!taiko | GameMode::Taiko |
Drum-based rhythm mode |
| osu!catch | GameMode::Catch |
Fruit-catching mode |
| osu!mania | GameMode::Mania |
Piano-style rhythm mode |
Each mode has its own event type with mode-specific data:
ReplayEventOsu: x/y coordinates and key statesReplayEventTaiko: drum hit positions and typesReplayEventCatch: horizontal position and dash stateReplayEventMania: key states for multiple lanes
File Format
The .osr format is a binary format used by osu! to store replay data. This library handles:
- All metadata fields (player, score, mods, etc.)
- LZMA-compressed replay event data
- Life bar data
- Timestamp conversion between Windows ticks and Unix timestamps
- Both old (32-bit) and new (64-bit) replay ID formats
Attribution
This library is a port of the excellent Python osrparse library by kszlim and contributors. The original Python implementation provided the foundation for understanding the .osr file format and replay data structures.
Original Python library: https://github.com/kszlim/osu-replay-parser
While this Rust port maintains API compatibility where possible, it leverages Rust's type system and memory safety features to provide additional guarantees and performance improvements.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- kszlim and contributors for the original
osrparsePython library - The osu! community for documenting the .osr file format
- ppy for creating osu! and maintaining the replay format