Metadata-Version: 2.4
Name: opendrama
Version: 0.1.0
Summary: OpenDrama 核心库：编剧 / 资产 / 分镜 / 视频 / 后期流水线（web.Runner）
Home-page: https://github.com/
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: pyyaml>=6.0
Requires-Dist: requests>=2.32.0
Requires-Dist: httpx>=0.28.0
Requires-Dist: pydantic<3,>=2.5.0
Requires-Dist: typing-extensions>=4.12.0
Requires-Dist: numpy>=1.26.0
Requires-Dist: imageio-ffmpeg>=0.6.0
Requires-Dist: faster-whisper>=1.2.0
Requires-Dist: langchain-core>=0.3.0
Requires-Dist: langchain-openai>=0.2.0
Requires-Dist: langgraph>=0.2.0
Requires-Dist: cloudinary>=1.36.0
Requires-Dist: boto3>=1.28.0
Requires-Dist: markdown>=3.5.0
Requires-Dist: pypdf>=4.0.0
Requires-Dist: pikepdf>=8.0.0
Requires-Dist: Pillow>=10.0.0
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# OpenDrama（Python 包）

**[English](README.en.md)**

本目录提供 `setup.py`，用于把同级的 **`OpenDrama/`** 目录打成可安装的 Python 分发包（包名 **`opendrama`**）。  
源码布局是**扁平顶层导入**（例如 `from web import Runner`），与 **OpenDrama_Web** 里 `backend` 的用法一致。

当前 **`setup.py` 中的分发版本** 为 **0.1.0**（发布请在 `submodules/setup.py` 的 `_VERSION` 处递增）。

## 与本仓库 `backend` / `web` 的关系

- **`backend`**（FastAPI）并不通过 PyPI 依赖本包；它在运行时把 **OpenDrama 根目录** 插入 `sys.path`，再执行与 CLI 相同的导入：
  - `from web import Runner`
  - `from utils.common_utils import load_config`
  - `from step0_config import Step0_SetConfig`
  - 并在调用前设置 **`CONFIG_PATH`** 指向项目 YAML（绝对路径）。
  - 默认 OpenDrama 根目录为仓库内 **`OpenDrama_Web/submodules/OpenDrama`**；可通过整站配置 / 环境变量 **`OPENDRAMA_ROOT`** 指向其它检出路径（须含 `config/default.yaml`）。
- **`web`**（Vite 前端）通过 **`/api/v1/...`** 调用上述后端；本地开发时由 Vite 把 `/api` 代理到后端端口。前端里 `@opendramaRoot` 等别名仍指向子模块目录，与「是否 pip 安装 opendrama」无关。

若你希望在**任意虚拟环境**里 `import web` / `import utils` 而不手动改 `sys.path`，可使用本 `setup.py` 安装（见下文）。

## 安装

在 **`OpenDrama_Web/submodules`** 下执行：

```bash
# 可编辑安装（开发推荐；与直接改 OpenDrama/ 源码一致）
pip install -e .

# 或打 wheel / 安装发行版
pip install .
```

完整依赖见 **`OpenDrama/requirements.txt`**。其中 **`-r submodules/MediaCrawler/requirements.txt`** 在打包时会被忽略（避免未检出 MediaCrawler 时安装失败）；若你需要爬虫相关能力，请自行按 OpenDrama 仓库说明安装 MediaCrawler 及其依赖。

**系统工具（非 pip）**：流水线中的后期与视频工具会通过子进程调用 **FFmpeg** 等，请安装并保证在 `PATH` 中。

## 使用方式（与 `backend` 对齐的最小示例）

```python
import os
from pathlib import Path

from utils.common_utils import load_config
from web import Runner

cfg_path = os.environ.get("CONFIG_PATH") or str(
    Path("/path/to/OpenDrama/config/your_project.yaml").resolve()
)
os.environ["CONFIG_PATH"] = cfg_path

cfg = load_config(cfg_path)
runner = Runner(cfg)
# 再调用 runner 上与 web 流程一致的方法（由业务 YAML 与步骤决定）
```

