diff --git a/bemani/api/objects/catalog.py b/bemani/api/objects/catalog.py index b6e066d..e430b6d 100644 --- a/bemani/api/objects/catalog.py +++ b/bemani/api/objects/catalog.py @@ -35,9 +35,38 @@ class CatalogObject(BaseObject): } def __format_jubeat_song(self, song: Song) -> Dict[str, Any]: + # Map a default if the user hasn't imported the version DB. This is a nasty + # hack but we don't want to break existing installations. + defaultcategory = { + 1: VersionConstants.JUBEAT, + 2: VersionConstants.JUBEAT_RIPPLES, + 3: VersionConstants.JUBEAT_KNIT, + 4: VersionConstants.JUBEAT_COPIOUS, + 5: VersionConstants.JUBEAT_SAUCER, + 6: VersionConstants.JUBEAT_PROP, + 7: VersionConstants.JUBEAT_QUBELL, + 8: VersionConstants.JUBEAT_CLAN, + 9: VersionConstants.JUBEAT_FESTO + }.get(int(song.id / 10000000), VersionConstants.JUBEAT) + # Map the category to the version numbers defined on BEMAPI. + categorymapping = { + VersionConstants.JUBEAT: '1', + VersionConstants.JUBEAT_RIPPLES: '2', + VersionConstants.JUBEAT_RIPPLES_APPEND: '2a', + VersionConstants.JUBEAT_KNIT: '3', + VersionConstants.JUBEAT_KNIT_APPEND: '3a', + VersionConstants.JUBEAT_COPIOUS: '4', + VersionConstants.JUBEAT_COPIOUS_APPEND: '4a', + VersionConstants.JUBEAT_SAUCER: '5', + VersionConstants.JUBEAT_SAUCER_FULFILL: '5a', + VersionConstants.JUBEAT_PROP: '6', + VersionConstants.JUBEAT_QUBELL: '7', + VersionConstants.JUBEAT_CLAN: '8', + VersionConstants.JUBEAT_FESTO: '9', + } return { 'difficulty': song.data.get_int('difficulty'), - 'category': song.data.get_int('version'), + 'category': categorymapping.get(song.data.get_int('version', defaultcategory), '1'), 'bpm_min': song.data.get_int('bpm_min'), 'bpm_max': song.data.get_int('bpm_max'), } diff --git a/bemani/data/api/music.py b/bemani/data/api/music.py index c22a300..a55dc57 100644 --- a/bemani/data/api/music.py +++ b/bemani/data/api/music.py @@ -913,6 +913,33 @@ class GlobalMusicData(BaseGlobalData): genre: Optional[str], data: Dict[str, Any], ) -> Song: + defaultcategory = { + 1: VersionConstants.JUBEAT, + 2: VersionConstants.JUBEAT_RIPPLES, + 3: VersionConstants.JUBEAT_KNIT, + 4: VersionConstants.JUBEAT_COPIOUS, + 5: VersionConstants.JUBEAT_SAUCER, + 6: VersionConstants.JUBEAT_PROP, + 7: VersionConstants.JUBEAT_QUBELL, + 8: VersionConstants.JUBEAT_CLAN, + 9: VersionConstants.JUBEAT_FESTO + }.get(int(songid / 10000000), VersionConstants.JUBEAT) + # Map the category to the version numbers defined on BEMAPI. + categorymapping = { + '1': VersionConstants.JUBEAT, + '2': VersionConstants.JUBEAT_RIPPLES, + '2a': VersionConstants.JUBEAT_RIPPLES_APPEND, + '3': VersionConstants.JUBEAT_KNIT, + '3a': VersionConstants.JUBEAT_KNIT_APPEND, + '4': VersionConstants.JUBEAT_COPIOUS, + '4a': VersionConstants.JUBEAT_COPIOUS_APPEND, + '5': VersionConstants.JUBEAT_SAUCER, + '5a': VersionConstants.JUBEAT_SAUCER_FULFILL, + '6': VersionConstants.JUBEAT_PROP, + '7': VersionConstants.JUBEAT_QUBELL, + '8': VersionConstants.JUBEAT_CLAN, + '9': VersionConstants.JUBEAT_FESTO, + } return Song( game=GameConstants.JUBEAT, version=version, @@ -925,7 +952,7 @@ class GlobalMusicData(BaseGlobalData): 'bpm_min': int(data['bpm_min']), 'bpm_max': int(data['bpm_max']), 'difficulty': int(data['difficulty']), - 'version': int(data.get('category', int(songid / 10000000))), + 'version': categorymapping.get(data.get('category', '0'), defaultcategory), }, ) diff --git a/bemani/frontend/jubeat/endpoints.py b/bemani/frontend/jubeat/endpoints.py index 5dbf261..3350ea9 100644 --- a/bemani/frontend/jubeat/endpoints.py +++ b/bemani/frontend/jubeat/endpoints.py @@ -194,7 +194,7 @@ def viewtopscores(musicid: int) -> Response: artist = details.artist genre = details.genre if category < version: - category = version; + category = version if difficulties[chart] == 0.0: difficulties[chart] = details.data.get_float('difficulty', 13) if difficulties[chart] >= 13.0: diff --git a/bemani/frontend/jubeat/jubeat.py b/bemani/frontend/jubeat/jubeat.py index a1d8907..6cb24d5 100644 --- a/bemani/frontend/jubeat/jubeat.py +++ b/bemani/frontend/jubeat/jubeat.py @@ -91,21 +91,28 @@ class JubeatFrontend(FrontendBase): formatted_song['bpm_min'] = song.data.get_int('bpm_min', 120) formatted_song['bpm_max'] = song.data.get_int('bpm_max', 120) formatted_song['difficulties'] = difficulties - formatted_song['version'] = { - VersionConstants.JUBEAT: 1, - VersionConstants.JUBEAT_RIPPLES: 2, - VersionConstants.JUBEAT_RIPPLES_APPEND: 2, - VersionConstants.JUBEAT_KNIT: 3, - VersionConstants.JUBEAT_KNIT_APPEND: 3, - VersionConstants.JUBEAT_COPIOUS: 4, - VersionConstants.JUBEAT_COPIOUS_APPEND: 4, - VersionConstants.JUBEAT_SAUCER: 5, - VersionConstants.JUBEAT_SAUCER_FULFILL: 5, - VersionConstants.JUBEAT_PROP: 6, - VersionConstants.JUBEAT_QUBELL: 7, - VersionConstants.JUBEAT_CLAN: 8, - VersionConstants.JUBEAT_FESTO: 9, - }.get(song.data.get_int('version', 1), 1) + version = song.data.get_int('version', 0) + if version == 0: + # The default here is a nasty hack for installations that existed prior to importing + # version using read.py. This ensures that not importing again won't break existing + # installations. + formatted_song['version'] = int(song.id / 10000000) + else: + formatted_song['version'] = { + VersionConstants.JUBEAT: 1, + VersionConstants.JUBEAT_RIPPLES: 2, + VersionConstants.JUBEAT_RIPPLES_APPEND: 2, + VersionConstants.JUBEAT_KNIT: 3, + VersionConstants.JUBEAT_KNIT_APPEND: 3, + VersionConstants.JUBEAT_COPIOUS: 4, + VersionConstants.JUBEAT_COPIOUS_APPEND: 4, + VersionConstants.JUBEAT_SAUCER: 5, + VersionConstants.JUBEAT_SAUCER_FULFILL: 5, + VersionConstants.JUBEAT_PROP: 6, + VersionConstants.JUBEAT_QUBELL: 7, + VersionConstants.JUBEAT_CLAN: 8, + VersionConstants.JUBEAT_FESTO: 9, + }[version] return formatted_song def merge_song(self, existing: Dict[str, Any], new: Song) -> Dict[str, Any]: