Skip to content

Commit

Permalink
file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko authored Feb 16, 2020
1 parent 62ae261 commit 92fe4c6
Show file tree
Hide file tree
Showing 7 changed files with 733 additions and 0 deletions.
4 changes: 4 additions & 0 deletions commonTypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import NewType, Dict

LevelString = NewType('LevelString', bytes)
RobDict = NewType('RobDict', Dict[str, str])
101 changes: 101 additions & 0 deletions levelConverter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/python3

#######################################
# 2.1 level format to 1.9 level auto converter
# for the truest dashers
# uploads to servers automatically and unlisted
# by zmx
######################################


import objCharts
import re
import levelUtil, levelDownloader, saveUtil, sys, requests, base64, objCharts
import os # for error codes
from typing import Dict
from commonTypes import LevelString, RobDict

def uploadLevel(levelString: LevelString, levelInfo: RobDict) -> int:
'''
Uploads a level to 1.9 servers
'''

url = "https://absolllute.com/gdps/gdapi/uploadGJLevel19.php"

# 1.9 descriptions aren't base64 encoded, we need to remove illegal characters before upload breaks them anyways
desc: str = base64.urlsafe_b64decode(levelInfo["3"]).decode()
desc = re.sub(r"[^A-Za-z0-9\., \$\-\_\.\+\!\*\'\(\)]", "", desc) # remove anything not url safe

# some params don't exist
postdata = {"gjp": '', "gameVersion": 19, "userName": "21Reupload",
"unlisted": "1", "levelDesc": desc,
"levelName": levelInfo["2"], "levelVersion": levelInfo["5"],
"levelLength": levelInfo["15"], "audioTrack": levelInfo["12"],
"password": 1, "original": levelInfo["1"], "songID": levelInfo.get("35", 0),
"objects": levelInfo.get("45", 0), "udid": "hi absolute :)"}
postdata["levelString"] = levelString
uploadRequest = requests.post(url, postdata)

try:
levelID: int = int(uploadRequest.text)
if levelID == -1: # -1 is an error dumb
throw

return levelID
except:
print(f"Error occured while reuploading:\n{uploadRequest.text}")
raise Exception()

if __name__ == "__main__":
print("~ 1.9 Level Reuploader by zmx ~\n")

mainID: int = 128
try:
mainID = int(sys.argv[1])
except:
print(f"Usage: {sys.argv[0]} <id>\nset env variable DRY to true if you want to skip upload\nset env variable CLUB to true to convert clubstep blocks 1-8")
sys.exit(os.EX_USAGE)

levelString: LevelString = LevelString(b"")
levelInfo: RobDict = RobDict({})

try:
levelString, levelInfo = levelDownloader.downloadLevel(mainID)
except:
print("invalid level!")
sys.exit(os.EX_DATAERR)

print(f"Downloaded level `{levelInfo['2']}`")
if os.getenv("CLUB", False):
print("Clubstep block conversion enabled!\nThis can make some levels impossible!")
levelUtil.convClubstep = True

print("Converting...\n")

# rob likes his levels encoded
convLevel: LevelString = levelUtil.convLevelString(levelString)
encodedLevel: bytes = saveUtil.encodeLevel(convLevel)

illegalObjs: Dict[int, str] = levelUtil.illegalObjInfo(levelUtil.illegalObj)

for objID, name in illegalObjs.items():
print(f"Illegal object: {objID} ({name})")

if set(levelUtil.illegalObj).intersection(objCharts.clubstepObjConv):
print("Note: Enabling the CLUB environment variable will convert most of the clubstep blocks, but can make the level impossible!")

if not illegalObjs:
print("All objects converted!")

print("")

if os.getenv("DRY", False):
print("Dry mode enabled, no upload!")
sys.exit()

print("Uploading level...")
try:
levelID: int = uploadLevel(convLevel, levelInfo)
print(f"Level reuploaded to id: {levelID}")
except:
print("couldn't reupload level!")
49 changes: 49 additions & 0 deletions levelDownloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from commonTypes import LevelString
import levelUtil, requests, saveUtil, sys
from commonTypes import LevelString, RobDict
from typing import Tuple, Dict

gameV = 22
url = 'http://www.boomlings.com/database/downloadGJLevel21.php'
secret = 'Wmfd2893gb7'

def downloadLevel(id: int) -> Tuple[LevelString, RobDict]:
postdata = {'levelID': id, 'gameVersion': gameV, 'secret': secret}
downloaded = requests.post(url, postdata)
levelInfo = levelUtil.parseKeyVarArray(downloaded.text, ':')
levelString = LevelString(saveUtil.decodeLevel(levelInfo['4']))

return levelString, levelInfo

if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="Downloads GD Levels", epilog="Daily ID: -1, Weekly ID: -2")

parser.add_argument('id', help='Level ID (int, required)', type=int)

parser.add_argument('--gameversion', '-gv',
help='Game Version (defaults to 22, int)', type=int, default=22)

parser.add_argument('--url', help='Site URL (defaults to www.boomlings.com)', default='http://www.boomlings.com/database/downloadGJLevel21.php')

parser.add_argument(
'--secret', '-s', help='Secret (Don\'t set this unless you know what you\'re doing!, autoset)', default='Wmfd2893gb7')

args = parser.parse_args()

# setup values
gameV = args.gameversion
url = args.url
secret = args.secret

levelString, levelInfo = downloadLevel(args.id)

if sys.stdout.isatty():
print(f'Name: {levelInfo["2"]}\nVersion: {levelInfo["13"]}')
with open(levelInfo['2'] + '.txt', 'wb') as levelFile:
levelFile.write(levelString)
else:
print(levelString.decode('utf-8'))
Loading

0 comments on commit 92fe4c6

Please sign in to comment.