API Reference

Module contents

py115.connect(credential=None, protocol_kwargs=None)

Connect to 115 cloud.

Parameters:
  • credential (py115.types.Credential) – Credential data to identity user.

  • protocol_kwargs (dict) – Keyword arguments for underlying protocol client.

Returns:

Cloud instance.

Return type:

py115.cloud.Cloud

Submodules

py115.cloud module

class py115.cloud.Cloud(credential=None, protocol_kwargs=None)

Bases: _Handler

115 cloud service.

Parameters:
  • credential (py115.types.Credential) – Credential object.

  • protocol_kwargs (dict) – Settings for underlying protocol client.

import_credential(credential)

Import credential to cloud instance.

Parameters:

credential (py115.types.Credential) – Credential object to identity user.

Returns:

Is credential valid.

Return type:

bool

export_credentail()

Export current credentail from cloud instance.

Returns:

Credential object, or None when credential is invalid.

Return type:

py115.types.Credential

qrcode_login(app_type)

Start QRcode login session.

Parameters:

app_type (py115.types.AppType) – App to login.

Returns:

QRcode login session.

Return type:

py115.login.QrcodeSession

offline()

Get offline service.

Returns:

Offline service instance.

Return type:

py115.services.OfflineService

storage()

Get storage service.

Returns:

Storage service instance.

Return type:

py115.services.StorageService

py115.login module

class py115.login.QrcodeSession

Bases: object

QRcode login session.

image_data: bytes

QRcode image data

poll()

Poll QRcode status. This method will block until login is done, or QRcode is invalid.

Returns:

Is login succeeded.

Return type:

bool

py115.services module

class py115.services.OfflineService

Bases: object

Offline task manager.

list()

Get all tasks.

Yields:

py115.types.Task – Task object

Return type:

Generator[Task, None, None]

add_url(*urls)

Create task(s) from download URL.

Parameters:

*urls (str) – Download URL, can be a http/ftp/ed2k/magnet link.

Returns:

Task list for the download URLs.

Return type:

Iterable[py115.types.Task]

delete(*task_ids)

Delete task(s).

Parameters:

*task_ids (str) – The ID of tasks you wants to delete.

clear(status=TaskStatus.Complete)

Clear tasks.

Parameters:

status (py115.types.TaskStatus) – Tasks in given status will be cleared. Set status to None to clear all tasks.

class py115.services.StorageService

Bases: object

Cloud file/directory manager.

space()

Get total size and used size of the storage.

Returns:

Total size and used size in byte.

Return type:

Tuple[int, int]

list(dir_id='0')

Get files under a directory.

Parameters:

dir_id (str) – Directory ID to list, default is “0” which means root directory.

Yields:

py115.types.File – File object under the directory.

Return type:

Generator[File, None, None]

search(keyword, dir_id='0')

Recursively search files under a directory.

Parameters:
  • keyword (str) – Keyword to search files.

  • dir_id (str) – Directory ID to search.

Yields:

py115.types.File – File object whose name contains the keyword.

move(target_dir_id, *file_ids)

Move files to a directory.

Parameters:
  • target_dir_id (str) – ID of target directory where to move files.

  • *file_ids (str) – ID of files to be moved.

rename(file_id, new_name)

Rename file.

Parameters:
  • file_id (str) – ID of file to be renamed.

  • new_name (str) – New name for the file.

delete(*file_ids)

Delete files.

Parameters:

*file_ids (str) – ID of files to be deleted.

make_dir(parent_id, name)

Make new directory under a directory.

Parameters:
  • parent_id (str) – ID of parent directory where to make new directory.

  • name (str) – Name for the new directory.

Returns:

File object of the created directory.

Return type:

py115.types.File

request_download(pickcode)

Download file from cloud storage.

Parameters:

pickcode (str) – Pick code of file.

Returns:

A ticket contains all required fields to download file from cloud.

Return type:

py115.types.DownloadTicket

request_play(pickcode)

