diff --git a/ncmlyrics/enum.py b/ncmlyrics/enum.py index 105d018..20000b8 100644 --- a/ncmlyrics/enum.py +++ b/ncmlyrics/enum.py @@ -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() diff --git a/ncmlyrics/object.py b/ncmlyrics/object.py index d1a9c0d..0829070 100644 --- a/ncmlyrics/object.py +++ b/ncmlyrics/object.py @@ -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,