# AnyClip Integration

Tools for integrating with AnyClip's Video Manager API.

## Setup

```bash
cp .env.example .env
# Edit .env with your AnyClip credentials
bun install
```

## Project Structure

```
├── anyclip/              # Extracted source code (from sourcemaps)
├── docs/                 # Documentation
├── scripts/              # CLI tools
├── sourcemaps/           # Raw .map files (gitignored)
└── urls.txt              # JS file URLs to download
```

## Scripts

### Authentication

```bash
# Login and save session to session.json
bun scripts/auth.ts
```

Programmatic usage:

```typescript
import { login, getAuthHeaders } from './scripts/auth';

const session = await login(email, password);
const headers = getAuthHeaders(session);
// session.cookies contains both required cookies
```

See [docs/auth.md](docs/auth.md) for details on the two-step auth flow.

### Source Extraction

Extract AnyClip's frontend source from public sourcemaps:

```bash
# 1. Update urls.txt from build manifest
bun scripts/update-urls.ts

# 2. Download sourcemaps for all URLs
bun scripts/download-sourcemaps.ts

# 3. Extract source files to anyclip/
bun scripts/extract-sources.ts
```

Or run all three:

```bash
bun scripts/update-urls.ts && bun scripts/download-sourcemaps.ts && bun scripts/extract-sources.ts
```

### Script Options

**extract-sources.ts:**
```bash
bun scripts/extract-sources.ts [options]
  --output, -o <dir>   Output directory (default: anyclip)
  --input, -i <dir>    Sourcemaps directory (default: sourcemaps)
  --verbose, -v        Verbose output
  --no-clean           Don't delete output directory first
```

## Documentation

- [docs/auth.md](docs/auth.md) - Authentication system (two-step flow, cookies, encryption)
