feature: support saving lyrics for pure music tracks and add a option to close it

This commit is contained in:
Puqns67 2024-12-04 23:16:15 +08:00
parent d0349a7a4d
commit 7f4bb99e24
Signed by: Puqns67
GPG Key ID: 9669DF042554F536
4 changed files with 10 additions and 13 deletions

View File

@ -16,13 +16,16 @@ from .app import NCMLyricsApp
) )
@option("-e", "--exist", is_flag=True, help="仅在源文件存在时保存歌词文件。") @option("-e", "--exist", is_flag=True, help="仅在源文件存在时保存歌词文件。")
@option("-O", "--overwrite", 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="不进行任何提示并跳过所有确认。") @option("-q", "--quiet", is_flag=True, help="不进行任何提示并跳过所有确认。")
@argument( @argument(
"links", "links",
nargs=-1, nargs=-1,
) )
def main(exist: bool, overwrite: bool, quiet: bool, outputs: list[Path], links: list[str]) -> None: def main(exist: bool, overwrite: bool, no_pure_music: bool, quiet: bool, outputs: list[Path], links: list[str]) -> None:
NCMLyricsApp(exist=exist, overwrite=overwrite, quiet=quiet, outputs=outputs, links=links).run() NCMLyricsApp(
exist=exist, overwrite=overwrite, noPureMusic=no_pure_music, quiet=quiet, outputs=outputs, links=links
).run()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -36,7 +36,9 @@ NCMLyricsAppTheme = Theme(
class NCMLyricsApp: 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.console = Console(theme=NCMLyricsAppTheme, highlight=False)
self.progress = Progress(console=self.console) self.progress = Progress(console=self.console)
self.pool = ThreadPoolExecutor(max_workers=4) self.pool = ThreadPoolExecutor(max_workers=4)
@ -45,6 +47,7 @@ class NCMLyricsApp:
self.exist = exist self.exist = exist
self.overwrite = overwrite self.overwrite = overwrite
self.noPureMusic = noPureMusic
self.quiet = quiet self.quiet = quiet
if len(outputs) == 0: if len(outputs) == 0:
self.outputs = [Path()] self.outputs = [Path()]
@ -206,7 +209,7 @@ class NCMLyricsApp:
return return
ncmlyrics = self.api.getLyricsByTrack(track.id) ncmlyrics = self.api.getLyricsByTrack(track.id)
if ncmlyrics.isPureMusic: if ncmlyrics.isPureMusic and self.noPureMusic:
self.console.print( self.console.print(
f"[trackarrow]-->[/trackarrow] {track.prettyString()} [dark_turquoise]==>[/dark_turquoise] [warning]为纯音乐, 跳过此曲目。[/warning]" f"[trackarrow]-->[/trackarrow] {track.prettyString()} [dark_turquoise]==>[/dark_turquoise] [warning]为纯音乐, 跳过此曲目。[/warning]"
) )

View File

@ -8,7 +8,6 @@ __all__ = [
"ObjectParseError", "ObjectParseError",
"ParseLinkError", "ParseLinkError",
"UnsupportedLinkError", "UnsupportedLinkError",
"UnsupportedPureMusicTrackError",
] ]
@ -38,7 +37,3 @@ class ParseLinkError(NCMLyricsAppError):
class UnsupportedLinkError(NCMLyricsAppError): class UnsupportedLinkError(NCMLyricsAppError):
"""不支持的分享链接""" """不支持的分享链接"""
class UnsupportedPureMusicTrackError(NCMLyricsAppError):
"""不支持纯音乐单曲"""

View File

@ -7,7 +7,6 @@ from typing import Generator, Iterable, Self
from .constant import CONFIG_LRC_AUTO_MERGE, CONFIG_LRC_AUTO_MERGE_OFFSET from .constant import CONFIG_LRC_AUTO_MERGE, CONFIG_LRC_AUTO_MERGE_OFFSET
from .type import LrcMetaType, LrcType from .type import LrcMetaType, LrcType
from .error import UnsupportedPureMusicTrackError
from .object import NCMLyrics from .object import NCMLyrics
__all__ = ["Lrc"] __all__ = ["Lrc"]
@ -35,9 +34,6 @@ class Lrc:
@classmethod @classmethod
def fromNCMLyrics(cls, lyrics: NCMLyrics) -> Self: def fromNCMLyrics(cls, lyrics: NCMLyrics) -> Self:
if lyrics.isPureMusic:
raise UnsupportedPureMusicTrackError
result = cls() result = cls()
for lrcType in LrcType: for lrcType in LrcType: