Metadata-Version: 2.4
Name: slikemedia
Version: 0.1.3
Summary: Python SDK for publishing media on Slike platform
Project-URL: Homepage, https://github.com/yourusername/slikemedia
Project-URL: Documentation, https://github.com/yourusername/slikemedia#readme
Project-URL: Repository, https://github.com/yourusername/slikemedia
Project-URL: Issues, https://github.com/yourusername/slikemedia/issues
Author: Arpit Kumar
License-Expression: MIT
License-File: LICENSE
Keywords: api,media,publishing,sdk,slike
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.7
Requires-Dist: requests>=2.25.0
Requires-Dist: tomli>=1.2; python_version < '3.11'
Description-Content-Type: text/markdown

# slikemedia

Python SDK and CLI for uploading media to the [Slike](https://sli.ke) platform.

Supports **chunked file upload** (4 MiB chunks) and **publish-by-URL** (Google Drive, YouTube, direct links).

Requires Python 3.7+.

---

## Install

```bash
pip3 install slikemedia
```

---

## Quick Start

### 1. Create a config file

```bash
# Project-local (recommended)
cp config.example.toml config.toml

# Or global
mkdir -p ~/.slike && cp config.example.toml ~/.slike/config.toml
```

Edit it:

```toml
token       = "your-token-here"   # from Slike CMS → Settings → API Tokens
environment = "prod"              # "dev" or "prod"
```

The SDK checks `./config.toml` first, then `~/.slike/config.toml`.

### 2. Upload a file

```bash
slike-upload video.mp4 --title "My Video" --desc "Description"
```

### 3. Publish by URL

```bash
slike-upload --url https://drive.google.com/file/d/FILE_ID/view \
             --type gdrive --title "My Video" --desc "Description"
```

---

## Configuration

### Priority (highest wins)

1. CLI flags (`--token`, `--env`, `--config`)
2. Environment variables (`SLIKE_TOKEN`, `SLIKE_ENVIRONMENT`, `SLIKE_CONFIG`)
3. `./config.toml` (current directory), then `~/.slike/config.toml`

### Config file format

```toml
token       = "your-token-here"
environment = "prod"              # "dev" or "prod"
```

### Environment variables

| Variable            | Description                             |
|---------------------|-----------------------------------------|
| `SLIKE_TOKEN`       | Auth token                              |
| `SLIKE_ENVIRONMENT` | `dev` or `prod`                         |
| `SLIKE_CONFIG`      | Path to a specific config file          |

---

## CLI Reference

### Publish by URL

```
slike-upload --url <URL> --type <gdrive|youtube|url>
             --title "Title" --desc "Description"
             [--asset-type video|shorts]
             [--tags tag1,tag2]
             [--no-publish]
             [--token <token>] [--env dev|prod] [--config <path>]
```

| Flag           | Required | Description                                              |
|----------------|----------|----------------------------------------------------------|
| `--url`        | yes      | Media URL to ingest                                      |
| `--type`       | no       | `gdrive`, `youtube`, or `url` (default: `url`)           |
| `--title`      | yes      | Media title                                              |
| `--desc`       | yes      | Media description                                        |
| `--asset-type` | no       | Asset type, e.g. `video`, `shorts` (default: `video`)   |
| `--tags`       | no       | Comma-separated tags                                     |
| `--no-publish` | no       | Save as draft, skip auto-publish                         |
| `--token`      | no       | Auth token (overrides config)                            |
| `--env`        | no       | `dev` or `prod` (overrides config)                       |
| `--config`     | no       | Path to config file                                      |

**Examples:**

```bash
# Google Drive
slike-upload --url https://drive.google.com/file/d/FILE_ID/view \
             --type gdrive --title "My Video" --desc "Description"

# YouTube
slike-upload --url https://www.youtube.com/watch?v=VIDEO_ID \
             --type youtube --title "My Video" --desc "Desc"

# Save as draft
slike-upload --url https://example.com/video.mp4 --type url \
             --title "My Video" --desc "Desc" --no-publish
```

---

### Upload a local file

```
slike-upload <file>
             --title "Title" --desc "Description"
             [--asset-type video|shorts]
             [--tags tag1,tag2]
             [--payload '<JSON>']
             [--token <token>] [--env dev|prod] [--config <path>]
```

#### Using `--payload` JSON

Pass all metadata as a single JSON string instead of individual flags. CLI flags take precedence when both are given.

| Field           | Type         | Default       | Notes                              |
|-----------------|--------------|---------------|------------------------------------|
| `title`         | string       | required      |                                    |
| `desc`          | string       | required      |                                    |
| `asset_type`    | string       | `"video"`     | e.g. `"video"`, `"shorts"`         |
| `tags`          | list[string] | `null`        | e.g. `["news", "sports"]`          |
| `preset_config` | object       | `null`        | `{"meta": "...", "social": "..."}` |
| `downloads`     | object       | `null`        | `{"url": "https://..."}`           |
| `islive`        | int          | `0`           | `0` or `1`                         |
| `type`          | int          | `0`           | Media type integer                 |
| `source`        | string       | `"uploadsdk"` | Upload source identifier           |

**Examples:**

```bash
# Basic
slike-upload video.mp4 --title "My Video" --desc "Description"

# With tags and asset type
slike-upload video.mp4 --title "My Video" --desc "Desc" \
             --asset-type video --tags news,sports

# Via --payload JSON
slike-upload video.mp4 --payload '{"title":"My Video","desc":"Description"}'

# With preset_config
slike-upload video.mp4 --payload '{
  "title": "My Video",
  "desc": "Description",
  "asset_type": "video",
  "preset_config": {"meta": "preset-a", "social": "preset-b"},
  "tags": ["news", "sports"]
}'

# --title overrides the title inside --payload
slike-upload video.mp4 --title "Override" \
             --payload '{"title":"Ignored","desc":"Description"}'

# Dev environment
slike-upload video.mp4 --title "Test" --desc "Dev test" \
             --env dev --token mydevtoken
```

---

## Python SDK

### Publish by URL

```python
from slikemedia import PublishMediaOnSlike

result = PublishMediaOnSlike(
    url="https://drive.google.com/file/d/FILE_ID/view",
    title="My Video",
    description="Description",
    type="gdrive",              # gdrive | youtube | url
    token="your-token",
    environment="prod",         # optional, default: "prod"
    asset_type="video",         # optional
    tags=["news", "sports"],    # optional
    auto_publish=True,          # optional, default: True
)
print(result["result"]["id"])   # media ID
```

### One-call upload

```python
from slikeupload import UploadMediaOnSlike

result = UploadMediaOnSlike(
    file_path="/path/to/video.mp4",
    title="My Video",
    description="Description",
    token="your-token",
    environment="prod",                          # optional
    asset_type="video",                          # optional
    tags=["news", "sports"],                     # optional
    preset_config={"meta": "", "social": ""},   # optional
    on_progress=lambda done, total: print(f"{done}/{total} chunks"),
)
print(result["id"])  # media ID
```

### Two-step upload

```python
from slikeupload import RegisterMediaOnSlike, UploadChunksOnSlike

# Step 1: Register — get media ID before upload starts
result = RegisterMediaOnSlike(
    file_path="/path/to/video.mp4",
    title="My Video",
    description="Description",
    token="your-token",
    environment="prod",
    asset_type="video",
    tags=["news", "sports"],
    preset_config={"meta": "", "social": ""},
)
print(result["id"])   # media ID available immediately

# Step 2: Upload chunks
from slikeupload import UploadChunksOnSlike

UploadChunksOnSlike(
    file_path="/path/to/video.mp4",
    media_id=result["id"],
    upload_jwt=result["jwt"],
    environment="prod",
    on_progress=lambda done, total: print(f"{done}/{total} chunks"),
)
```

### Error handling

```python
from slikemedia import SlikeAPIError
from slikeupload import UploadMediaOnSlike

try:
    result = UploadMediaOnSlike(
        file_path="video.mp4",
        title="My Video",
        description="Description",
        token="your-token",
    )
except ValueError as e:
    print(f"Bad input: {e}")
except SlikeAPIError as e:
    print(f"API error: {e}")
```

---

## Environments

| Environment | RPC endpoint                 | Upload endpoint                   |
|-------------|------------------------------|-----------------------------------|
| `prod`      | `https://b2b.sli.ke/rpc`     | `https://asset.sli.ke/upload`     |
| `dev`       | `https://app-dev.sli.ke/rpc` | `https://asset-dev.sli.ke/upload` |

---

## How chunked upload works

1. `media.register` RPC → returns `media_id` + short-lived upload JWT
2. File is split into **4 MiB chunks**, each POSTed as `multipart/form-data` with the JWT in the `token` header
3. The asset server assembles and processes the file

Failed chunks are automatically retried up to **3 times** with exponential backoff.

---

## Development

```bash
git clone <repo>
cd slike-media-package
python3 -m pip install -e .

# Run tests
python3 -m pytest test_slikemedia.py -v

# Build wheel
pip install hatch && hatch build
```

---

## License

MIT
