From 7f4bb99e24e222ad5b86ed30eeaacf50545eb6e1 Mon Sep 17 00:00:00 2001 From: Puqns67 Date: Wed, 4 Dec 2024 23:16:15 +0800 Subject: [PATCH] feature: support saving lyrics for pure music tracks and add a option to close it --- ncmlyrics/__main__.py | 7 +++++-- ncmlyrics/app.py | 7 +++++-- ncmlyrics/error.py | 5 ----- ncmlyrics/lrc.py | 4 ---- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ncmlyrics/__main__.py b/ncmlyrics/__main__.py index 8ffb19a..3635d2d 100644 --- a/ncmlyrics/__main__.py +++ b/ncmlyrics/__main__.py @@ -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__": diff --git a/ncmlyrics/app.py b/ncmlyrics/app.py index 83bedb4..cad6f37 100644 --- a/ncmlyrics/app.py +++ b/ncmlyrics/app.py @@ -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]" ) diff --git a/ncmlyrics/error.py b/ncmlyrics/error.py index a5aaffb..bbd1e94 100644 --- a/ncmlyrics/error.py +++ b/ncmlyrics/error.py @@ -8,7 +8,6 @@ __all__ = [ "ObjectParseError", "ParseLinkError", "UnsupportedLinkError", - "UnsupportedPureMusicTrackError", ] @@ -38,7 +37,3 @@ class ParseLinkError(NCMLyricsAppError): class UnsupportedLinkError(NCMLyricsAppError): """不支持的分享链接""" - - -class UnsupportedPureMusicTrackError(NCMLyricsAppError): - """不支持纯音乐单曲""" diff --git a/ncmlyrics/lrc.py b/ncmlyrics/lrc.py index 70f197c..595dac9 100644 --- a/ncmlyrics/lrc.py +++ b/ncmlyrics/lrc.py @@ -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: