﻿# Media server: dance_Content catalog API

## Deploy (WinSCP)

1. Upload this file to the media host:
   - Local: `server-media/api/videos.php`
   - Remote: `/var/www/html/server-media/api/videos.php`
   - Public URL: `http://HOST/server-media/api/videos.php`

2. Ensure video folders exist under:
   - `/var/www/html/dance_Content/video_NNN/video_NNN.mp4`
   - `/var/www/html/dance_Content/video_NNN/video_NNN.png`

3. PHP must be enabled for `/server-media/api/*.php` (nginx/apache).
   If the browser shows raw `<?php` source instead of JSON, PHP is not executing.
   Example nginx location:

```nginx
location ~ ^/server-media/api/.*\.php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/run/php/php-fpm.sock;  # adjust socket/version
}
```

4. Smoke-test in browser (must return JSON, not PHP source):
   - `http://185.7.212.199/server-media/api/videos.php`

## Contract

Only **immediate child directories** of `dance_Content` that contain **both** `{folder}.mp4` and `{folder}.png` are returned.
Incomplete folders, root-level files, hidden names (`.…`), and reserved names (`.git`, `.DS_Store`, `node_modules`, `api`, `deploy-tv`, `jd-addressable`, `videos`) are ignored.

`id` is taken from the trailing digits of the folder name (`video_001` → `1`). Duplicate ids are skipped. Results are sorted numerically by `id`.

Adding a new complete folder appears on the next TV catalog refresh with no app rebuild.

### Response format

Always JSON (never HTML/warnings). Responses use a success envelope:

**Success**

```json
{
  "success": true,
  "videos": [
    {
      "id": 1,
      "name": "video_001",
      "folder": "video_001",
      "videoUrl": "/dance_Content/video_001/video_001.mp4",
      "imageUrl": "/dance_Content/video_001/video_001.png"
    }
  ]
}
```

**Failure**

```json
{
  "success": false,
  "error": "dance_Content directory missing or unreadable"
}
```

Headers include `Access-Control-Allow-Origin: *` and `Cache-Control: no-store`.
