feat: implement VoicePackLanguage
Enum better than string 8)
This commit is contained in:
parent
a9f3ee2e3e
commit
80f1ea87d7
@ -3,6 +3,9 @@ Class wrapper for API endpoint /resource
|
||||
"""
|
||||
|
||||
|
||||
from vollerei.common.enums import VoicePackLanguage
|
||||
|
||||
|
||||
class Segment:
|
||||
"""
|
||||
A segment of the game archive.
|
||||
@ -41,7 +44,7 @@ class VoicePack:
|
||||
`name` maybe converted from `path` if the server returns empty string.
|
||||
|
||||
Attributes:
|
||||
language (str): Language of the voice pack.
|
||||
language (VoicePackLanguage): Language of the voice pack.
|
||||
name (str): Voice pack archive name.
|
||||
path (str): Voice pack download path.
|
||||
size (int): Voice pack size.
|
||||
@ -49,7 +52,7 @@ class VoicePack:
|
||||
package_size (int): Voice pack package size.
|
||||
"""
|
||||
|
||||
language: str
|
||||
language: VoicePackLanguage
|
||||
name: str
|
||||
path: str
|
||||
# str -> int
|
||||
@ -60,7 +63,7 @@ class VoicePack:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
language: str,
|
||||
language: VoicePackLanguage,
|
||||
name: str,
|
||||
path: str,
|
||||
size: int,
|
||||
@ -77,7 +80,7 @@ class VoicePack:
|
||||
@staticmethod
|
||||
def from_dict(data: dict) -> "VoicePack":
|
||||
return VoicePack(
|
||||
data["language"],
|
||||
VoicePackLanguage.from_remote_str(data["language"]),
|
||||
data["name"],
|
||||
data["path"],
|
||||
int(data["size"]),
|
||||
|
27
vollerei/common/enums.py
Normal file
27
vollerei/common/enums.py
Normal file
@ -0,0 +1,27 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class VoicePackLanguage(Enum):
|
||||
Japanese = "ja-jp"
|
||||
Chinese = "zh-cn"
|
||||
Taiwanese = "zh-tw"
|
||||
Korean = "ko-kr"
|
||||
English = "en-us"
|
||||
|
||||
@staticmethod
|
||||
def from_remote_str(s: str) -> "VoicePackLanguage":
|
||||
"""
|
||||
Converts a language string from remote server to a VoicePackLanguage enum.
|
||||
"""
|
||||
if s == "ja-jp":
|
||||
return VoicePackLanguage.Japanese
|
||||
elif s == "zh-cn":
|
||||
return VoicePackLanguage.Chinese
|
||||
elif s == "zh-tw":
|
||||
return VoicePackLanguage.Taiwanese
|
||||
elif s == "ko-kr":
|
||||
return VoicePackLanguage.Korean
|
||||
elif s == "en-us":
|
||||
return VoicePackLanguage.English
|
||||
else:
|
||||
raise ValueError(f"Invalid language string: {s}")
|
Loading…
Reference in New Issue
Block a user