# Deploying Emby Server with SAMI-CLOUD Dashboard

Quick guide to deploy Emby media server using the SAMI-CLOUD Status Dashboard.

## Prerequisites

1. Emby Server installed somewhere (Docker, Windows, Linux, etc.)
2. SAMI-CLOUD API server running (`node caddy-api.js`)
3. Know the IP and port where Emby is running

## Option 1: Deploy Existing Emby Server

If you already have Emby running somewhere, use the dashboard to add it:

### Step 1: Gather Information

You'll need:
- **IP Address**: Where Emby is running (e.g., `192.168.254.100`)
- **Port**: Emby's HTTP port (default: `8096`)

### Step 2: Deploy via Dashboard

1. Open the dashboard: `https://status.sami`
2. Click **"📱 App Selector"** button
3. Find **Emby** under the **Media** category
4. Fill in the deployment form:
   ```
   Subdomain: emby
   IP Address: 192.168.254.100
   Port: 8096
   DNS Type: Private DNS (creates DNS record)
   SSL Type: Internal CA (local network)
   ```
5. Click **"Deploy App"**

### Step 3: Access Emby

Your Emby server will be accessible at:
```
https://emby.sami
```

## Option 2: Deploy Emby in Docker

If you don't have Emby yet, here's how to deploy it with Docker:

### Using Docker Compose

Create `docker-compose.yml`:

```yaml
version: '3'
services:
  emby:
    image: lscr.io/linuxserver/emby:latest
    container_name: emby
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
    volumes:
      - ./config:/config
      - /path/to/media:/data/media
      - /path/to/movies:/data/movies
      - /path/to/tvshows:/data/tvshows
    ports:
      - "8096:8096"
    restart: unless-stopped
```

Then:
```bash
docker-compose up -d
```

### Using Docker CLI

```bash
docker run -d \
  --name=emby \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=America/New_York \
  -p 8096:8096 \
  -v /path/to/config:/config \
  -v /path/to/media:/data/media \
  --restart unless-stopped \
  lscr.io/linuxserver/emby:latest
```

### After Docker Deployment

1. Verify Emby is running: `docker ps`
2. Test access: `curl http://localhost:8096`
3. Use the Dashboard App Selector to add reverse proxy:
   - IP: `localhost` or `172.17.0.1` (Docker bridge)
   - Port: `8096`

## Option 3: Install Emby Directly

### Windows

1. Download Emby Server: https://emby.media/download.html
2. Install and run setup wizard
3. Note the IP and port (default: `8096`)
4. Use Dashboard App Selector to add it

### Linux

```bash
# Ubuntu/Debian
wget https://github.com/MediaBrowser/Emby.Releases/releases/download/4.8.0.62/emby-server-deb_4.8.0.62_amd64.deb
sudo dpkg -i emby-server-deb_4.8.0.62_amd64.deb

# Start service
sudo systemctl start emby-server
sudo systemctl enable emby-server
```

Then add to dashboard with IP and port `8096`.

## Emby Initial Setup

After deploying, complete Emby's setup wizard:

1. Open `https://emby.sami`
2. Choose your language
3. Create admin account
4. Add media libraries (Movies, TV Shows, Music, etc.)
5. Configure metadata providers
6. Set up remote access (if needed)

## Troubleshooting

### Can't access Emby through reverse proxy

Check that Emby allows the proxy:

1. Open Emby Settings → Network
2. Add to **"Allow remote connections from"**:
   - Your Caddy server IP
   - `127.0.0.1`
3. Ensure **"Enable automatic port mapping"** is off (not needed with reverse proxy)

### Certificate errors

If using Internal CA:
- Ensure you've installed the Caddy root certificate on your devices
- Export from: `https://dns1.sami/config/pki/ca/local/download`

### Performance issues

If streaming is slow:
1. Check network bandwidth
2. Enable hardware transcoding in Emby (Settings → Transcoding)
3. Adjust quality settings in Emby clients

### DNS not resolving

If `emby.sami` doesn't resolve:
```bash
# Test DNS
nslookup emby.sami dns1.sami

# Add manually if needed
# Windows: C:\Windows\System32\drivers\etc\hosts
# Linux/Mac: /etc/hosts
192.168.254.100  emby.sami
```

## Updating Emby Logo

The dashboard now has the official Emby logo. If you want to customize it:

1. Replace: `e:\CaddyCerts\sites\status\assets\emby.png`
2. Copy to production: `C:\caddy\sites\status\assets\emby.png`
3. Clear browser cache

## Advanced: Emby with Custom Settings

You can configure additional Caddy settings for Emby:

```caddyfile
emby.sami {
  tls internal

  # Increase timeouts for long transcoding operations
  reverse_proxy http://192.168.254.100:8096 {
    flush_interval -1

    transport http {
      dial_timeout 30s
      response_header_timeout 0
      read_timeout 0
    }
  }
}
```

## Next Steps

After Emby is deployed:

1. **Add Media Libraries** - Configure your movies, TV shows, music
2. **Install Plugins** - Trailers, Trakt, Theme Songs, etc.
3. **Setup Users** - Create accounts for family members
4. **Configure Clients** - Install Emby apps on phones, TVs, streaming devices
5. **Enable Live TV** - If you have TV tuners or IPTV

## Comparing Emby vs Plex vs Jellyfin

| Feature | Emby | Plex | Jellyfin |
|---------|------|------|----------|
| Free features | Most | Some | All |
| Hardware transcoding | Premiere only | Pass only | Free |
| Open source | No | No | Yes |
| Mobile apps | Paid | Free | Free |
| Best for | Power users | Everyone | Self-hosters |

## Resources

- Emby Documentation: https://support.emby.media/
- Emby Forums: https://emby.media/community/
- Docker Hub: https://hub.docker.com/r/emby/embyserver
- LinuxServer.io: https://docs.linuxserver.io/images/docker-emby/

## License

Emby has both free and Premiere (paid) versions. Some features require Emby Premiere subscription.
