fs¶
此模块包含了客户端操作的文件系统封装
- class p115client.fs.P115FileSystem(client: str | PathLike | P115Client, refresh: bool = False, id_to_readdir: None | int | dict[int, dict[int, MutableMapping]] = None)[source]¶
Bases:
P115FileSystemBase[P115Path]- copy(id_or_path: IDOrPathType, /, to_dir: IDOrPathType = '', pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) dict[source]¶
- copy(id_or_path: IDOrPathType, /, to_dir: IDOrPathType = '', pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, dict]
复制文件或目录
- get_url(id_or_path: IDOrPathType, /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) P115URL[source]¶
- get_url(id_or_path: IDOrPathType, /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, P115URL]
获取下载链接
- iterdir(id: int, /, async_: Literal[False] = False, **request_kwargs) Iterator[dict][source]¶
- iterdir(id: int, /, async_: Literal[True], **request_kwargs) AsyncIterator[dict]
迭代获取某个目录下直属的文件或目录的信息,并且需要负责更新 self.id_to_dirnode
- mkdir(id_or_path: IDOrPathType, /, name: str, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) AttrDict[source]¶
- mkdir(id_or_path: IDOrPathType, /, name: str, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, AttrDict]
创建目录
- move(id_or_path: IDOrPathType, /, to_dir: IDOrPathType = '', pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) AttrDict[source]¶
- move(id_or_path: IDOrPathType, /, to_dir: IDOrPathType = '', pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, AttrDict]
移动文件或目录
- path_class¶
alias of
P115Path
- remove(id_or_path: IDOrPathType, /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) AttrDict[source]¶
- remove(id_or_path: IDOrPathType, /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, AttrDict]
删除文件或目录
- rename(id_or_path: IDOrPathType, /, name: str, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) AttrDict[source]¶
- rename(id_or_path: IDOrPathType, /, name: str, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, AttrDict]
重命名文件或路径
- upload(id_or_path: IDOrPathType, /, file: Buffer | str | PathLike | URL | SupportsGeturl | SupportsRead | Iterable[Buffer] = b'', filename: str = '', filesha1: str = '', filesize: int = -1, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) AttrDict[source]¶
- upload(id_or_path: IDOrPathType, /, file: Buffer | str | PathLike | URL | SupportsGeturl | SupportsRead | Iterable[Buffer] | AsyncIterable[Buffer] = b'', filename: str = '', filesha1: str = '', filesize: int = -1, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, AttrDict]
上传文件到目录
- class p115client.fs.P115FileSystemBase(client: str | PathLike | P115Client, refresh: bool = False, id_to_readdir: None | int | dict[int, dict[int, MutableMapping]] = None)[source]¶
-
- as_path(id_or_path: IDOrPathType = '', /, pid: None | int = None, ensure_file: None | bool = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) P115PathType[source]¶
- as_path(id_or_path: IDOrPathType = '', /, pid: None | int = None, ensure_file: None | bool = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, P115PathType]
获取对应的路径对象
- chdir(id_or_path: IDOrPathType = 0, /, pid: None | int = None, *, async_: Literal[False] = False, **request_kwargs) int[source]¶
- chdir(id_or_path: IDOrPathType = 0, /, pid: None | int = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, int]
切换工作目录
- dirlen(id_or_path: IDOrPathType = '', /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) int[source]¶
- dirlen(id_or_path: IDOrPathType = '', /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, int]
获取目录直属的文件和目录个数
- download(id_or_path: IDOrPathType, /, path: bytes | str | PathLike = '', mode: Literal['a', 'w', 'x', 'i'] = 'a', pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) tuple[str, int][source]¶
- download(id_or_path: IDOrPathType, /, path: bytes | str | PathLike = '', mode: Literal['a', 'w', 'x', 'i'] = 'a', pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, tuple[str, int]]
下载文件到本地
- Parameters:
id_or_path – 文件在 115 网盘上的 id 或路径
path – 本地文件路径
mode – 写入模式 - a: append,如果文件不存在则创建,存在则追加(断点续传),返回一个任务 - w: write, 如果文件不存在则创建,存在则覆盖 - x: exists,如果文件不存在则创建,存在则报错 FileExistsError - i: ignore,如果文件不存在则创建,存在则忽略
pid – 相对路径的根目录 id
refresh – 是否刷新数据
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
写入的文件路径和字节数
- has_child(child: int | str, parent: IDOrPathType = '', pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) bool[source]¶
- has_child(child: int | str, parent: IDOrPathType = '', pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, bool]
检查目录中是否存在某个文件或目录
- is_empty(id_or_path: IDOrPathType = '', /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) bool[source]¶
- is_empty(id_or_path: IDOrPathType = '', /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, bool]
是否为空文件、空目录或者不存在
- abstractmethod iterdir(id: int, /, async_: Literal[False] = False, **request_kwargs) Iterable[MutableMapping][source]¶
- abstractmethod iterdir(id: int, /, async_: Literal[True], **request_kwargs) AsyncIterable[MutableMapping]
迭代获取某个目录下直属的文件或目录的信息,并且需要负责更新 self.id_to_dirnode
- open(id_or_path: IDOrPathType, /, mode: Literal['rb', 'br'] = 'rb', buffering: None | int = None, encoding: None | str = None, errors: None | str = None, newline: None | str = None, start: int = 0, seek_threshold: int = 1 << 20, http_file_reader_cls: None | type[HTTPFileReader] = None, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) HTTPFileReader | BufferedReader[source]¶
- open(id_or_path: IDOrPathType, /, mode: Literal['r', 'rt', 'tr'], buffering: None | int = None, encoding: None | str = None, errors: None | str = None, newline: None | str = None, start: int = 0, seek_threshold: int = 1 << 20, http_file_reader_cls: None | type[HTTPFileReader] = None, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) TextIOWrapper
- open(id_or_path: IDOrPathType, /, mode: Literal['rb', 'br'] = 'rb', buffering: None | int = None, encoding: None | str = None, errors: None | str = None, newline: None | str = None, start: int = 0, seek_threshold: int = 1 << 20, http_file_reader_cls: None | type[AsyncHTTPFileReader] = None, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) AsyncHTTPFileReader | AsyncBufferedReader
- open(id_or_path: IDOrPathType, /, mode: Literal['r', 'rt', 'tr'], buffering: None | int = None, encoding: None | str = None, errors: None | str = None, newline: None | str = None, start: int = 0, seek_threshold: int = 1 << 20, http_file_reader_cls: None | type[AsyncHTTPFileReader] = None, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) AsyncTextIOWrapper
打开一个文件,仅用于读取
- read(id_or_path: IDOrPathType = '', /, start: None | int = None, stop: None | int | Undefined = undefined, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) bytes[source]¶
- read(id_or_path: IDOrPathType = '', /, start: None | int = None, stop: None | int | Undefined = undefined, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, bytes]
- read_block(id_or_path: IDOrPathType = '', /, start: int = 0, size: None | int = None, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) bytes[source]¶
- read_block(id_or_path: IDOrPathType = '', /, start: int = 0, size: None | int = None, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, bytes]
- stat(id_or_path: IDOrPathType = '', /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) stat_result[source]¶
- stat(id_or_path: IDOrPathType = '', /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, stat_result]
检查文件或目录的属性,就像 os.stat
Bases:
P115FileSystemBase分享的创建时间
分享的创建时间
- get_url(id_or_path: IDOrPathType, /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, P115URL]
获取下载链接
- iterdir(id: int, /, async_: Literal[True], **request_kwargs) AsyncIterator[MutableMapping]
迭代获取某个目录下直属的文件或目录的信息,并且需要负责更新 self.id_to_dirnode
- receive(ids: int | str | Iterable[int | str], /, to_pid: int = 0, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, dict]
接收分享文件到网盘
- Parameters:
ids – 要转存到文件 id(这些 id 归属分享链接)
to_pid – 你的网盘的一个目录 id(这个 id 归属你的网盘)
async – 是否异步
request_kwargs – 其它请求参数
- Returns:
接口响应
获取分享的首页数据
获取分享信息
获取分享者的用户 id
获取这个分享的 id
- class p115client.fs.P115ZipFileSystem(client: str | PathLike | P115Client, pickcode: str, refresh: bool = False, id_to_readdir: None | int | dict[int, dict[int, MutableMapping]] = None)[source]¶
Bases:
P115FileSystemBase[P115ZipPath]- extract(path: IDOrPathType = '', to_pid: int | str = 0, pid: None | int = None, *, async_: Literal[False] = False, **request_kwargs) int[source]¶
- extract(path: IDOrPathType = '', to_pid: int | str = 0, pid: None | int = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, int]
解压缩到网盘
- extract_many(paths: Iterable[IDOrPathType], to_pid: int | str = 0, pid: None | int = None, *, async_: Literal[False] = False, **request_kwargs) int[source]¶
- extract_many(paths: Iterable[IDOrPathType], to_pid: int | str = 0, pid: None | int = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, int]
解压缩到网盘
- get_url(id_or_path: IDOrPathType, /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[False] = False, **request_kwargs) P115URL[source]¶
- get_url(id_or_path: IDOrPathType, /, pid: None | int = None, refresh: None | bool = None, *, async_: Literal[True], **request_kwargs) Coroutine[Any, Any, P115URL]
获取下载链接