Metadata-Version: 2.4
Name: streamvault-core-kaustubh
Version: 0.1.0
Summary: Core serverless video transcoding and API backend for StreamVault.
Home-page: https://github.com/Kaustubhd1314/streamvault-core
Author: Kaustubh D.
Author-email: kaustubhd1314@gmail.com
Project-URL: Bug Tracker, https://github.com/Kaustubhd1314/streamvault-core/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: boto3>=1.26.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# StreamVault Core SDK

`streamvault-core-kaustubh` is a serverless Python SDK that simplifies building event-driven AWS video streaming pipelines. It provides pre-built logic for FFmpeg MPEG-DASH transcoding, DynamoDB job tracking, and a RESTful backend with Role-Based Access Control (RBAC).

## 🚀 Installation

Install the library directly from PyPI (once published):

```bash
pip install streamvault-core-kaustubh
```

## 🏗️ Prerequisites
To use this SDK in AWS Lambda, your architecture requires:
1. **Source S3 Bucket:** Where raw MP4s are uploaded.
2. **Distribution S3 Bucket:** Where `.mpd` and `.m4s` segments are stored.
3. **DynamoDB Table:** A single-table design for tracking users and transcoding jobs (Partition Key: `PK`, string).
4. **FFmpeg Lambda Layer:** An AWS Lambda Layer providing the `ffmpeg` binary at `/opt/python/bin/ffmpeg`.

---

## 🎬 1. Video Transcoder Implementation

Create an AWS Lambda function triggered by **S3 ObjectCreated** events on your Source bucket. 
This function uses the `process_video_s3_trigger` wrapper to automatically download the video, transcode it to MPEG-DASH, push to the Distribution bucket, and send an SNS alert!

```python
# lambda_function.py
import streamvault

import os

def lambda_handler(event, context):
    # Retrieve required environment variables
    table_name = os.environ["DYNAMODB_TABLE_NAME"]
    output_bucket = os.environ["OUTPUT_BUCKET"]
    sns_topic = os.environ.get("SNS_TOPIC_ARN", None)
    
    # 💥 StreamVault Magic
    streamvault.process_video_s3_trigger(
        event=event,
        table_name=table_name,
        output_bucket=output_bucket,
        sns_topic_arn=sns_topic
    )
    
    return {
        "statusCode": 200,
        "body": "Transcoding workflow triggered successfully!"
    }
```

---

## 🛡️ 2. API Gateway & User Registration Implementation

Create a second AWS Lambda function strictly for handling API Gateway requests. 
This function provides instant backend routes for: user registration, logging in, role-based video retrieval, video deletion, and group access assignments.

```python
# api_lambda_function.py
import streamvault
import os

def lambda_handler(event, context):
    # Retrieve required environment variables
    table_name = os.environ["DYNAMODB_TABLE_NAME"]
    source_bucket = os.environ["SOURCE_BUCKET"]
    
    # 💥 StreamVault Magic
    return streamvault.handle_api_request(
        event=event,
        table_name=table_name,
        source_bucket=source_bucket
    )
```

### Supported API Routes:
If your API Gateway endpoint is `https://api.example.com`, you instantly have access to:

* `GET ?action=jobs` - Retrieve all background transcoding job statuses (Admin).
* `GET ?action=videos&group=[Group]` - Retrieve successfully transcoded videos the user has access to.
* `POST ?action=signup&username=[User]&password=[Pass]&group=[Plan]` - Register a new user in the DB.
* `GET ?action=login&username=[User]&password=[Pass]` - Returns profile information and group tier.
* `GET ?action=upload-url&filename=[Name.mp4]` - Generates an S3 Pre-signed URL for direct uploads.
* `DELETE ?action=delete&id=[JobID]` - Completely purges a video from S3 and DynamoDB.
* `POST ?action=update_access&id=[JobID]&group=[Plan]` - Locks video access to a specific subscription tier.

## 🤝 Contributing
Pull requests are welcome! If you encounter issues setting up the AWS resources or FFmpeg Lambda Layer, please submit an issue to the bug tracker.
