# Strapi Plugin: YouTube Transcript

Fetch and generate transcripts from YouTube videos. Store them as content types and expose via REST API.

## Installation

```bash
npm install strapi-plugin-youtube-transcript
```

Then enable in `config/plugins.ts`:

```ts
export default {
  'youtube-transcript': { enabled: true },
};
```

## Authentication

| Endpoint | Auth required |
|----------|--------------|
| `POST /fetch-transcript` | ✅ Yes — Bearer token or session |
| `GET /transcripts` | ❌ Public |
| `GET /transcripts/:id` | ❌ Public |
| `DELETE /transcripts/:id` | ✅ Yes — Bearer token or session |

To call authenticated endpoints, pass your Strapi API token:

```bash
curl -H "Authorization: Bearer <YOUR_API_TOKEN>" ...
```

## API Reference

### Fetch and save a transcript

```http
POST /api/youtube-transcript/fetch-transcript
Authorization: Bearer <YOUR_API_TOKEN>
Content-Type: application/json

{ "videoUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" }
```

Response:
```json
{ "data": { "documentId": "...", "videoId": "dQw4w9WgXcQ", ... }, "created": true }
```

> If the transcript already exists, it is updated and `created` is `false`.

### List all transcripts

```http
GET /api/youtube-transcript/transcripts
```

### Get transcript by ID

```http
GET /api/youtube-transcript/transcripts/:id
```

### Delete transcript

```http
DELETE /api/youtube-transcript/transcripts/:id
Authorization: Bearer <YOUR_API_TOKEN>
```

## Content Type Schema

| Field | Type | Description |
|-------|------|-------------|
| `videoId` | string (unique) | YouTube video ID (e.g. `dQw4w9WgXcQ`) |
| `videoUrl` | string (unique) | Full YouTube URL |
| `transcript` | richtext | Full transcript text |
| `language` | string | Language code (e.g. `en`) |
| `segments` | json | Timestamped transcript segments `[{ text, start, duration }]` |

## Local Development

Clone this repo. The project contains the plugin and a playground Strapi app.

```bash
# 1. Build the plugin
cd plugins/strapi-plugin-youtube-transcript
npm install

# 2. Run the playground
cd ../../playground
npm install
npm run develop
```

## License

MIT
