# geegeng

Geegeng Python API 客户端。

## 安装

```bash
pip install geegeng
```

## 快速开始

```python
from geegeng import GeegengClient

# 创建客户端并登录
client = GeegengClient(phone="your_phone", password="your_password")
client.login()

# 获取用户信息
user_info = client.get_user_info()
print(user_info)

# 列出文件
files = client.list_files()
print(files)
```

也可以使用便捷函数一步创建并登录：

```python
from geegeng import create_client

client = create_client(phone="your_phone", password="your_password")
```

## 功能

### 文件管理

```python
# 列出根目录文件
files = client.list_files(parent_id=-1)

# 搜索文件
results = client.search_files(keyword="video")

# 创建文件夹
client.create_folder(name="新文件夹", parent_id=-1)

# 删除文件
client.delete_files(file_ids=["file_id_1", "file_id_2"])
```

### 下载文件

```python
# 获取下载链接
url = client.get_download_url(file_id="your_file_id")

# 下载文件（支持进度回调）
def on_progress(downloaded, total):
    print(f"{downloaded / total * 100:.1f}%")

client.download_file(
    url=url,
    save_path="./downloads",
    progress_callback=on_progress,
)
```

### 上传文件

```python
# 上传文件（自动尝试秒传）
def on_progress(stage, current, total):
    if stage == "md5":
        print(f"计算 MD5: {current / total * 100:.1f}%")
    elif stage == "upload":
        print(f"上传中: {current / total * 100:.1f}%")
    elif stage == "complete":
        print("上传完成!")

result = client.upload_file(
    file_path="./video.mp4",
    parent_id=-1,
    progress_callback=on_progress,
)
```

### 分享功能

```python
# 创建分享链接
share = client.create_share(file_ids=["file_id"], days=7)

# 获取分享信息
info = client.get_share_info(share_id="share_id", share_pwd="password")
```

### 上下文管理器

```python
with GeegengClient(phone="your_phone", password="your_password") as client:
    client.login()
    files = client.list_files()
# 自动关闭连接
```

## 异常处理

```python
from geegeng import GeegengAuthError, GeegengAPIError

try:
    client.login()
except GeegengAuthError as e:
    print(f"登录失败: {e}")
except GeegengAPIError as e:
    print(f"API 错误: {e}")
```

## License

MIT
