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"]
|
__all__ = ["LrcType", "LrcMetaType", "LinkType"]
|
||||||
|
|
||||||
|
|
||||||
class LrcType(Enum):
|
class LrcType(StrEnum):
|
||||||
Origin = auto()
|
Origin = auto()
|
||||||
Translation = auto()
|
Translation = auto()
|
||||||
Romaji = auto()
|
Romaji = auto()
|
||||||
@ -17,18 +17,27 @@ class LrcType(Enum):
|
|||||||
case LrcType.Romaji:
|
case LrcType.Romaji:
|
||||||
return "音"
|
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"
|
Title = "ti"
|
||||||
Artist = "ar"
|
Artist = "ar"
|
||||||
Album = "al"
|
Album = "al"
|
||||||
Author = "au"
|
Author = "au"
|
||||||
Length = "length"
|
Length = "length"
|
||||||
LrcAuthor = "by"
|
Author = "by"
|
||||||
Offset = "offset"
|
Offset = "offset"
|
||||||
|
|
||||||
|
|
||||||
class LinkType(Enum):
|
class LinkType(StrEnum):
|
||||||
Track = "track"
|
Track = auto()
|
||||||
Album = "album"
|
Album = auto()
|
||||||
Playlist = "playlist"
|
Playlist = auto()
|
||||||
|
@ -157,18 +157,9 @@ class NCMLyrics:
|
|||||||
|
|
||||||
lyrics: dict[LrcType, str] = {}
|
lyrics: dict[LrcType, str] = {}
|
||||||
|
|
||||||
|
for lrctype in LrcType:
|
||||||
try:
|
try:
|
||||||
lyrics[LrcType.Origin] = data["lrc"]["lyric"]
|
lyrics[lrctype] = data[lrctype.ncmAPIString()]["lyric"]
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
lyrics[LrcType.Translation] = data["tlyric"]["lyric"]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
lyrics[LrcType.Romaji] = data["romalrc"]["lyric"]
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user