要点：

- **`CONFIG_PATH`**：必须指向**已存在**的项目 YAML；`load_config` / `Runner` 依赖其中的 `save_dir`、`env` 等字段。
- **`utils.common_utils`** 中的工程根 `_PROJECT_ROOT` 由 **`utils/common_utils.py` 的位置**推导：可编辑安装时即为你的 **`OpenDrama/`** 目录；普通安装时为 **site-packages** 根（本包会把 `config/`、`prompt/`、`admin/` 等数据装到同一根下，以便默认能找到 `config/default.yaml` 等）。
- 顶层模块名 **`web`** 较通用；若环境中有同名包，请使用虚拟环境隔离。

## 许可

以 **OpenDrama** 上游仓库为准（本文件仅描述打包与集成方式）。

---

# OpenDrama (Python package)

**[中文说明](README.md)**

This directory contains `setup.py` to build the sibling **`OpenDrama/`** tree into an installable Python distribution named **`opendrama`**.  
The code layout uses **flat top-level imports** (e.g. `from web import Runner`), matching how **OpenDrama_Web**’s **`backend`** uses it.

The **distribution version** in **`setup.py`** is **0.1.0** (bump `_VERSION` in `submodules/setup.py` when releasing).

## How this relates to `backend` / `web` in this repo

- **`backend`** (FastAPI) does **not** depend on this package via PyPI. At runtime it prepends the **OpenDrama root** to `sys.path` and uses the same imports as the CLI:
  - `from web import Runner`
  - `from utils.common_utils import load_config`
  - `from step0_config import Step0_SetConfig`
  - Set **`CONFIG_PATH`** to your project YAML (absolute path) before calling into OpenDrama.
  - By default the OpenDrama root is **`OpenDrama_Web/submodules/OpenDrama`**; override with site config / **`OPENDRAMA_ROOT`** (must contain `config/default.yaml`).
- **`web`** (Vite frontend) talks to that backend via **`/api/v1/...`**; in local dev, Vite proxies `/api` to the API port. Aliases like `@opendramaRoot` still point at the submodule tree and are unrelated to whether you `pip install opendrama`.

Use this `setup.py` when you want `import web` / `import utils` in any venv **without** manually editing `sys.path`.

## Installation

From **`OpenDrama_Web/submodules`**:

```bash
# Editable install (recommended for dev; edits in OpenDrama/ apply immediately)
pip install -e .

# Or build/install a wheel
pip install .
```

Full Python deps are listed in **`OpenDrama/requirements.txt`**. The line **`-r submodules/MediaCrawler/requirements.txt`** is **skipped** during packaging so installs do not fail when MediaCrawler is missing; install crawler deps separately if you need that stack.

**System tools (not from pip)**: post-processing and video helpers invoke **FFmpeg** (and similar) via subprocess—install them and ensure they are on `PATH`.

## Minimal usage (aligned with `backend`)

```python
import os
from pathlib import Path

from utils.common_utils import load_config
from web import Runner

cfg_path = os.environ.get("CONFIG_PATH") or str(
    Path("/path/to/OpenDrama/config/your_project.yaml").resolve()
)
os.environ["CONFIG_PATH"] = cfg_path

cfg = load_config(cfg_path)
runner = Runner(cfg)
# Then call the same Runner methods as in the web flow (depends on your YAML and step)
```

Notes:

- **`CONFIG_PATH`** must point to an **existing** project YAML; `load_config` / `Runner` rely on fields such as `save_dir`, `env`, etc.
- **`utils.common_utils`** derives project root `_PROJECT_ROOT` from **`utils/common_utils.py`’s location**: editable installs resolve to your **`OpenDrama/`** checkout; plain installs resolve to **site-packages** (this package installs `config/`, `prompt/`, `admin/` next to `utils/` so defaults like `config/default.yaml` still resolve).
- The top-level module name **`web`** is generic; use a dedicated virtualenv if you risk clashing with another `web` package.

## License

Follow the upstream **OpenDrama** repository (this file only describes packaging and integration).
