Skip to content

Commit

Permalink
add songinfo args
Browse files Browse the repository at this point in the history
  • Loading branch information
MoYoez committed Aug 26, 2023
1 parent e16c2de commit a5ee5af
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 55 deletions.
6 changes: 3 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Just Like Phigros Unlimited API, due to it's unstable,so I write this.

**Get Users Best, support Overflow songs, you can delete this limit.**

> args: Session | overflow (max:20)
> args: Session | overflow (max:20) | songinfo Optional(bool) (Default:False)
```
{
Expand Down Expand Up @@ -63,7 +63,7 @@ Just Like Phigros Unlimited API, due to it's unstable,so I write this.

**Check User's best Songs.**

> args: songid | Session | diff: Optional(Default "IN")
> args: songid | Session | diff: Optional(Default "IN") | songinfo Optional(bool) (Default:False)
- tips: songid just like "DESTRUCTION321.Normal1zervsBrokenNerdz" || diff just like "EZ" "AT"

Expand Down Expand Up @@ -108,7 +108,7 @@ Just Like Phigros Unlimited API, due to it's unstable,so I write this.

- [x] /api/phi/rand

> no args
> songinfo Optional(bool) (Default:False)
```
{
Expand Down
89 changes: 39 additions & 50 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
info,
info_by,
levels,
info_illustrator,
info_hd_designer,
info_at_designer,
info_ez_desinger,
info_in_desingner,
song_info_handler_main,
)
import random as rand

Expand All @@ -34,19 +30,39 @@ def index():
def get_bests():
session = request.args.get("session")
overflow = request.args.get("overflow")
songinfo = request.args.get("songinfo")
if session is None:
return jsonify({"message": "session is required."})
if overflow is None:
overflow = 0
else:
overflow = int(overflow)
if songinfo is None or songinfo == "false":
songinfo = False
else:
songinfo = True
try:
bests, isphi = BestsRender.get_bests(session, overflow)
is_phi = {"phi": isphi}
best_list_args = {"bests": bests}
best_list = {**is_phi, **best_list_args}
get_formatData = BestsRender.get_formatData(session)
content = {**best_list, **get_formatData}
if songinfo:
# generated a songslist id.
i = 0
songinfoList = []
for _ in bests:
listChatNum = bests[i]
getSortSongID = listChatNum["songId"]
songinfoList.append(song_info_handler_main(songid=getSortSongID))
i = i + 1
full_reply = {"songinfo": songinfoList}
content = {
**best_list,
**full_reply,
**get_formatData,
}
data = {"status": True, "content": content}
data = json.dumps(data, ensure_ascii=False).encode("utf-8")
data = make_response(data)
Expand All @@ -61,12 +77,17 @@ def get_songs():
session = request.args.get("session")
songs = request.args.get("songid")
diff = request.args.get("diff")
songinfo = request.args.get("songinfo")
if session is None:
return jsonify({"message": "session is required."})
if songs is None:
return jsonify({"message": "songid is required."})
if diff is None:
diff = "IN"
if songinfo is None or songinfo == "false":
songinfo = False
else:
songinfo = True
try:
Contents, msg = BestsRender.get_songs_stats(session, songs, diff)
if Contents is None:
Expand All @@ -75,10 +96,10 @@ def get_songs():
get_formatData = BestsRender.get_formatData(session)
Contents = {"record": Contents}
Content = {**Contents, **get_formatData}
data = {
"status": True,
"content": Content,
}
if songinfo:
dict_songinfo = {"song_info": song_info_handler_main(songid=songs)}
Content = {**Content, **dict_songinfo}
data = {"status": True, "content": Content}
data = json.dumps(data, ensure_ascii=False).encode("utf-8")
data = make_response(data)
data.headers["Content-Type"] = "application/json; charset=utf-8"
Expand All @@ -89,6 +110,11 @@ def get_songs():

