attr¶
属性¶
这个模块提供了一些和文件或目录信息有关的函数
- p115client.tool.attr.get_ancestors(client: str | PathLike | P115Client | P115OpenClient, attr: int | str | dict = 0, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, ensure_file: None | bool = None, refresh: bool = False, app: str = 'web', *, async_: Literal[False] = False, **request_kwargs) list[dict][source]¶
- p115client.tool.attr.get_ancestors(client: str | PathLike | P115Client | P115OpenClient, attr: int | str | dict = 0, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, ensure_file: None | bool = None, refresh: bool = False, app: str = 'web', *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, list[dict]]
获取某个节点对应的祖先节点列表(只有 “id”、”parent_id” 和 “name” 的信息)
- Parameters:
client – 115 客户端或 cookies
attr – 待查询节点 id 或 pickcode 或信息字典(必须有 “id”,可选有 “parent_id” 或 “is_dir”)
id_to_dirnode – 字典,保存 id 到对应文件的
(name, parent_id)元组的字典ensure_file –
是否确保为文件
True: 确定是文件
False: 确定是目录
None: 不确定
refresh – 是否强制刷新,如果为 False,则尽量从
id_to_dirnode获取,以减少接口调用app – 使用指定 app(设备)的接口
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
目录所对应的祖先信息列表,每一条的结构如下
{ "id": int, # 目录的 id "parent_id": int, # 上级目录的 id "name": str, # 名字 }
- p115client.tool.attr.get_attr(client: str | PathLike | P115Client, id: int | str = 0, skim: bool = False, *, async_: Literal[False] = False, **request_kwargs) dict[source]¶
- p115client.tool.attr.get_attr(client: str | PathLike | P115Client, id: int | str = 0, skim: bool = False, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, dict]
获取文件或目录的信息
- Parameters:
client – 115 客户端或 cookies
id – 文件或目录的 id 或 pickcode
skim – 是否获取简要信息(可避免风控)
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
文件或目录的信息
- p115client.tool.attr.get_file_count(client: str | PathLike | P115Client, cid: int | str = 0, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, app: str = 'web', use_fs_files: bool = False, *, async_: Literal[False] = False, **request_kwargs) int[source]¶
- p115client.tool.attr.get_file_count(client: str | PathLike | P115Client, cid: int | str = 0, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, app: str = 'web', use_fs_files: bool = False, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, int]
获取文件总数
Caution
如果
use_fs_files = True,但cid不存在、已经被删除或者是文件,那么相当于cid = 0,这会导致导致长久的等待- Parameters:
client – 115 客户端或 cookies
cid – 目录 id 或 pickcode
id_to_dirnode – 字典,保存 id 到对应文件的
(name, parent_id)元组的字典app – 使用指定 app(设备)的接口
use_fs_files – 使用 client.fs_files,否则使用 client.fs_category_get
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
目录内的文件总数(不包括目录)
- p115client.tool.attr.get_id(client: str | PathLike | P115Client | P115OpenClient, id: int | str | Sequence[str] | Mapping = -1, pickcode: str = '', sha1: str = '', name: str = '', path: str | Sequence[str] = '', value: int | str | Sequence[str] = '', size: int = -1, cid: int = 0, ensure_file: None | bool = None, is_posixpath: bool = False, refresh: bool = False, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, app: str = 'web', dont_use_getid: bool = False, *, async_: Literal[False] = False, **request_kwargs) int[source]¶
- p115client.tool.attr.get_id(client: str | PathLike | P115Client | P115OpenClient, id: int | str | Sequence[str] | Mapping = -1, pickcode: str = '', sha1: str = '', name: str = '', path: str | Sequence[str] = '', value: int | str | Sequence[str] = '', size: int = -1, cid: int = 0, ensure_file: None | bool = None, is_posixpath: bool = False, refresh: bool = False, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, app: str = 'web', dont_use_getid: bool = False, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, int]
获取 id
Note
优先级,
id > pickcode > name > path > value- Parameters:
client – 115 客户端或 cookies
id – id 或某种可借以取得 id 的信息
pickcode – 提取码
sha1 – 文件的 sha1 散列值(hex 或 base32 编码)
name – 名称
path – 路径
value – 当
id、pickcode、name和path不可用时生效,将会自动决定所属类型size – 文件大小
cid – 顶层目录 id
ensure_file –
是否确保为文件
True: 必须是文件
False: 必须是目录
None: 可以是目录或文件
is_posixpath – 使用 posixpath,会把 “/” 转换为 “|”,因此解析的时候,会对 “|” 进行特别处理
refresh – 是否刷新。如果为 True,则会执行网络请求以查询;如果为 False,则直接从 id_to_dirnode 中获取
id_to_dirnode – 字典,保存 id 到对应文件的
(name, parent_id)元组的字典app – 使用指定 app(设备)的接口
dont_use_getid – 不要使用 client.fs_dir_getid 或 client.fs_dir_getid_app,以便 id_to_dirnode 有缓存
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
文件或目录的 id
- p115client.tool.attr.get_id_to_name(client: str | PathLike | P115Client | P115OpenClient, name: str, size: int = -1, cid: int | str = 0, ensure_file: None | bool = None, app: str = 'web', *, async_: Literal[False] = False, **request_kwargs) P115ID[source]¶
- p115client.tool.attr.get_id_to_name(client: str | PathLike | P115Client | P115OpenClient, name: str, size: int = -1, cid: int | str = 0, ensure_file: None | bool = None, app: str = 'web', *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, P115ID]
获取 name 对应的文件的 id
Caution
这个函数并不会检查输入的
name是否合法- Parameters:
client – 115 客户端或 cookies
name – 文件名
size – 文件大小
cid – 顶层目录 id
ensure_file –
是否确保为文件
True: 确定是文件
False: 确定是目录
None: 不确定
app – 使用指定 app(设备)的接口
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
文件或目录的 id
- p115client.tool.attr.get_id_to_path(client: str | PathLike | P115Client | P115OpenClient, path: str | Sequence[str], cid: int = 0, ensure_file: None | bool = None, is_posixpath: bool = False, refresh: bool = False, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, app: str = 'web', dont_use_getid: bool = False, *, async_: Literal[False] = False, **request_kwargs) int[source]¶
- p115client.tool.attr.get_id_to_path(client: str | PathLike | P115Client | P115OpenClient, path: str | Sequence[str], cid: int = 0, ensure_file: None | bool = None, is_posixpath: bool = False, refresh: bool = False, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, app: str = 'web', dont_use_getid: bool = False, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, int]
获取 path 对应的 id
- Parameters:
client – 115 客户端或 cookies
path – 路径
cid – 顶层目录的 id
ensure_file –
是否确保为文件
True: 必须是文件
False: 必须是目录
None: 可以是目录或文件
is_posixpath – 使用 posixpath,会把 “/” 转换为 “|”,因此解析的时候,会对 “|” 进行特别处理
refresh – 是否刷新。如果为 True,则会执行网络请求以查询;如果为 False,则直接从 id_to_dirnode 中获取
id_to_dirnode – 字典,保存 id 到对应文件的
(name, parent_id)元组的字典app – 使用指定 app(设备)的接口
dont_use_getid – 不要使用 client.fs_dir_getid 或 client.fs_dir_getid_app,以便 id_to_dirnode 有缓存
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
文件或目录的 id
- p115client.tool.attr.get_id_to_sha1(client: str | PathLike | P115Client | P115OpenClient, sha1: str, size: int = -1, cid: int | str = 0, app: str = 'web', *, async_: Literal[False] = False, **request_kwargs) P115ID[source]¶
- p115client.tool.attr.get_id_to_sha1(client: str | PathLike | P115Client | P115OpenClient, sha1: str, size: int = -1, cid: int | str = 0, app: str = 'web', *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, P115ID]
获取 sha1 对应的文件的 id
Caution
这个函数并不会检查输入的
sha1是否合法- Parameters:
client – 115 客户端或 cookies
sha1 – 文件的 sha1 哈希值(hex 或 base32 编码)
size – 文件大小
cid – 顶层目录 id
app – 使用指定 app(设备)的接口
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
文件或目录的 id
- p115client.tool.attr.get_info(client: str | PathLike | P115Client | P115OpenClient, id: int | str = 0, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, app: str = 'web', *, async_: Literal[False] = False, **request_kwargs) dict[source]¶
- p115client.tool.attr.get_info(client: str | PathLike | P115Client | P115OpenClient, id: int | str = 0, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, app: str = 'web', *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, dict]
获取文件或目录的信息
Caution
如果是目录,还包含其内(子目录树下)所有的文件数和目录数,数量越多,响应越久,所以对于目录要慎用
- Parameters:
client – 115 客户端或 cookies
id – 文件或目录的 id 或 pickcode
id_to_dirnode – 字典,保存 id 到对应文件的
(name, parent_id)元组的字典app – 使用指定 app(设备)的接口
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
文件或目录的信息
- p115client.tool.attr.get_path(client: str | PathLike | P115Client | P115OpenClient, attr: int | str | dict = 0, root_id: None | int | str = None, escape: None | bool | Callable[[str], str] = True, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, ensure_file: None | bool = None, refresh: bool = False, app: str = 'web', *, async_: Literal[False] = False, **request_kwargs) str[source]¶
- p115client.tool.attr.get_path(client: str | PathLike | P115Client | P115OpenClient, attr: int | str | dict = 0, root_id: None | int | str = None, escape: None | bool | Callable[[str], str] = True, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, ensure_file: None | bool = None, refresh: bool = False, app: str = 'web', *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, str]
获取目录对应的路径(绝对路径或相对路径)
- Parameters:
client – 115 客户端或 cookies
attr – 待查询节点 id 或 pickcode 或信息字典(必须有 “id”,可选有 “parent_id” 或 “is_dir”)
root_id – 根目录 id 或 pickcode,如果指定此参数且不为 None,则返回相对路径,否则返回绝对路径
escape –
对文件名进行转义
如果为 None,则不处理;否则,这个函数用来对文件名中某些符号进行转义,例如 “/” 等
如果为 True,则使用 posixpatht.escape,会对文件名中 “/”,或单独出现的 “.” 和 “..” 用 “" 进行转义
如果为 False,则使用 posix_escape_name 函数对名字进行转义,会把文件名中的 “/” 转换为 “|”
如果为 Callable,则用你所提供的调用,以或者转义后的名字
id_to_dirnode – 字典,保存 id 到对应文件的
(name, parent_id)元组的字典ensure_file –
是否确保为文件
True: 确定是文件
False: 确定是目录
None: 不确定
refresh – 是否刷新。如果为 True,则会执行网络请求以查询;如果为 False,则直接从 id_to_dirnode 中获取
app – 使用指定 app(设备)的接口
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
目录对应的绝对路径或相对路径
- p115client.tool.attr.get_url(client, value, /, size: int = -1, share_code: str = '', receive_code: str = '', cid: int = 0, user_agent: str = '', is_posixpath: bool = False, refresh: bool = False, id_to_dirnode: EllipsisType | MutableMapping[int, tuple[str, int]] | None = None, app: str = 'android', *, async_: Literal[False] = False, **request_kwargs) P115URL[source]¶
- p115client.tool.attr.get_url(client, value, /, size: int = -1, share_code: str = '', receive_code: str = '', cid: int = 0, user_agent: str = '', is_posixpath: bool = False, refresh: bool = False, id_to_dirnode: EllipsisType | MutableMapping[int, tuple[str, int]] | None = None, app: str = 'android', *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, P115URL]
获取文件的下载链接
- Parameters:
client – 115 客户端或 cookies
value – 文件的 id, pickcode, sha1, path, name 其一
size – 文件的大小,用于辅助判断
share_code – 分享码或链接
receive_code – 接收码
cid – 文件所在目录,用于辅助判断
user_agent – 下载链接的请求头中的 User-Agent
is_posixpath – 使用 posixpath,会把 “/” 转换为 “|”,因此解析的时候,会对 “|” 进行特别处理
refresh – 是否刷新。如果为 True,则会执行网络请求以查询;如果为 False,则直接从 id_to_dirnode 中获取
id_to_dirnode – 字典,保存 id 到对应文件的
(name, parent_id)元组的字典app – 使用指定 app(设备)的接口
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
文件的下载链接
- p115client.tool.attr.iter_list(client: str | PathLike | P115Client | P115OpenClient, cid: int | str = 0, start: int = 0, page_size: int = 7000, first_page_size: int = 0, payload: None | dict = None, normalize_attr: None | Callable[[dict], dict] = normalize_attr, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, app: str = 'web', *, async_: Literal[False] = False, **request_kwargs) Iterator[dict][source]¶
- p115client.tool.attr.iter_list(client: str | PathLike | P115Client | P115OpenClient, cid: int | str = 0, start: int = 0, page_size: int = 7000, first_page_size: int = 0, payload: None | dict = None, normalize_attr: None | Callable[[dict], dict] = normalize_attr, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, app: str = 'web', *, async_: Literal[True], **request_kwargs) AsyncIterator[dict]
在某个目录下面,迭代获取直属的文件或目录列表(逐页拉取)
- Parameters:
client – 115 客户端或 cookies
cid – 目录的 id 或 pickcode
start – 开始索引(从 0 开始)
page_size – 分页大小,如果 <= 0,则自动确定
first_page_size – 首次拉取的分页大小,如果 <= 0,则自动确定
payload – 其它的查询参数
normalize_attr – 把数据进行转换处理,使之便于阅读
id_to_dirnode – 字典,保存 id 到对应文件的
(name, parent_id)元组的字典app – 使用指定 app(设备)的接口
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
迭代器,每迭代一次执行一次分页拉取请求(就像瀑布流)
- p115client.tool.attr.normalize_attr(info: Mapping[str, Any], /, simple: bool = False, keep_raw: bool = False, default: None | Mapping[str, Any] | Iterable[tuple[str, Any]] = None, *, dict_cls: None = None) AttrDict[str, Any][source]¶
- p115client.tool.attr.normalize_attr(info: Mapping[str, Any], /, simple: bool = False, keep_raw: bool = False, default: None | Mapping[str, Any] | Iterable[tuple[str, Any]] = None, *, dict_cls: type[D]) D
翻译获取自罗列目录、搜索、获取文件信息等接口的数据,使之便于阅读
- Parameters:
info – 原始数据
simple – 只提取少量必要字段 “is_dir”, “id”, “parent_id”, “name”, “sha1”, “size”, “pickcode”, “is_collect”, “ctime”, “mtime”
keep_raw – 是否保留原始数据,如果为 True,则保存到 “raw” 字段
default – 一些预设值,可被覆盖
dict_cls – 字典类型
- Returns:
翻译后的 dict 类型数据
- p115client.tool.attr.normalize_attr_app(info: Mapping[str, Any], /, simple: bool = False, keep_raw: bool = False, default: None | Mapping[str, Any] | Iterable[tuple[str, Any]] = None, *, dict_cls: None = None) dict[str, Any][source]¶
- p115client.tool.attr.normalize_attr_app(info: Mapping[str, Any], /, simple: bool = False, keep_raw: bool = False, default: None | Mapping[str, Any] | Iterable[tuple[str, Any]] = None, *, dict_cls: type[D]) D
翻译
P115Client.fs_files_app()方法响应的文件信息数据,使之便于阅读- Parameters:
info – 原始数据
simple – 只提取少量必要字段 “is_dir”, “id”, “parent_id”, “name”, “sha1”, “size”, “pickcode”, “is_collect”, “ctime”, “mtime”, “type”
keep_raw – 是否保留原始数据,如果为 True,则保存到 “raw” 字段
default – 一些预设值,可被覆盖
dict_cls – 字典类型
- Returns:
翻译后的 dict 类型数据
- p115client.tool.attr.normalize_attr_app2(info: Mapping[str, Any], /, simple: bool = False, keep_raw: bool = False, default: None | Mapping[str, Any] | Iterable[tuple[str, Any]] = None, *, dict_cls: None = None) dict[str, Any][source]¶
- p115client.tool.attr.normalize_attr_app2(info: Mapping[str, Any], /, simple: bool = False, keep_raw: bool = False, default: None | Mapping[str, Any] | Iterable[tuple[str, Any]] = None, *, dict_cls: type[D]) D
翻译
P115Client.fs_files_app2()方法响应的文件信息数据,使之便于阅读- Parameters:
info – 原始数据
simple – 只提取少量必要字段 “is_dir”, “id”, “parent_id”, “name”, “sha1”, “size”, “pickcode”, “is_collect”, “ctime”, “mtime”, “type”
keep_raw – 是否保留原始数据,如果为 True,则保存到 “raw” 字段
default – 一些预设值,可被覆盖
dict_cls – 字典类型
- Returns:
翻译后的 dict 类型数据
- p115client.tool.attr.normalize_attr_simple(info: Mapping[str, Any], /, keep_raw: bool = False, default: None | Mapping[str, Any] | Iterable[tuple[str, Any]] = None, *, dict_cls: None = None) AttrDict[str, Any][source]¶
- p115client.tool.attr.normalize_attr_simple(info: Mapping[str, Any], /, keep_raw: bool = False, default: None | Mapping[str, Any] | Iterable[tuple[str, Any]] = None, *, dict_cls: type[D]) D
翻译获取自罗列目录、搜索、获取文件信息等接口的数据,使之便于阅读
Note
只提取少量必要字段 “is_dir”, “id”, “parent_id”, “name”, “sha1”, “size”, “pickcode”, “is_collect”, “ctime”, “mtime”
- Parameters:
info – 原始数据
keep_raw – 是否保留原始数据,如果为 True,则保存到 “raw” 字段
default – 一些预设值,可被覆盖
dict_cls – 字典类型
- Returns:
翻译后的 dict 类型数据
- p115client.tool.attr.normalize_attr_web(info: Mapping[str, Any], /, simple: bool = False, keep_raw: bool = False, default: None | Mapping[str, Any] | Iterable[tuple[str, Any]] = None, *, dict_cls: None = None) dict[str, Any][source]¶
- p115client.tool.attr.normalize_attr_web(info: Mapping[str, Any], /, simple: bool = False, keep_raw: bool = False, default: None | Mapping[str, Any] | Iterable[tuple[str, Any]] = None, *, dict_cls: type[D]) D
翻译
P115Client.fs_files()、P115Client.fs_search()、P115Client.share_snap()等方法响应的文件信息数据,使之便于阅读- Parameters:
info – 原始数据
simple – 只提取少量必要字段 “is_dir”, “id”, “parent_id”, “name”, “sha1”, “size”, “pickcode”, “is_collect”, “ctime”, “mtime”, “type”
keep_raw – 是否保留原始数据,如果为 True,则保存到 “raw” 字段
default – 一些预设值,可被覆盖
dict_cls – 字典类型
- Returns:
翻译后的 dict 类型数据
- p115client.tool.attr.share_get_id(client: str | PathLike | P115Client, share_code: str, receive_code: str = '', id: int | str | Sequence[str] | Mapping = -1, name: str = '', path: str | Sequence[str] = '', value: int | str | Sequence[str] = '', size: int = -1, cid: int = 0, ensure_file: None | bool = None, is_posixpath: bool = False, refresh: bool = False, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, int]
对分享链接,获取 id
Note
优先级,
name > path > value- Parameters:
client – 115 客户端或 cookies
share_code – 分享码或链接
receive_code – 接收码
id – id
name – 名称
path – 路径
value – 当
id、name和path不可用时生效,将会自动决定所属类型size – 文件大小
cid – 顶层目录 id
ensure_file –
是否确保为文件
True: 必须是文件
False: 必须是目录
None: 可以是目录或文件
is_posixpath – 使用 posixpath,会把 “/” 转换为 “|”,因此解析的时候,会对 “|” 进行特别处理
refresh – 是否刷新。如果为 True,则会执行网络请求以查询;如果为 False,则直接从 id_to_dirnode 中获取
id_to_dirnode – 字典,保存 id 到对应文件的
(name, parent_id)元组的字典async – 是否异步
request_kwargs – 其它请求参数
- Returns:
文件或目录的 id
- p115client.tool.attr.share_get_id_to_name(client: str | PathLike | P115Client, name: str, share_code: str, receive_code: str = '', size: int = -1, cid: int | str = 0, ensure_file: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, P115ID]
对分享链接,获取 sha1 对应的文件的 id
Caution
这个函数并不会检查输入的
name是否合法- Parameters:
client – 115 客户端或 cookies
name – 文件名
share_code – 分享码或链接
receive_code – 接收码
size – 文件大小
cid – 顶层目录 id
ensure_file –
是否确保为文件
True: 确定是文件
False: 确定是目录
None: 不确定
app – 使用指定 app(设备)的接口
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
文件或目录的 id
- p115client.tool.attr.share_get_id_to_path(client: str | PathLike | P115Client, share_code: str, receive_code: str = '', path: str | Sequence[str] = '', cid: int = 0, ensure_file: None | bool = None, is_posixpath: bool = False, refresh: bool = False, id_to_dirnode: None | EllipsisType | MutableMapping[int, tuple[str, int]] = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, int]
对分享链接,获取 path 对应的 id
- Parameters:
client – 115 客户端或 cookies
share_code – 分享码或链接
receive_code – 接收码
path – 路径
cid – 顶层目录的 id
ensure_file –
是否确保为文件
True: 必须是文件
False: 必须是目录
None: 可以是目录或文件
is_posixpath – 使用 posixpath,会把 “/” 转换为 “|”,因此解析的时候,会对 “|” 进行特别处理
refresh – 是否刷新。如果为 True,则会执行网络请求以查询;如果为 False,则直接从 id_to_dirnode 中获取
id_to_dirnode – 字典,保存 id 到对应文件的
(name, parent_id)元组的字典async – 是否异步
request_kwargs – 其它请求参数
- Returns:
文件或目录的 id