11from asyncio import run
22from contextlib import suppress
3- from pathlib import Path as Root
3+ from pathlib import Path
44from textwrap import fill
5+ from typing import Callable
56
67from click import (
78 Choice ,
89 Context ,
9- Path ,
10+ Path as ClickPath ,
1011 command ,
1112 echo ,
1213 option ,
2930__all__ = ["cli" ]
3031
3132
32- def check_value (function ) :
33+ def check_value (function : Callable ) -> Callable :
3334 def inner (ctx : Context , param , value ):
3435 return function (ctx , param , value ) if value else None
3536
@@ -55,22 +56,22 @@ async def __aenter__(self):
5556 await self .APP .__aenter__ ()
5657 return self
5758
58- async def __aexit__ (self , exc_type , exc_value , traceback ):
59+ async def __aexit__ (self , exc_type , exc_value , traceback ) -> None :
5960 await self .APP .__aexit__ (exc_type , exc_value , traceback )
6061
61- async def run (self ):
62+ async def run (self ) -> None :
6263 if self .url :
6364 await self .APP .extract_cli (self .url , index = self .index )
6465 self .__update_settings ()
6566
66- def __update_settings (self ):
67+ def __update_settings (self ) -> None :
6768 if self .update :
6869 self .settings .update (self .parameter )
6970
7071 def __check_settings_path (self ) -> Path :
7172 if not self .path :
7273 return VOLUME
73- return s .parent if (s := Root (self .path )).is_file () else VOLUME
74+ return s .parent if (s := Path (self .path )).is_file () else VOLUME
7475
7576 @staticmethod
7677 def __merge_cookie (data : dict ) -> None :
@@ -80,10 +81,10 @@ def __merge_cookie(data: dict) -> None:
8081
8182 def __clean_params (self , data : dict ) -> dict :
8283 # self.__merge_cookie(data)
83- return {k : v for k , v in data .items () if v != None }
84+ return {k : v for k , v in data .items () if v is not None }
8485
8586 @staticmethod
86- def __format_index (index : str ) -> list :
87+ def __format_index (index : str ) -> list [ int ] :
8788 if index :
8889 result = []
8990 values = index .split ()
@@ -160,6 +161,12 @@ def help_(ctx: Context, param, value) -> None:
160161 _ ("图文作品文件下载格式,支持:PNG、WEBP、JPEG、HEIC、AUTO" ),
161162 ),
162163 ("--live_download" , "-ld" , "bool" , _ ("动态图片下载开关" )),
164+ (
165+ "--video_preference" ,
166+ "-vp" ,
167+ "choice" ,
168+ _ ("视频下载偏好,支持:resolution、bitrate、size" ),
169+ ),
163170 ("--download_record" , "-dr" , "bool" , _ ("作品下载记录开关" )),
164171 (
165172 "--folder_mode" ,
@@ -182,6 +189,12 @@ def help_(ctx: Context, param, value) -> None:
182189 width = 55 ,
183190 ),
184191 ),
192+ (
193+ "--note_format" ,
194+ "-nfmt" ,
195+ "choice" ,
196+ _ ("作品信息保存格式,支持:txt、md、all" ),
197+ ),
185198 ("--language" , "-l" , "choice" , _ ("设置程序语言,目前支持:zh_CN、en_US" )),
186199 ("--settings" , "-s" , "str" , _ ("读取指定配置文件" )),
187200 # (
@@ -233,7 +246,7 @@ def help_(ctx: Context, param, value) -> None:
233246@option (
234247 "--work_path" ,
235248 "-wp" ,
236- type = Path (file_okay = False ),
249+ type = ClickPath (file_okay = False ),
237250)
238251@option (
239252 "--folder_name" ,
@@ -325,7 +338,7 @@ def help_(ctx: Context, param, value) -> None:
325338@option (
326339 "--settings" ,
327340 "-s" ,
328- type = Path (dir_okay = False ),
341+ type = ClickPath (dir_okay = False ),
329342)
330343# @option(
331344# "--browser_cookie",
0 commit comments