Skip to content

Commit

Permalink
Use osu! cookie instead of logging in
Browse files Browse the repository at this point in the history
It seems logging in via this endpoint doesn't work anymore, using a cookie as a temporary way to download replays.
In the future it may be wise to use the osu!lazer oauth endpoint to do that.
  • Loading branch information
MasterIO02 committed Jul 16, 2024
1 parent efeebd6 commit 067ce72
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ REDDIT_USERNAME=
REDDIT_USER_AGENT=
REDDIT_SUBREDDIT=
OSU_API_KEY=
OSU_USERNAME=
OSU_PASSWORD=
OSU_COOKIE=
ORDR_API_KEY=devmode_success
SERVER_ADDR=
REDIS_HOST=localhost
Expand Down
3 changes: 2 additions & 1 deletion src/queue.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os

from typing import Iterable
Expand Down Expand Up @@ -33,5 +34,5 @@ def _stream() -> Iterable[Comment]:

def main() -> None:
for comment in _stream():
print(comment)
logging.info(f"Enqueueing comment id {comment}")
enqueue(job, comment)
11 changes: 6 additions & 5 deletions src/worker/osu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from tempfile import mkstemp

from requests import Session
import requests

from . import ReplyWith

Expand All @@ -21,13 +21,13 @@ def download_replay(score: int) -> Path:

def _download(url: str) -> bytes:
"""Download something from osu!web at `url`, returning the file contents."""
with _login() as sess:
resp = sess.get(f"{url}/download", headers={"Referer": url})
download_url = f"{url}/download"
resp = requests.get(download_url, headers={"Referer": url, "Cookie": os.environ.get("OSU_COOKIE")})
if not resp.ok:
raise ReplyWith("Sorry, a download failed.")
raise ReplyWith(f"Sorry, a download failed at {download_url}.")
return resp.content


'''
def _login() -> Session:
"""Get a `Session` that's logged into osu!web."""
# Technique comes from: https://github.com/TheBicPen/osu-lazer-bot.
Expand All @@ -46,3 +46,4 @@ def _login() -> Session:
if resp.status_code == 302:
return sess
raise ReplyWith("Sorry, I couldn't log into osu!web.")
'''
1 change: 1 addition & 0 deletions src/worker/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def _score_id(beatmap: int, player: int, mods: int) -> int:
score = scores[0]
if not score.replay_available:
raise ReplyWith("Sorry, the replay is not available for download.")
logging.info(f"Found score id {score.score_id}")
return cast(int, score.score_id)


Expand Down

0 comments on commit 067ce72

Please sign in to comment.