feature: support saving lyrics for pure music tracks and add a option to close it
This commit is contained in:
parent
d0349a7a4d
commit
7f4bb99e24
@ -16,13 +16,16 @@ from .app import NCMLyricsApp
|
||||
)
|
||||
@option("-e", "--exist", is_flag=True, help="仅在源文件存在时保存歌词文件。")
|
||||
@option("-O", "--overwrite", is_flag=True, help="在歌词文件已存在时重新获取歌词并覆盖写入。")
|
||||
@option("-n", "--no-pure-music", is_flag=True, help="不为纯音乐曲目保存歌词文件。")
|
||||
@option("-q", "--quiet", is_flag=True, help="不进行任何提示并跳过所有确认。")
|
||||
@argument(
|
||||
"links",
|
||||
nargs=-1,
|
||||
)
|
||||
def main(exist: bool, overwrite: bool, quiet: bool, outputs: list[Path], links: list[str]) -> None:
|
||||
NCMLyricsApp(exist=exist, overwrite=overwrite, quiet=quiet, outputs=outputs, links=links).run()
|
||||
def main(exist: bool, overwrite: bool, no_pure_music: bool, quiet: bool, outputs: list[Path], links: list[str]) -> None:
|
||||
NCMLyricsApp(
|
||||
exist=exist, overwrite=overwrite, noPureMusic=no_pure_music, quiet=quiet, outputs=outputs, links=links
|
||||
).run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -36,7 +36,9 @@ NCMLyricsAppTheme = Theme(
|
||||
|
||||
|
||||
class NCMLyricsApp:
|
||||
def __init__(self, exist: bool, overwrite: bool, quiet: bool, outputs: list[Path], links: list[str]) -> None:
|
||||
def __init__(
|
||||
self, exist: bool, overwrite: bool, noPureMusic: bool, quiet: bool, outputs: list[Path], links: list[str]
|
||||
) -> None:
|
||||
self.console = Console(theme=NCMLyricsAppTheme, highlight=False)
|
||||
self.progress = Progress(console=self.console)
|
||||
self.pool = ThreadPoolExecutor(max_workers=4)
|
||||
@ -45,6 +47,7 @@ class NCMLyricsApp:
|
||||
|
||||
self.exist = exist
|
||||
self.overwrite = overwrite
|
||||
self.noPureMusic = noPureMusic
|
||||
self.quiet = quiet
|
||||
if len(outputs) == 0:
|
||||
self.outputs = [Path()]
|
||||
@ -206,7 +209,7 @@ class NCMLyricsApp:
|
||||
return
|
||||
|
||||
ncmlyrics = self.api.getLyricsByTrack(track.id)
|
||||
if ncmlyrics.isPureMusic:
|
||||
if ncmlyrics.isPureMusic and self.noPureMusic:
|
||||
self.console.print(
|
||||
f"[trackarrow]-->[/trackarrow] {track.prettyString()} [dark_turquoise]==>[/dark_turquoise] [warning]为纯音乐, 跳过此曲目。[/warning]"
|
||||
)
|
||||
|
@ -8,7 +8,6 @@ __all__ = [
|
||||
"ObjectParseError",
|
||||
"ParseLinkError",
|
||||
"UnsupportedLinkError",
|
||||
"UnsupportedPureMusicTrackError",
|
||||
]
|
||||
|
||||
|
||||
@ -38,7 +37,3 @@ class ParseLinkError(NCMLyricsAppError):
|
||||
|
||||
class UnsupportedLinkError(NCMLyricsAppError):
|
||||
"""不支持的分享链接"""
|
||||
|
||||
|
||||
class UnsupportedPureMusicTrackError(NCMLyricsAppError):
|
||||
"""不支持纯音乐单曲"""
|
||||
|
@ -7,7 +7,6 @@ from typing import Generator, Iterable, Self
|
||||
|
||||
from .constant import CONFIG_LRC_AUTO_MERGE, CONFIG_LRC_AUTO_MERGE_OFFSET
|
||||
from .type import LrcMetaType, LrcType
|
||||
from .error import UnsupportedPureMusicTrackError
|
||||
from .object import NCMLyrics
|
||||
|
||||
__all__ = ["Lrc"]
|
||||
@ -35,9 +34,6 @@ class Lrc:
|
||||
|
||||
@classmethod
|
||||
def fromNCMLyrics(cls, lyrics: NCMLyrics) -> Self:
|
||||
if lyrics.isPureMusic:
|
||||
raise UnsupportedPureMusicTrackError
|
||||
|
||||
result = cls()
|
||||
|
||||
for lrcType in LrcType:
|
||||
|
Loading…
Reference in New Issue
Block a user