Skip to main content

A python library for reading osz2 files

Project description

osz2.py

Python Version GitHub License GitHub Actions Workflow Status

osz2.py is a Python library for reading osz2 files. It's a direct port of the existing Osz2Decryptor project by xxCherry and osz2-go by me. The Python port itself was done by @ascenttree; all credit goes to them.

Installation

pip install osz2

Or install from source:

git clone https://github.com/Lekuruu/osz2.py
cd osz2.py
pip install -e .

Usage

This repository provides a command-line interface for easy testing:

python cli.py <input.osz2> <output_directory>

But that's not all!
Here is an example of how to use osz2.py as a library:

from osz2 import Osz2Package, MetadataType

# Parse package from file
package = Osz2Package.from_file("beatmap.osz2")

# Access metadata
print("Title:", package.metadata.get(MetadataType.Title))
print("Artist:", package.metadata.get(MetadataType.Artist))
print("Creator:", package.metadata.get(MetadataType.Creator))
print("Difficulty:", package.metadata.get(MetadataType.Difficulty))

# Access files
for file in package.files:
    print(f"File: {file.filename}, Size: {len(file.content)} bytes")

# Extract specific files
for file in package.files:
    if not file.filename.endswith(".osu"):
        continue

    with open(file.filename, "wb") as f:
        f.write(file.content)

Metadata-only Mode

If you only need to read metadata without extracting files, you can use the metadata_only parameter:

# Only parse metadata
package = Osz2Package.from_file("beatmap.osz2", metadata_only=True)

# Access metadata
print("Title:", package.metadata.get(MetadataType.Title))
print("BeatmapSet ID:", package.metadata.get(MetadataType.BeatmapSetID))

Alternative Constructors

# From file path
package = Osz2Package.from_file("beatmap.osz2")

# From bytes
with open("beatmap.osz2", "rb") as f:
    data = f.read()
    package = Osz2Package.from_bytes(data)

# From an io.BufferedReader-like object, e.g. a file stream
with open("beatmap.osz2", "rb") as f:
    package = Osz2Package(f)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

osz2-1.0.2.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

osz2-1.0.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file osz2-1.0.2.tar.gz.

File metadata

  • Download URL: osz2-1.0.2.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for osz2-1.0.2.tar.gz
Algorithm Hash digest
SHA256 ad9e1d23533487e07af58f435f12405ba8e4baebeea2b01f2941a307c9564683
MD5 ffee0fe396188967209194983d1dd844
BLAKE2b-256 e3d73a04274ee05897168c815b4c8320d3dccbccf3387d863d1cc07e2e8506aa

See more details on using hashes here.

File details

Details for the file osz2-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: osz2-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for osz2-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c252f535e7a176921759326ebe1765f2ae7398dad6c23f6ecc590b6fe9ccac69
MD5 55d4b340336814c2c6e56bb4491ea01f
BLAKE2b-256 46f9176026a4d0248e6f85be53b2c0b301c8a9f5d1dd73f7de64e06b51f7a0a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page