@app.route("/api/phi/rand", methods=["GET"])
def get_rand():
songinfo = request.args.get("songinfo")
if songinfo is None or songinfo == "false":
songinfo = False
else:
songinfo = True
try:
getRandSongIDNum = rand.randrange(0, getLength)
result = listDiff[getRandSongIDNum - 1]
Expand All @@ -105,6 +131,9 @@ def get_rand():
"level": getLevel,
"rating": getRating,
}
if songinfo:
dict_songinfo = {"song_info": song_info_handler_main(songid=result[0])}
Content = {**Content, **dict_songinfo}
data = {
"status": True,
"content": Content,
Expand Down Expand Up @@ -139,47 +168,7 @@ def get_song_info():
if songid is None:
return jsonify({"message": "songid is required."})
try:
result_info_name = info[songid]
result_info_by = info_by[songid]
result_get_diff_list: list = difficulty[songid] # list
result_get_ins_by = info_illustrator[songid]
result_get_ez_designer = info_ez_desinger[songid]
result_get_hd_desinger = info_hd_designer[songid]
result_get_in_desinger = info_in_desingner[songid]
result_get_at_desinger = info_at_designer[songid]
showEZDetailed = {
"EZ": {"rating": result_get_diff_list[0], "charter": result_get_ez_designer}
}
showHDDetailed = {
"HD": {"rating": result_get_diff_list[1], "charter": result_get_hd_desinger}
}
showInDetailed = {
"IN": {"rating": result_get_diff_list[2], "charter": result_get_in_desinger}
}
if len(result_get_diff_list) >= 4:
showAtDetailed = {
"AT": {
"rating": result_get_diff_list[3],
"charter": result_get_at_desinger,
}
}
else:
showAtDetailed = {}
getChartDetailedInfo = {
**showEZDetailed,
**showHDDetailed,
**showInDetailed,
**showAtDetailed,
"level_list": result_get_diff_list,
}
infos = {
"songname": result_info_name,
"composer": result_info_by,
"illustrator": result_get_ins_by,
"chartDetail": getChartDetailedInfo,
}
content = {"songid": songid, "info": infos}
data = {"status": True, "content": content}
data = {"status": True, "content": song_info_handler_main(songid=songid)}
except Exception as e:
return jsonify({"status": False, "message": str(e)})
data = json.dumps(data, ensure_ascii=False).encode("utf-8")
Expand Down
51 changes: 49 additions & 2 deletions method.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def parse_render_bests(gameRecord, overflow: int):
if overflow > 21:
overflow = 21
reader = ByteReader(gameRecord)
for i in range(reader.readVarShort()):
for _ in range(reader.readVarShort()):
songId = reader.readString()[:-2]
record = reader.readRecord(songId)
records.extend(record)
Expand All @@ -137,7 +137,7 @@ def get_songs_stat_main(gameRecord, songid, diff):
getdiff = diff # Diff should be EZ,HD,IN,AT
if getdiff != "EZ" and getdiff != "HD" and getdiff != "IN" and getdiff != "AT":
getdiff = "IN"
for i in range(reader.readVarShort()):
for _ in range(reader.readVarShort()):
songId = reader.readString()[:-2]
record = reader.readRecord(songId)
if songId == songid:
Expand Down Expand Up @@ -264,3 +264,50 @@ def get_songs_stats(session, songid, diff):
gameRecord = DataPackage.GameReader(result)
gameRecord = decrypt_gameRecord(gameRecord)
return get_songs_stat_main(gameRecord, songid, diff)


def song_info_handler_main(songid: str):
try:
result_info_name = info[songid]
result_info_by = info_by[songid]
result_get_diff_list: list = difficulty[songid] # list
result_get_ins_by = info_illustrator[songid]
result_get_ez_designer = info_ez_desinger[songid]
result_get_hd_desinger = info_hd_designer[songid]
result_get_in_desinger = info_in_desingner[songid]
result_get_at_desinger = info_at_designer[songid]
showEZDetailed = {
"EZ": {"rating": result_get_diff_list[0], "charter": result_get_ez_designer}
}
showHDDetailed = {
"HD": {"rating": result_get_diff_list[1], "charter": result_get_hd_desinger}
}
showInDetailed = {
"IN": {"rating": result_get_diff_list[2], "charter": result_get_in_desinger}
}
if len(result_get_diff_list) >= 4:
showAtDetailed = {
"AT": {
"rating": result_get_diff_list[3],
"charter": result_get_at_desinger,
}
}
else:
showAtDetailed = {}
getChartDetailedInfo = {
**showEZDetailed,
**showHDDetailed,
**showInDetailed,
**showAtDetailed,
"level_list": result_get_diff_list,
}
infos = {
"songname": result_info_name,
"composer": result_info_by,
"illustrator": result_get_ins_by,
"chartDetail": getChartDetailedInfo,
}
content = {"songid": songid, "info": infos}
return content
except Exception as e:
return {}

0 comments on commit a5ee5af

Please sign in to comment.