-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from kszlim/restructure
osrparse 6.0.0
- Loading branch information
Showing
14 changed files
with
863 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line, and also | ||
# from the environment for the first two. | ||
SPHINXOPTS ?= | ||
SPHINXBUILD ?= sphinx-build | ||
SOURCEDIR = docs | ||
BUILDDIR = build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Appendix | ||
======== | ||
|
||
Replay | ||
------ | ||
.. automodule:: osrparse.replay | ||
:members: | ||
|
||
Utils | ||
----- | ||
.. automodule:: osrparse.utils | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# This file only contains a selection of the most common options. For a full | ||
# list see the documentation: | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html | ||
|
||
from osrparse import __version__ | ||
|
||
project = "osrparse" | ||
copyright = "2022, Kevin Lim, Liam DeVoe" | ||
author = "Kevin Lim, Liam DeVoe" | ||
release = "v" + __version__ | ||
version = "v" + __version__ | ||
master_doc = 'index' | ||
|
||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_show_copyright | ||
html_show_copyright = False | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_show_sphinx | ||
html_show_sphinx = False | ||
|
||
extensions = [ | ||
"sphinx.ext.autodoc", | ||
"sphinx.ext.napoleon", | ||
"sphinx.ext.intersphinx", | ||
"sphinx.ext.viewcode", | ||
"sphinx.ext.todo" | ||
] | ||
|
||
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)} | ||
# https://stackoverflow.com/a/37210251 | ||
autodoc_member_order = "bysource" | ||
|
||
html_theme = "furo" | ||
|
||
# Add any paths that contain templates here, relative to this directory. | ||
templates_path = ["_templates"] | ||
|
||
# List of patterns, relative to source directory, that match files and | ||
# directories to ignore when looking for source files. | ||
# This pattern also affects html_static_path and html_extra_path. | ||
exclude_patterns = [] | ||
|
||
|
||
# Add any paths that contain custom static files (such as style sheets) here, | ||
# relative to this directory. They are copied after the builtin static files, | ||
# so a file named "default.css" will overwrite the builtin "default.css". | ||
# html_static_path = ["_static"] | ||
|
||
# references that we want to use easily in any file | ||
rst_prolog = """ | ||
.. |Replay| replace:: :class:`~osrparse.replay.Replay` | ||
.. |from_path| replace:: :func:`Replay.from_path() <osrparse.replay.Replay.from_path>` | ||
.. |from_file| replace:: :func:`Replay.from_file() <osrparse.replay.Replay.from_file>` | ||
.. |from_string| replace:: :func:`Replay.from_string() <osrparse.replay.Replay.from_string>` | ||
.. |write_path| replace:: :func:`Replay.write_path() <osrparse.replay.Replay.write_path>` | ||
.. |write_file| replace:: :func:`Replay.write_file() <osrparse.replay.Replay.write_file>` | ||
.. |pack| replace:: :func:`Replay.pack() <osrparse.replay.Replay.pack>` | ||
.. |parse_replay_data| replace:: :func:`parse_replay_data() <osrparse.replay.parse_replay_data>` | ||
.. |br| raw:: html | ||
<br /> | ||
""" | ||
|
||
# linebreak workaround documented here | ||
# https://stackoverflow.com/a/9664844/12164878 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
osrparse | ||
========== | ||
|
||
osrparse is a parser for the ``.osr`` format, as described `on the osu! wiki <https://osu.ppy.sh/wiki/en/Client/File_formats/Osr_%28file_format%29>`__. | ||
|
||
osrparse is maintained by: | ||
|
||
* `tybug <https://github.com/tybug>`__ | ||
* `kszlim <https://github.com/kszlim>`__ | ||
|
||
Installation | ||
------------ | ||
|
||
osrparse can be installed from pip: | ||
|
||
.. code-block:: console | ||
$ pip install osrparse | ||
Links | ||
----- | ||
|
||
| Github: https://github.com/kszlim/osu-replay-parser | ||
| Documentation: https://kevin-lim.ca/osu-replay-parser/ | ||
|
||
.. | ||
couple notes about these toctrees - the first toctree is so our sidebar has | ||
a link back to the index page. the ``self`` keyword comes with its share of | ||
issues (https://github.com/sphinx-doc/sphinx/issues/2103), but none that matter | ||
that much to us. It's better than using ``index`` which works but generates | ||
many warnings when building. | ||
Hidden toctrees appear on the sidebar but not as text on the table of contents | ||
displayed on this page. | ||
|
||
Contents | ||
-------- | ||
|
||
.. toctree:: | ||
:hidden: | ||
|
||
self | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
parsing-replays | ||
writing-replays | ||
appendix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Parsing Replays | ||
=============== | ||
|
||
Creating a Replay | ||
----------------- | ||
|
||
Depending on the type of data you have, a |Replay| can be created multiple ways, using either one of |from_path|, |from_file|, or |from_string|: | ||
|
||
.. code-block:: python | ||
from osrparse import Replay | ||
# from a path | ||
replay = Replay.from_path("path/to/osr.osr") | ||
# or from an opened file object | ||
with open("path/to/osr.osr") as f: | ||
replay = Replay.from_file(f) | ||
# or from a string | ||
with open("path/to/osr.osr") as f: | ||
replay_string = f.read() | ||
replay = Replay.from_string(replay_string) | ||
Most likely, you will be using |from_path| to create a |Replay|. | ||
|
||
Parsing Just Replay Data | ||
------------------------ | ||
|
||
Unfortunately, the `/get_replay <https://github.com/ppy/osu-api/wiki#apiget_replay>`__ endpoint of `osu!api v1 <https://github.com/ppy/osu-api/wiki>`__ does not return the full contents of a replay, but only the replay data potion. This means that you cannot create a full replay from the response of this endpoint. | ||
|
||
For this, we provide |parse_replay_data|, a function that takes the response of this endpoint and returns List[:class:`~osrparse.utils.ReplayEvent`] (ie, the parsed replay data): | ||
|
||
.. code-block:: python | ||
from osrparse import parse_replay_data | ||
import base64 | ||
import lzma | ||
lzma_string = retrieve_from_api() | ||
replay_data = parse_replay_data(lzma_string) | ||
assert isinstance(replay_data[0], ReplayEvent) | ||
# or parse an already decoded lzma string | ||
lzma_string = retrieve_from_api() | ||
lzma_string = base64.b64decode(lzma_string) | ||
replay_data = parse_replay_data(lzma_string, decoded=True) | ||
# or parse an already decoded and decompressed lzma string | ||
lzma_string = retrieve_from_api() | ||
lzma_string = base64.b64decode(lzma_string) | ||
lzma_string = lzma.decompress(lzma_string).decode("ascii") | ||
replay_data = parse_replay_data(lzma_string, decompressed=True) |
Oops, something went wrong.