Metadata-Version: 2.4
Name: dycap
Version: 0.1.2
Summary: Douyu Live Stream Danmu Collector - async library and CLI for collecting chat messages.
Author-email: Douyu Danmu Crawler Project <contact@example.com>
License: MIT
Keywords: douyu,danmu,chat,websocket,collector
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Requires-Dist: dycommon>=0.1.0
Requires-Dist: dyproto[discovery]>=0.1.0
Requires-Dist: websockets>=12.0
Requires-Dist: psycopg[binary]>=3.0.0
Requires-Dist: cyclopts
Requires-Dist: rich>=14.0.0
Requires-Dist: loguru>=0.7.0
Requires-Dist: tenacity>=9.1.2

# dycap

Douyu Live Stream Danmu Collector - async library and CLI for collecting chat messages.

## Installation

```bash
pip install dycap
```

## Quick Start

### CLI

```bash
# Collect to PostgreSQL (default)
export DYKIT_DSN="postgresql://user:pass@localhost:5432/douyu"
dycap -r 6657

# Collect to CSV
dycap -r 6657 --storage csv -o backup.csv

# Collect to console
dycap -r 6657 --storage console

# Show version
dycap --version
```

### Python API

```python
import asyncio
from dycap import AsyncCollector, PostgreSQLStorage

async def main():
    storage = await PostgreSQLStorage.create(
        room_id="6657",
        host="localhost",
        port=5432,
        database="douyu",
        user="douyu",
        password="pass"
    )
    
    async with storage:
        collector = AsyncCollector("6657", storage)
        try:
            await collector.connect()
        except KeyboardInterrupt:
            await collector.stop()

asyncio.run(main())
```

## Features

- **Async WebSocket collection** - High-performance async collection
- **Multiple storage backends** - PostgreSQL, CSV, Console
- **Batch writes** - Optimized PostgreSQL with buffered batch inserts
- **Type filtering** - Filter message types to collect
- **Automatic reconnection** - Robust connection handling

## CLI Options

| Option | Description |
|--------|-------------|
| `-r, --room` | Room ID (required) |
| `--dsn` | PostgreSQL DSN |
| `--storage` | Storage backend (postgres/csv/console) |
| `-o, --output` | Output file for CSV |
| `-v, --verbose` | Enable verbose logging |
| `--with TYPES` | Include only specified message types (comma-separated). Available: `chatmsg（弹幕）`, `dgb（礼物）`, `uenter（进场）`, `anbc（开通贵族）`, `rnewbc（续费贵族）`, `blab（粉丝牌升级）`, `upgrade（等级升级）` |
| `--without TYPES` | Exclude specified message types (comma-separated), same candidate set as `--with` |

## Environment Variables

| Variable | Description |
|----------|-------------|
| `DYKIT_DSN` | PostgreSQL connection string |
| `DYCAP_DSN` | Alias for DYKIT_DSN |

## License

MIT
