1
0
mirror of synced 2024-11-27 15:40:48 +01:00

Fix missing self.version->self.music_version renames, fix formatting, lint issues.

This commit is contained in:
Jennifer Taylor 2023-07-29 19:12:37 +00:00
parent 9a7d0ccdb9
commit b93b8aed4f
9 changed files with 212 additions and 127 deletions

View File

@ -341,7 +341,9 @@ class PopnMusicBase(CoreHandler, CardManagerHandler, PASELIHandler, Base):
) -> None:
# Generate scorecard
profile = self.get_profile(userid)
song = self.data.local.music.get_song(self.game, self.music_version, songid, chart)
song = self.data.local.music.get_song(
self.game, self.music_version, songid, chart
)
card_medal = {
self.PLAY_MEDAL_CIRCLE_FAILED: "Failed",

View File

@ -328,7 +328,7 @@ class PopnMusicModernBase(PopnMusicBase, ABC):
# Top 500 Popular music
for songid, _plays in self.data.local.music.get_hit_chart(
self.game, self.version, 500
self.game, self.music_version, 500
):
popular_music = Node.void("popular_music")
root.add_child(popular_music)
@ -575,7 +575,9 @@ class PopnMusicModernBase(PopnMusicBase, ABC):
return root
rivalid = links[no].other_userid
rivalprofile = profiles[rivalid]
scores = self.data.remote.music.get_scores(self.game, self.version, rivalid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, rivalid
)
# First, output general profile info.
friend = Node.void("friend")
@ -673,7 +675,9 @@ class PopnMusicModernBase(PopnMusicBase, ABC):
return Node.void("player24")
root = Node.void("player24")
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
for score in scores:
# Skip any scores for chart types we don't support
if score.chart not in [
@ -829,7 +833,9 @@ class PopnMusicModernBase(PopnMusicBase, ABC):
root.add_child(Node.s8("result", 1))
# Scores
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
for score in scores:
# Skip any scores for chart types we don't support
if score.chart not in [
@ -1036,13 +1042,13 @@ class PopnMusicModernBase(PopnMusicBase, ABC):
last_played = [
x[0]
for x in self.data.local.music.get_last_played(
self.game, self.version, userid, 10
self.game, self.music_version, userid, 10
)
]
most_played = [
x[0]
for x in self.data.local.music.get_most_played(
self.game, self.version, userid, 20
self.game, self.music_version, userid, 20
)
]
while len(last_played) < 10:
@ -1157,7 +1163,9 @@ class PopnMusicModernBase(PopnMusicBase, ABC):
if game_config.get_bool("force_unlock_songs"):
songs = {
song.id
for song in self.data.local.music.get_all_songs(self.game, self.version)
for song in self.data.local.music.get_all_songs(
self.game, self.music_version
)
}
for song in songs:
item = Node.void("item")

View File

@ -210,7 +210,7 @@ class PopnMusicEclale(PopnMusicBase):
# Output the hit chart
for songid, _plays in self.data.local.music.get_hit_chart(
self.game, self.version, 500
self.game, self.music_version, 500
):
popular_music = Node.void("popular_music")
root.add_child(popular_music)
@ -360,7 +360,9 @@ class PopnMusicEclale(PopnMusicBase):
userid = self.data.remote.user.from_refid(self.game, self.version, refid)
if userid is not None:
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
else:
scores = []
@ -451,7 +453,9 @@ class PopnMusicEclale(PopnMusicBase):
return root
rivalid = links[no].other_userid
rivalprofile = profiles[rivalid]
scores = self.data.remote.music.get_scores(self.game, self.version, rivalid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, rivalid
)
# First, output general profile info.
friend = Node.void("friend")
@ -573,7 +577,9 @@ class PopnMusicEclale(PopnMusicBase):
root.add_child(Node.s8("result", 1))
# Scores
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
for score in scores:
# Skip any scores for chart types we don't support
if score.chart not in [
@ -684,13 +690,13 @@ class PopnMusicEclale(PopnMusicBase):
last_played = [
x[0]
for x in self.data.local.music.get_last_played(
self.game, self.version, userid, 5
self.game, self.music_version, userid, 5
)
]
most_played = [
x[0]
for x in self.data.local.music.get_most_played(
self.game, self.version, userid, 10
self.game, self.music_version, userid, 10
)
]
while len(last_played) < 5:
@ -794,7 +800,9 @@ class PopnMusicEclale(PopnMusicBase):
if game_config.get_bool("force_unlock_songs"):
songs = {
song.id
for song in self.data.local.music.get_all_songs(self.game, self.version)
for song in self.data.local.music.get_all_songs(
self.game, self.music_version
)
}
for song in songs:
item = Node.void("item")

View File

@ -204,13 +204,13 @@ class PopnMusicFantasia(PopnMusicBase):
last_played = [
x[0]
for x in self.data.local.music.get_last_played(
self.game, self.version, userid, 3
self.game, self.music_version, userid, 3
)
]
most_played = [
x[0]
for x in self.data.local.music.get_most_played(
self.game, self.version, userid, 20
self.game, self.music_version, userid, 20
)
]
while len(last_played) < 3:
@ -222,7 +222,9 @@ class PopnMusicFantasia(PopnMusicBase):
clear_medal = [0] * self.GAME_MAX_MUSIC_ID
clear_medal_sub = [0] * self.GAME_MAX_MUSIC_ID
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
for score in scores:
if score.id > self.GAME_MAX_MUSIC_ID:
continue
@ -329,7 +331,9 @@ class PopnMusicFantasia(PopnMusicBase):
clear_medal = [0] * self.GAME_MAX_MUSIC_ID
hiscore_array = [0] * int((((self.GAME_MAX_MUSIC_ID * 4) * 17) + 7) / 8)
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
for score in scores:
if score.id > self.GAME_MAX_MUSIC_ID:
continue
@ -643,7 +647,9 @@ class PopnMusicFantasia(PopnMusicBase):
for rival in links[:2]:
rivalid = rival.other_userid
rivalprofile = profiles[rivalid]
scores = self.data.remote.music.get_scores(self.game, self.version, rivalid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, rivalid
)
# First, output general profile info.
friend = Node.void("friend")

View File

@ -334,7 +334,9 @@ class PopnMusicLapistoria(PopnMusicBase):
return root
rivalid = links[no].other_userid
rivalprofile = profiles[rivalid]
scores = self.data.remote.music.get_scores(self.game, self.version, rivalid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, rivalid
)
achievements = self.data.local.user.get_achievements(
self.game, self.version, rivalid
)
@ -658,13 +660,13 @@ class PopnMusicLapistoria(PopnMusicBase):
last_played = [
x[0]
for x in self.data.local.music.get_last_played(
self.game, self.version, userid, 5
self.game, self.music_version, userid, 5
)
]
most_played = [
x[0]
for x in self.data.local.music.get_most_played(
self.game, self.version, userid, 10
self.game, self.music_version, userid, 10
)
]
while len(last_played) < 5:
@ -675,7 +677,9 @@ class PopnMusicLapistoria(PopnMusicBase):
account.add_child(Node.s16_array("my_best", most_played))
account.add_child(Node.s16_array("latest_music", last_played))
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
for score in scores:
# Skip any scores for chart types we don't support
if score.chart not in [
@ -822,7 +826,9 @@ class PopnMusicLapistoria(PopnMusicBase):
if game_config.get_bool("force_unlock_songs"):
songs = {
song.id
for song in self.data.local.music.get_all_songs(self.game, self.version)
for song in self.data.local.music.get_all_songs(
self.game, self.music_version
)
}
for song in songs:
item = Node.void("item")
@ -1082,7 +1088,9 @@ class PopnMusicLapistoria(PopnMusicBase):
root.add_child(Node.s32("option", profile.get_int("option", 0)))
root.add_child(Node.s8("result", 1))
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
for score in scores:
if score.id > self.GAME_MAX_MUSIC_ID:
continue

View File

@ -186,13 +186,13 @@ class PopnMusicSunnyPark(PopnMusicBase):
last_played = [
x[0]
for x in self.data.local.music.get_last_played(
self.game, self.version, userid, 3
self.game, self.music_version, userid, 3
)
]
most_played = [
x[0]
for x in self.data.local.music.get_most_played(
self.game, self.version, userid, 20
self.game, self.music_version, userid, 20
)
]
while len(last_played) < 3:
@ -204,7 +204,9 @@ class PopnMusicSunnyPark(PopnMusicBase):
clear_medal = [0] * self.GAME_MAX_MUSIC_ID
clear_medal_sub = [0] * self.GAME_MAX_MUSIC_ID
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
for score in scores:
if score.id > self.GAME_MAX_MUSIC_ID:
continue
@ -463,7 +465,9 @@ class PopnMusicSunnyPark(PopnMusicBase):
clear_medal = [0] * self.GAME_MAX_MUSIC_ID
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
for score in scores:
if score.id > self.GAME_MAX_MUSIC_ID:
continue
@ -815,7 +819,9 @@ class PopnMusicSunnyPark(PopnMusicBase):
for rival in links[:2]:
rivalid = rival.other_userid
rivalprofile = profiles[rivalid]
scores = self.data.remote.music.get_scores(self.game, self.version, rivalid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, rivalid
)
# First, output general profile info.
friend = Node.void("friend")

View File

@ -227,7 +227,9 @@ class PopnMusicTuneStreet(PopnMusicBase):
# Format Scores
hiscore_array = [0] * int((((self.GAME_MAX_MUSIC_ID * 7) * 17) + 7) / 8)
scores = self.data.remote.music.get_scores(self.game, self.version, userid)
scores = self.data.remote.music.get_scores(
self.game, self.music_version, userid
)
for score in scores:
if score.id > self.GAME_MAX_MUSIC_ID:
continue
@ -284,7 +286,7 @@ class PopnMusicTuneStreet(PopnMusicBase):
most_played = [
x[0]
for x in self.data.local.music.get_most_played(
self.game, self.version, userid, 20
self.game, self.music_version, userid, 20
)
]
while len(most_played) < 20:

View File

@ -398,9 +398,12 @@ class ImportPopn(ImportBase):
"24": VersionConstants.POPN_MUSIC_USANEKO,
"25": VersionConstants.POPN_MUSIC_PEACE,
"26": VersionConstants.POPN_MUSIC_KAIMEI_RIDDLES,
"omni-24": VersionConstants.POPN_MUSIC_USANEKO + DBConstants.OMNIMIX_VERSION_BUMP, #Omnimix v2 only works for 24 - 26
"omni-25": VersionConstants.POPN_MUSIC_PEACE + DBConstants.OMNIMIX_VERSION_BUMP ,
"omni-26": VersionConstants.POPN_MUSIC_KAIMEI_RIDDLES + DBConstants.OMNIMIX_VERSION_BUMP,
"omni-24": VersionConstants.POPN_MUSIC_USANEKO
+ DBConstants.OMNIMIX_VERSION_BUMP, # Omnimix v2 only works for 24 - 26
"omni-25": VersionConstants.POPN_MUSIC_PEACE
+ DBConstants.OMNIMIX_VERSION_BUMP,
"omni-26": VersionConstants.POPN_MUSIC_KAIMEI_RIDDLES
+ DBConstants.OMNIMIX_VERSION_BUMP,
}.get(version, -1)
if actual_version == VersionConstants.POPN_MUSIC_TUNE_STREET:
@ -420,84 +423,113 @@ class ImportPopn(ImportBase):
config, GameConstants.POPN_MUSIC, actual_version, no_combine, update
)
def scrape_xml(self, xmlfile: str, songs: List[Dict[str, Any]] = []) -> List[Dict[str, Any]]:
with open(xmlfile, 'rb') as xmlhandle:
xmldata = xmlhandle.read().decode('shift_jisx0213')
def scrape_xml(
self, xmlfile: Path, songs: List[Dict[str, Any]] = []
) -> List[Dict[str, Any]]:
with open(xmlfile, "rb") as xmlhandle:
xmldata = xmlhandle.read().decode("shift_jisx0213")
root = ET.fromstring(xmldata)
for music_entry in root.findall('music'):
for music_entry in root.findall("music"):
difficulties = [0, 0, 0, 0, 0, 0]
filenames = ['', '', '', '', '', '']
filenames = ["", "", "", "", "", ""]
diff_map = {
'ep': 0,
'np': 1,
'hp': 2,
'op': 3,
'bp_n': 4,
'bp_h': 5,
"ep": 0,
"np": 1,
"hp": 2,
"op": 3,
"bp_n": 4,
"bp_h": 5,
}
charts = music_entry.find('charts')
charts = music_entry.find("charts")
if charts is not None:
for chart in charts.findall('chart'):
chart_idx = diff_map.get(chart.attrib['idx'])
if chart.find('diff') is not None:
difficulties[chart_idx] = int(chart.find('diff').text)
filenames[chart_idx] = f'{chart.find("folder").text}/{chart.find("filename").text}'
for chart in charts.findall("chart"):
chart_idx = diff_map.get(chart.attrib["idx"])
if chart.find("diff") is not None:
difficulties[chart_idx] = int(chart.find("diff").text)
filenames[
chart_idx
] = f'{chart.find("folder").text}/{chart.find("filename").text}'
songinfo: Dict
# Check if song metadata is in this entry
if music_entry.find('fw_title') is not None:
if music_entry.find("fw_title") is not None:
songinfo = {
'id': int(music_entry.attrib['id']),
'title': music_entry.find('fw_title').text,
'artist': music_entry.find('fw_artist').text,
'genre': music_entry.find('fw_genre').text,
'comment': music_entry.find('genre').text,
'title_en': music_entry.find('title').text,
'artist_en': music_entry.find('artist').text,
'long_genre': '',
'folder': music_entry.find('folder').text,
'difficulty': {
'standard': {
'easy': difficulties[0],
'normal': difficulties[1],
'hyper': difficulties[2],
'ex': difficulties[3],
"id": int(music_entry.attrib["id"]),
"title": music_entry.find("fw_title").text,
"artist": music_entry.find("fw_artist").text,
"genre": music_entry.find("fw_genre").text,
"comment": music_entry.find("genre").text,
"title_en": music_entry.find("title").text,
"artist_en": music_entry.find("artist").text,
"long_genre": "",
"folder": music_entry.find("folder").text,
"difficulty": {
"standard": {
"easy": difficulties[0],
"normal": difficulties[1],
"hyper": difficulties[2],
"ex": difficulties[3],
},
'battle': {
'normal': difficulties[4],
'hyper': difficulties[5],
}
"battle": {
"normal": difficulties[4],
"hyper": difficulties[5],
},
'file': {
'standard': {
'easy': filenames[0],
'normal': filenames[1],
'hyper': filenames[2],
'ex': filenames[3],
},
'battle': {
'normal': filenames[4],
'hyper': filenames[5],
"file": {
"standard": {
"easy": filenames[0],
"normal": filenames[1],
"hyper": filenames[2],
"ex": filenames[3],
},
"battle": {
"normal": filenames[4],
"hyper": filenames[5],
},
},
}
# It's not here so find the entry at the current song id
else:
for song in songs:
if song['id'] == int(music_entry.attrib['id']):
if song["id"] == int(music_entry.attrib["id"]):
if difficulties is not None:
for diff, i in zip(['easy', 'normal', 'hyper', 'ex'], range(4)):
song['difficulty']['standard'][diff] = difficulties[i] if difficulties[i] else song['difficulty']['standard'][diff]
song['file']['standard'][diff] = filenames[i] if filenames[i] else song['file']['standard'][diff]
for diff, i in zip(
["easy", "normal", "hyper", "ex"], range(4)
):
song["difficulty"]["standard"][diff] = (
difficulties[i]
if difficulties[i]
else song["difficulty"]["standard"][diff]
)
song["file"]["standard"][diff] = (
filenames[i]
if filenames[i]
else song["file"]["standard"][diff]
)
song['difficulty']['battle']['normal'] = difficulties[4] if difficulties[4] else song['difficulty']['battle']['normal']
song['difficulty']['battle']['hyper'] = difficulties[5] if difficulties[5] else song['difficulty']['battle']['hyper']
song['file']['battle']['normal'] = filenames[4] if filenames[4] else song['file']['battle']['normal']
song['file']['battle']['hyper'] = filenames[5] if filenames[5] else song['file']['battle']['hyper']
song["difficulty"]["battle"]["normal"] = (
difficulties[4]
if difficulties[4]
else song["difficulty"]["battle"]["normal"]
)
song["difficulty"]["battle"]["hyper"] = (
difficulties[5]
if difficulties[5]
else song["difficulty"]["battle"]["hyper"]
)
song["file"]["battle"]["normal"] = (
filenames[4]
if filenames[4]
else song["file"]["battle"]["normal"]
)
song["file"]["battle"]["hyper"] = (
filenames[5]
if filenames[5]
else song["file"]["battle"]["hyper"]
)
else:
song['genre'] = music_entry.find('fw_genre').text
song['comment'] = music_entry.find('genre').text
song["genre"] = music_entry.find("fw_genre").text
song["comment"] = music_entry.find("genre").text
break
continue
@ -529,11 +561,11 @@ class ImportPopn(ImportBase):
}
for orig, rep in accent_lut.items():
songinfo['title'] = songinfo['title'].replace(orig, rep)
songinfo['artist'] = songinfo['artist'].replace(orig, rep)
songinfo['title_en'] = songinfo['title_en'].replace(orig, rep)
songinfo['artist_en'] = songinfo['artist_en'].replace(orig, rep)
songinfo['genre'] = songinfo['genre'].replace(orig, rep)
songinfo["title"] = songinfo["title"].replace(orig, rep)
songinfo["artist"] = songinfo["artist"].replace(orig, rep)
songinfo["title_en"] = songinfo["title_en"].replace(orig, rep)
songinfo["artist_en"] = songinfo["artist_en"].replace(orig, rep)
songinfo["genre"] = songinfo["genre"].replace(orig, rep)
songs.append(songinfo)
return songs
@ -993,7 +1025,9 @@ class ImportPopn(ImportBase):
mask & 0x4000000 > 0, # Battle hyper chart bit
)
elif self.version == VersionConstants.POPN_MUSIC_USANEKO or self.version == (VersionConstants.POPN_MUSIC_USANEKO + DBConstants.OMNIMIX_VERSION_BUMP):
elif self.version == VersionConstants.POPN_MUSIC_USANEKO or self.version == (
VersionConstants.POPN_MUSIC_USANEKO + DBConstants.OMNIMIX_VERSION_BUMP
):
# Based on M39:J:A:A:2018101500
# Normal offset for music DB, size
@ -1083,7 +1117,9 @@ class ImportPopn(ImportBase):
mask & 0x4000000 > 0, # Battle hyper chart bit
)
elif self.version == VersionConstants.POPN_MUSIC_PEACE or self.version == (VersionConstants.POPN_MUSIC_PEACE + DBConstants.OMNIMIX_VERSION_BUMP):
elif self.version == VersionConstants.POPN_MUSIC_PEACE or self.version == (
VersionConstants.POPN_MUSIC_PEACE + DBConstants.OMNIMIX_VERSION_BUMP
):
# Based on M39:J:A:A:2020092800
# Normal offset for music DB, size
@ -1173,7 +1209,14 @@ class ImportPopn(ImportBase):
mask & 0x4000000 > 0, # Battle hyper chart bit
)
elif self.version == VersionConstants.POPN_MUSIC_KAIMEI_RIDDLES or self.version == (VersionConstants.POPN_MUSIC_KAIMEI_RIDDLES + DBConstants.OMNIMIX_VERSION_BUMP):
elif (
self.version == VersionConstants.POPN_MUSIC_KAIMEI_RIDDLES
or self.version
== (
VersionConstants.POPN_MUSIC_KAIMEI_RIDDLES
+ DBConstants.OMNIMIX_VERSION_BUMP
)
):
# Based on M39:J:A:A:2022061300
# Normal offset for music DB, size
@ -4228,11 +4271,11 @@ if __name__ == "__main__":
help="The access token to use with the remote BEMAPI server.",
)
parser.add_argument(
'--folder',
dest='folder',
action='store',
"--folder",
dest="folder",
action="store",
type=str,
help='The path were a folder of files are stored.',
help="The path were a folder of files are stored.",
)
# Parse args, validate invariants.
@ -4263,12 +4306,14 @@ if __name__ == "__main__":
if args.xml:
songs = popn.scrape_xml(args.xml, songs)
elif args.folder:
files = Path(args.folder).glob('*xml')
for file in files:
files = Path(args.folder).glob("*xml")
for filename in files:
try:
songs = popn.scrape_xml(file, songs)
except:
raise Exception("Invalid XML (" + str(file) +")" )
songs = popn.scrape_xml(filename, songs)
except Exception:
# We should really be just catching invalid XML but I didn't write this
# nor do I have omnimix so I can't really test what it should do.
raise Exception(f"Invalid XML ({filename})")
elif args.server and args.token:
songs = popn.lookup(args.server, args.token)
else: