export_dir¶
导出目录树
这个模块提供了一些和导出目录树有关的函数
- p115client.tool.export_dir.export_dir(client: str | PathLike | P115Client, export_file_ids: int | str | Iterable[int | str], target_pid: int | str = 0, layer_limit: int = 0, *, async_: Literal[False] = False, **request_kwargs) int[source]¶
- p115client.tool.export_dir.export_dir(client: str | PathLike | P115Client, export_file_ids: int | str | Iterable[int | str], target_pid: int | str = 0, layer_limit: int = 0, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, int]
导出目录树
- Parameters:
client – 115 客户端或 cookies
export_file_ids – 待导出的目录 id 或 pickcode
target_pid – 导出到的目标目录 id 或 pickcode
layer_limit – 层级深度,小于等于 0 时不限
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
返回任务 id,可用 P115Client.fs_export_dir_status 查询进度
- p115client.tool.export_dir.export_dir_parse_iter(client: str | PathLike | P115Client, export_file_ids: int | str | Iterable[int | str] = 0, export_id: int | str = 0, target_pid: int | str = 0, layer_limit: int = 0, parse_iter: None | Callable[[IO[bytes]], Iterator] = None, delete: bool = True, timeout: None | int | float = None, check_interval: int | float = 1, show_clock: bool | Callable[[], Any] = False, clock_interval: int | float = 0.05, *, async_: Literal[False] = False, **request_kwargs) Iterator[source]¶
- p115client.tool.export_dir.export_dir_parse_iter(client: str | PathLike | P115Client, export_file_ids: int | str | Iterable[int | str] = 0, export_id: int | str = 0, target_pid: int | str = 0, layer_limit: int = 0, parse_iter: None | Callable[[IO[bytes]], AsyncIterator] = None, delete: bool = True, timeout: None | int | float = None, check_interval: int | float = 1, show_clock: bool | Callable[[], Any] = False, clock_interval: int | float = 0.05, *, async_: Literal[True], **request_kwargs) AsyncIterator
导出目录树到文件,读取文件并解析后返回迭代器,关闭后自动删除导出的文件
- Parameters:
client – 115 客户端或 cookies
export_file_ids – 待导出的目录 id、pickcode 或 路径(如果有多个,需传入可迭代对象)
export_id – 优先级高于 export_file_ids,之前提交的 export_dir 任务的 id,如果是 str,则视为导出的目录树文件的提取码(因此无需导出)
target_pid – 导出到的目标目录 id 或 pickcode
layer_limit – 层级深度,小于等于 0 时不限
parse_iter – 解析打开的二进制文件,返回可迭代对象
delete – 最终删除目录树文件(如果 export_id 为 str(即提取码),则这个值不生效,必不删除)
timeout – 导出任务的超时秒数,如果为 None 或 小于等于 0,则相当于 float(“inf”),即永不超时
check_interval – 导出任务的状态,两次轮询之间的等待秒数,如果 <= 0,则不等待
show_clock – 是否在等待导出目录树时,显示时钟。如果为 True,则显示默认的时钟,如果为 Callable,则作为自定义时钟进行调用(无参数)
clock_interval – 更新时钟的时间间隔
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
解析导出文件的迭代器
- p115client.tool.export_dir.export_dir_result(client: str | PathLike | P115Client, export_id: int | str, timeout: None | int | float = None, check_interval: int | float = 1, *, async_: Literal[False] = False, **request_kwargs) dict[source]¶
- p115client.tool.export_dir.export_dir_result(client: str | PathLike | P115Client, export_id: int | str, timeout: None | int | float = None, check_interval: int | float = 1, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, dict]
获取导出目录树的结果
Attention
如果指定超时时间为正数,则会在过期时抛出 TimeoutError,但这并不会取消远程正在执行的任务,而 115 同时只允许运行一个导出目录树的任务,所以如果要开始下一个导出任务,还需要此任务完成或者被 115 自动超时取消
- Parameters:
client – 115 客户端或 cookies
export_id – 任务 id,由 P115Client.fs_export_dir 接口调用产生
timeout – 超时秒数,如果为 None 或 小于等于 0,则相当于 float(“inf”),即永不超时
check_interval – 两次轮询之间的等待秒数,如果 <= 0,则不等待
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
接口返回结果,格式为
{ "export_id": str, # 任务 id "file_id": str, # 导出文件的 id "file_name": str, # 导出文件的名字 "pick_code": str # 导出文件的提取码 }
- p115client.tool.export_dir.parse_export_dir_as_dict_iter(file: bytes | str | PathLike | Iterable[bytes | str], /, encoding: str = 'utf-16', close_file: bool = False, *, async_: Literal[False] = False) Iterator[dict][source]¶
- p115client.tool.export_dir.parse_export_dir_as_dict_iter(file: bytes | str | PathLike | Iterable[bytes | str] | AsyncIterable[bytes | str], /, encoding: str = 'utf-16', close_file: bool = False, *, async_: Literal[True]) AsyncIterator[dict]
解析 115 导出的目录树(可通过 P115Client.fs_export_dir 提交导出任务)
- Parameters:
file – 文件路径、打开的文件或者迭代器(每次返回一行)
encoding – 字符编码,对字节数据使用,转换为字符串
close_file – 结束(包括异常退出)时尝试关闭 file
async – 是否异步
- Returns:
把每一行解析为一个字典,迭代返回,格式为
{ "key": int, # 序号 "parent_key": int, # 上级目录的序号 "depth": int, # 深度 "name": str, # 名字 }
- p115client.tool.export_dir.parse_export_dir_as_path_iter(file: bytes | str | PathLike | Iterable[bytes | str], /, encoding: str = 'utf-16', escape: None | bool | Callable[[str], str] = True, close_file: bool = False, *, async_: Literal[False] = False) Iterator[str][source]¶
- p115client.tool.export_dir.parse_export_dir_as_path_iter(file: bytes | str | PathLike | Iterable[bytes | str] | AsyncIterable[bytes | str], /, encoding: str = 'utf-16', escape: None | bool | Callable[[str], str] = True, close_file: bool = False, *, async_: Literal[True]) AsyncIterator[str]
解析 115 导出的目录树(可通过 P115Client.fs_export_dir 提交导出任务)
- Parameters:
file – 文件路径、打开的文件或者迭代器(每次返回一行)
encoding – 字符编码,对字节数据使用,转换为字符串
escape –
对文件名进行转义
如果为 None,则不处理;否则,这个函数用来对文件名中某些符号进行转义,例如 “/” 等
如果为 True,则使用 posixpatht.escape,会对文件名中 “/”,或单独出现的 “.” 和 “..” 用 “" 进行转义
如果为 False,则使用 posix_escape_name 函数对名字进行转义,会把文件名中的 “/” 转换为 “|”
如果为 Callable,则用你所提供的调用,以或者转义后的名字
close_file – 结束(包括异常退出)时尝试关闭 file
async – 是否异步
- Returns:
把每一行解析为一个路径,并逐次迭代返回
- p115client.tool.export_dir.parse_export_dir_as_patht_iter(file: bytes | str | PathLike | Iterable[bytes | str], /, encoding: str = 'utf-16', close_file: bool = False, *, async_: Literal[False] = False) Iterator[list[str]][source]¶
- p115client.tool.export_dir.parse_export_dir_as_patht_iter(file: bytes | str | PathLike | Iterable[bytes | str] | AsyncIterable[bytes | str], /, encoding: str = 'utf-16', close_file: bool = False, *, async_: Literal[True]) AsyncIterator[list[str]]
解析 115 导出的目录树(可通过 P115Client.fs_export_dir 提交导出任务)
- Parameters:
file – 文件路径、打开的文件或者迭代器(每次返回一行)
encoding – 字符编码,对字节数据使用,转换为字符串
close_file – 结束(包括异常退出)时尝试关闭 file
async – 是否异步
- Returns:
把每一行解析为一个名字列表,并逐次迭代返回