feat(hsr): more implementation on resource
This commit is contained in:
parent
1caadad664
commit
891cf71aa7
4
vollerei/common/api/__init__.py
Normal file
4
vollerei/common/api/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
from vollerei.common.api.resource import Resource
|
||||
|
||||
|
||||
__all__ = ["Resource"]
|
@ -100,11 +100,41 @@ class Latest:
|
||||
self.segments = segments
|
||||
self.package_size = package_size
|
||||
|
||||
@staticmethod
|
||||
def from_dict(data: dict) -> "Latest":
|
||||
if data["name"] == "":
|
||||
if data["path"] == "":
|
||||
data["name"] = data["segments"][0]["path"].split("/")[-1]
|
||||
else:
|
||||
data["name"] = data["path"].split("/")[-1]
|
||||
return Latest(
|
||||
data["name"],
|
||||
data["version"],
|
||||
data["path"],
|
||||
data["size"],
|
||||
data["md5"],
|
||||
data["entry"],
|
||||
[VoicePack.from_dict(i) for i in data["voice_packs"]],
|
||||
data["decompressed_path"],
|
||||
[Segment.from_dict(i) for i in data["segments"]],
|
||||
data["package_size"],
|
||||
)
|
||||
|
||||
|
||||
class Game:
|
||||
latest: Latest
|
||||
diffs: list[Diff]
|
||||
|
||||
def __init__(self, latest: Latest, diffs: list[Diff]) -> None:
|
||||
self.latest = latest
|
||||
self.diffs = diffs
|
||||
|
||||
@staticmethod
|
||||
def from_dict(data: dict) -> "Game":
|
||||
return Game(
|
||||
Latest.from_dict(data["latest"]), [Diff.from_dict(i) for i in data["diffs"]]
|
||||
)
|
||||
|
||||
|
||||
class Plugin:
|
||||
name: str
|
||||
@ -137,7 +167,7 @@ class DeprecatedFile:
|
||||
md5: str | None
|
||||
|
||||
|
||||
class Data:
|
||||
class Resource:
|
||||
"""
|
||||
Data class for /resource endpoint
|
||||
"""
|
||||
@ -168,6 +198,14 @@ class Data:
|
||||
sdk: None,
|
||||
deprecated_files: list[DeprecatedFile],
|
||||
) -> None:
|
||||
# Fixups
|
||||
game_latest_path = game.latest.path
|
||||
if game.latest.name == "":
|
||||
print("A")
|
||||
if game_latest_path == "":
|
||||
game.latest.name = game.latest.segments[0].path.split("/")[-1]
|
||||
else:
|
||||
game.latest.name = game_latest_path.split("/")[-1]
|
||||
self.game = game
|
||||
self.plugin = plugin
|
||||
self.web_url = web_url
|
||||
@ -176,3 +214,18 @@ class Data:
|
||||
self.deprecated_packages = deprecated_packages
|
||||
self.sdk = sdk
|
||||
self.deprecated_files = deprecated_files
|
||||
|
||||
@staticmethod
|
||||
def from_dict(json: dict) -> "Resource":
|
||||
return Resource(
|
||||
Game.from_dict(json["game"]),
|
||||
LauncherPlugin.from_dict(json["plugin"]),
|
||||
json["web_url"],
|
||||
json["force_update"],
|
||||
Game.from_dict(json["pre_download_game"])
|
||||
if json["pre_download_game"]
|
||||
else None,
|
||||
[DeprecatedPackage.from_dict(x) for x in json["deprecated_packages"]],
|
||||
json["sdk"],
|
||||
[DeprecatedFile.from_dict(x) for x in json["deprecated_files"]],
|
||||
)
|
||||
|
@ -0,0 +1,29 @@
|
||||
import requests
|
||||
|
||||
from vollerei.common.api import Resource
|
||||
from vollerei.hsr.constants import LAUNCHER_API
|
||||
from vollerei.hsr.launcher.enums import GameChannel
|
||||
|
||||
|
||||
def get_resource(channel: GameChannel = GameChannel.Overseas) -> Resource:
|
||||
"""
|
||||
Get game resource information from the launcher API.
|
||||
|
||||
Args:
|
||||
channel: Game channel to get the resource information from. (os, cn)
|
||||
|
||||
Returns:
|
||||
Resource: Game resource information.
|
||||
"""
|
||||
resource_path: dict
|
||||
match channel:
|
||||
case GameChannel.Overseas:
|
||||
resource_path = LAUNCHER_API.OS
|
||||
case GameChannel.China:
|
||||
resource_path = LAUNCHER_API.CN
|
||||
return Resource.from_dict(
|
||||
requests.get(
|
||||
resource_path["url"] + LAUNCHER_API.RESOURCE_PATH,
|
||||
params=resource_path["params"],
|
||||
).json()["data"]
|
||||
)
|
6
vollerei/hsr/launcher/enums.py
Normal file
6
vollerei/hsr/launcher/enums.py
Normal file
@ -0,0 +1,6 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class GameChannel(Enum):
|
||||
Overseas = 0
|
||||
China = 1
|
@ -1,17 +1,12 @@
|
||||
from hashlib import md5
|
||||
from os import PathLike
|
||||
from pathlib import Path
|
||||
from enum import Enum
|
||||
from vollerei.hsr.launcher.enums import GameChannel
|
||||
from vollerei.common import ConfigFile
|
||||
from vollerei.abc.launcher.game import GameABC
|
||||
from vollerei.hsr.constants import MD5SUMS
|
||||
|
||||
|
||||
class GameChannel(Enum):
|
||||
Overseas = 0
|
||||
China = 1
|
||||
|
||||
|
||||
class Game(GameABC):
|
||||
"""
|
||||
Manages the game installation
|
||||
|
Loading…
Reference in New Issue
Block a user