Play a video file on cloud, returns required parameters as a ticket.

Parameters:

pickcode (str) – Pick code of file.

Returns:

A ticket contains all required fields to play the media file on cloud.

Return type:

py115.types.PlayTicket

request_upload(dir_id, file_path)

Upload local file to cloud storage.

Parameters:
  • dir_id (str) – ID of directory where to store the file.

  • file_path (str) – Path of the local file.

Returns:

A ticket contains all required fields to upload file to cloud, should be used with aliyun-oss-python-sdk.

Return type:

py115.types.UploadTicket

request_upload_data(dir_id, save_name, data_io)

Upload data as a file to cloud storage.

Parameters:
  • dir_id (str) – ID of directory where to store the file.

  • save_name (str) – File name to be saved.

  • data_io (BinaryIO) – IO stream of data.

Returns:

A ticket contains all required fields to upload file to cloud, should be used with aliyun-oss-python-sdk.

Return type:

py115.types.UploadTicket

py115.types module

class py115.types.AppType(value)

Bases: IntEnum

App to login.

Web = 0

Login as web

Mac = 1

Login as MAC app

Linux = 2

Login as Linux app

Windows = 3

Login as Windows app

class py115.types.Credential(uid=None, cid=None, seid=None)

Bases: _Base

Credential contains required information to identify user.

Parameters:
  • uid (str) – The “UID” value in cookies.

  • cid (str) – The “CID” value in cookies.

  • seid (str) – The “SEID” value in cookies.

classmethod from_dict(d)

Create Credential from a dict object.

Parameters:

d (dict) – Dict object.

Returns:

Credential object.

Return type:

py115.types.Credential

to_dict()

Convert credential object to dict object.

Returns:

Dict object.

Return type:

dict

class py115.types.File

Bases: _Base

File represents a cloud file or directory.

file_id: str

Unique ID of the file on cloud.

parent_id: str

File ID of the parent directory.

name: str

Base name.

size: int

Size in bytes.

modified_time: datetime

Last modified datetime.

sha1: str

SHA-1 hash of the file in HEX encoding.

pickcode: str

Pickcode to download the file.

is_dir: bool

Is file a directory.

class py115.types.DownloadTicket

Bases: _Base

DownloadTicket contains required parameters to download a file from cloud storage.

Please check examples for detail usage.

file_name: str

Base name of the file.

file_size: int

Size of the file.

url: str

Download URL.

headers: dict

Required headers that should be used with download URL.

class py115.types.PlayTicket

Bases: _Base

url: str

Download URL.

headers: dict

Required headers that should be used with download URL.

class py115.types.UploadTicket

Bases: _Base

UploadTicket contains required parameters to upload a file to cloud storage.

Please check examples for detial usage.

is_done: bool

Is file already uploaded.

oss_endpoint: str

OSS endpoint address.

oss_token: dict

OSS token

bucket_name: str

OSS bucket name.

object_key: str

OSS object key.

headers: dict

Required headers that should be used in upload.

expiration: datetime

Expiration time of this ticket.

is_valid()

Check whether the ticket is valid.

Returns:

Valid flag.

Return type:

bool

class py115.types.TaskStatus(value)

Bases: IntEnum

An enumeration.

Running = 1

Task is running.

Complete = 2

Task is complete.

Failed = -1

Task is failed.

Unknown = 0

Unknown status?

class py115.types.Task

Bases: _Base

Task represents an offline task.

task_id: str

Unique ID of the task.

name: str

Task name.

size: int

Total size to be downloaded.

created_time: datetime

Task created time.

percent: float

Precentage of the download, 0~100.

file_id: str

Downloaded file ID of the task, may be None if the task does not finish.

file_is_dir: bool

Is the downloaded file a directory.

status: TaskStatus

Task status.

is_complete()

Check is task complete.

Return type:

bool

is_failed()

Check is task failed.

Return type:

bool

is_running()

Check is task still running.

Return type:

bool