refactor: convert Enum to StrEnum and reduce some duplicated code
This commit is contained in:
parent
72a5448976
commit
4c01aa7467
@ -1,9 +1,9 @@
|
||||
from enum import Enum, auto
|
||||
from enum import StrEnum, auto
|
||||
|
||||
__all__ = ["LrcType", "LrcMetaType", "LinkType"]
|
||||
|
||||
|
||||
class LrcType(Enum):
|
||||
class LrcType(StrEnum):
|
||||
Origin = auto()
|
||||
Translation = auto()
|
||||
Romaji = auto()
|
||||
@ -17,18 +17,27 @@ class LrcType(Enum):
|
||||
case LrcType.Romaji:
|
||||
return "音"
|
||||
|
||||
def ncmAPIString(self) -> str:
|
||||
match self:
|
||||
case LrcType.Origin:
|
||||
return "lrc"
|
||||
case LrcType.Translation:
|
||||
return "tlyric"
|
||||
case LrcType.Romaji:
|
||||
return "romalrc"
|
||||
|
||||
class LrcMetaType(Enum):
|
||||
|
||||
class LrcMetaType(StrEnum):
|
||||
Title = "ti"
|
||||
Artist = "ar"
|
||||
Album = "al"
|
||||
Author = "au"
|
||||
Length = "length"
|
||||
LrcAuthor = "by"
|
||||
Author = "by"
|
||||
Offset = "offset"
|
||||
|
||||
|
||||
class LinkType(Enum):
|
||||
Track = "track"
|
||||
Album = "album"
|
||||
Playlist = "playlist"
|
||||
class LinkType(StrEnum):
|
||||
Track = auto()
|
||||
Album = auto()
|
||||
Playlist = auto()
|
||||
|
@ -157,20 +157,11 @@ class NCMLyrics:
|
||||
|
||||
lyrics: dict[LrcType, str] = {}
|
||||
|
||||
try:
|
||||
lyrics[LrcType.Origin] = data["lrc"]["lyric"]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
lyrics[LrcType.Translation] = data["tlyric"]["lyric"]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
lyrics[LrcType.Romaji] = data["romalrc"]["lyric"]
|
||||
except KeyError:
|
||||
pass
|
||||
for lrctype in LrcType:
|
||||
try:
|
||||
lyrics[lrctype] = data[lrctype.ncmAPIString()]["lyric"]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
return cls(
|
||||
id=None,
|
||||
|
Loading…
Reference in New Issue
Block a user