Skip to content

Instantly share code, notes, and snippets.

@megamaz
Created June 9, 2024 05:42
Show Gist options
  • Save megamaz/f31bb7b26da756b314a1a170e3831692 to your computer and use it in GitHub Desktop.
Save megamaz/f31bb7b26da756b314a1a170e3831692 to your computer and use it in GitHub Desktop.
Generates a vanilla Song Play History json file (for those who lost said data from the AppData folder) from your BeatLeader plays.
import json
import requests
###### FOR FUTURE USERS
# This code grabs your BeatLader score and generates play information for your AppData folder.
# The goal is that if you accidentally wiped your PC clean or something and lost your appdata folder,
# you can run this code to get your PBs back. This is the vanilla portion only- the stuff that
# displays your max combo, highscore, max rank, and play count at the bottom of the leaderboard.
# I doubt anyone needs it but if someone does hit me up on discord "megamaz" and I'll write
# some code that generates a SongPlayHistory json file that you can shove into your UserData.
###### USAGE INSTRUCTIONS
# Shove your BeatLeader UID here.
# That's it. Then just run the code.
# Also you're gonna need requests installed, install that by running this command in your preferred command prompt:
# py -m pip install --upgrade requests
# after you've run the code by simply doing `py ./gen_play_history.py`
# you'll get a new file called `out.json` in your directory.
# in File Explorer, enter this into your adress bar: %appdata%\..\LocalLow\Hyperbolic Magnetism\Beat Saber
# then find "PlayerData.dat" (make sure that it is not the PlayerData.dat.bak file)
# and copy paste the entirety of the contents of out.json into the field called "levelsStatsData"
# (it may take a bit of scrolling. alternatively, ctrl+f)
# after this, copy paste the entire PlayerData.dat file into the PlayerData.dat.bak file.
# and you're done!
UID = 76561198400835990
# all this stuff below is no touchy :)
session = requests.Session()
DIFF_NAMES = "Easy,Normal,Hard,Expert,ExpertPlus".split(",")
page = 0
scores = []
while True:
page += 1
url = f"https://api.beatleader.xyz/player/{UID}/scores?sortBy=date&page={page}&count=100"
fetched_scores = session.get(url).json()
if len(fetched_scores['data']) == 0:
break
for score in fetched_scores['data']:
new_playhistory_obj = {
"levelId": "",
"difficulty": 0,
"beatmapCharacteristicName": "Standard",
"highScore": 0,
"maxCombo": 0,
"fullCombo": False,
"maxRank": 0,
"validScore": False,
"playCount": 1
}
new_playhistory_obj["levelId"] = f"custom_level_{score['leaderboard']['song']['hash'].upper()}"
new_playhistory_obj["difficulty"] = DIFF_NAMES.index(score['leaderboard']['difficulty']['difficultyName'])
new_playhistory_obj["beatmapCharacteristicName"] = score['leaderboard']['difficulty']['modeName']
new_playhistory_obj["highScore"] = score['baseScore']
new_playhistory_obj["maxCombo"] = score['maxCombo']
new_playhistory_obj["fullCombo"] = score['fullCombo']
if score['accuracy'] < 19.99:
new_playhistory_obj["maxRank"] = 6
elif score['accuracy'] < 34.99:
new_playhistory_obj["maxRank"] = 5
elif score['accuracy'] < 49.99:
new_playhistory_obj["maxRank"] = 4
elif score['accuracy'] < 64.99:
new_playhistory_obj["maxRank"] = 3
elif score['accuracy'] < 79.99:
new_playhistory_obj["maxRank"] = 2
elif score['accuracy'] < 89.99:
new_playhistory_obj["maxRank"] = 1
else:
new_playhistory_obj["maxRank"] = 0
new_playhistory_obj["validScore"] = True
new_playhistory_obj["playCount"] = score['playCount']
scores.append(new_playhistory_obj)
# print(f"{score['leaderboard']['song']['name']} (hash={score['leaderboard']['song']['hash']})")
print(f"completed {len(scores)} scores... page {page}")
json.dump(scores, open("./out.json", "w", encoding="utf-8"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment