oeilsimple/Streamliner-AI
Streamliner-AI is a fully automated, asynchronous Python pipeline designed to monitor Kick streamers, detect viral high-energy moments, generate vertical clips optimized for social media, and publish them to TikTok without manual intervention.
Streamliner-AI ๐ค๐ฌ
Overview
Streamliner-AI is a fully automated, asynchronous Python pipeline designed to monitor Kick streamers, detect viral high-energy moments, generate vertical clips optimized for social media, and publish them to TikTok without manual intervention.
The system leverages the official Kick API with OAuth2 Client Credentials authentication for stable, efficient, and robust stream monitoring. It intelligently processes live streams in real-time or recorded VODs to identify highlights using audio energy analysis, speech-to-text transcription, and keyword detection.
Features
- Official API Authentication: Connects to Kick using OAuth2 Client Credentials flow for stable and authorized access
- Asynchronous Monitoring: Uses
asyncioandhttpxto monitor multiple streamers concurrently with a single process - Intelligent Detection System:
- Analyzes audio energy (RMS) to quickly identify emotional peaks
- Uses
faster-whisperto transcribe only high-energy segments, saving processing time - Customizable scoring system combining audio energy and 200+ keyword patterns
- Automatic Vertical Rendering: Uses
ffmpegto create 9:16 format clips with blurred backgrounds, centered original content, and burned-in subtitles - TikTok Publishing: Integrates with TikTok Content API for automatic clip uploads
- Robust CLI: Command-line interface built with
clickfor easy management - Production Ready: Includes Docker configuration, unit tests, and CI pipeline with GitHub Actions
- Real-time Processing: Supports both live stream chunk processing and full VOD analysis
- Flexible Storage: Supports local filesystem and S3-compatible storage (AWS S3, Cloudflare R2)
Technology Stack
Core Technologies
- Python 3.10+ (developed and tested with Python 3.13.3)
- asyncio - Asynchronous I/O for concurrent stream monitoring
- httpx - Modern async HTTP client with HTTP/2 support
Media Processing
- FFmpeg - Video/audio processing, cutting, and rendering
- Streamlink - Stream extraction and downloading
- faster-whisper - Efficient speech-to-text transcription
- soundfile & scipy - Audio analysis and processing
- scenedetect - Scene change detection for highlight optimization
AI/ML
- PyTorch - Deep learning framework for Whisper model
- faster-whisper - Optimized Whisper implementation
APIs & Integration
- Kick API - OAuth2 authentication and stream monitoring
- TikTok Content API - Automated video publishing
Development & Testing
- pytest - Unit testing framework
- ruff - Fast Python linter and formatter
- Docker - Containerization for deployment
- GitHub Actions - Continuous Integration pipeline
Configuration & Logging
- python-dotenv - Environment variable management
- PyYAML - Configuration file parsing
- loguru - Advanced logging with structured output
- click - CLI framework
Project Structure
streamliner-ai/
โโโ .github/
โ โโโ workflows/
โ โโโ ci.yml # CI/CD pipeline configuration
โโโ assets/
โ โโโ architecture-diagram.png
โ โโโ logo.png
โโโ scripts/
โ โโโ generate_tiktok_tokens.py # TikTok OAuth token generator
โโโ src/
โ โโโ streamliner/
โ โโโ __init__.py
โ โโโ cli.py # Command-line interface
โ โโโ config.py # Configuration management
โ โโโ cutter.py # Video cutting utilities
โ โโโ detector.py # Highlight detection engine
โ โโโ downloader.py # Stream/VOD downloader
โ โโโ monitor.py # Stream monitoring system
โ โโโ pipeline.py # Main processing pipeline
โ โโโ render.py # Video rendering engine
โ โโโ stt.py # Speech-to-text transcription
โ โโโ worker.py # Real-time chunk processor
โ โโโ publisher/
โ โ โโโ __init__.py
โ โ โโโ tiktok.py # TikTok API integration
โ โโโ storage/
โ โโโ __init__.py
โ โโโ base.py # Storage interface
โ โโโ local.py # Local filesystem storage
โ โโโ s3.py # S3-compatible storage
โโโ tests/
โ โโโ test_cutter.py
โ โโโ test_detector.py
โ โโโ test_worker_cleanup.py
โโโ .env.template # Environment variables template
โโโ .gitignore
โโโ config.yaml.example # Configuration template
โโโ docker-composer.yml # Docker Compose configuration
โโโ Dockerfile # Docker image definition
โโโ pyproject.toml # Python project metadata
โโโ README.md
โโโ requirements.txt # Python dependencies
Key Components
- cli.py: Entry point for all commands (monitor, process, upload)
- monitor.py: Manages real-time stream monitoring and chunk recording
- detector.py: Analyzes audio and transcripts to identify highlights
- pipeline.py: Orchestrates the complete processing workflow
- worker.py: Handles real-time chunk processing and buffering
- render.py: Creates vertical format videos with subtitles
- publisher/tiktok.py: Handles TikTok API authentication and uploads
- storage/: Abstraction layer for local and cloud storage
Architecture
The system operates as a stable pipeline using official Kick authentication to ensure reliable data access.
Workflow
- Monitor: Continuously checks configured streamers' status via Kick API
- Record: When live, records stream in chunks using FFmpeg
- Detect: Analyzes audio energy (RMS) to find emotional peaks
- Transcribe: Uses Whisper to transcribe only high-energy segments
- Score: Combines audio energy and keyword matching to rank moments
- Cut: Extracts highlight clips from the stream
- Render: Creates vertical format with subtitles and branding
- Publish: Uploads to TikTok automatically
Quick Start
Prerequisites
Before installing Python dependencies, ensure you have:
- Python 3.10 or higher (download from python.org)
- FFmpeg (CRITICAL - required for all video/audio processing)
Installing FFmpeg
Windows:
- Download from ffmpeg.org/download.html
- Extract to a location (e.g.,
C:\ffmpeg) - Add the
binfolder to your PATH environment variable (e.g.,C:\ffmpeg\bin) - Verify: Open a new terminal and run
ffmpeg -version
macOS (using Homebrew):
brew install ffmpegLinux (Debian/Ubuntu):
sudo apt update
sudo apt install ffmpegInstallation
# 1. Clone the repository
git clone https://github.com/your-username/streamliner-ai.git
cd streamliner-ai
# 2. Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows PowerShell:
.\venv\Scripts\Activate
# Linux/macOS:
source venv/bin/activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure environment
cp .env.template .env
cp config.yaml.example config.yaml
# Edit .env and config.yaml with your credentials
# 5. Test with a local video
python -m src.streamliner.cli process "data/video.mp4" --streamer "test" --dry-run
# 6. Start monitoring
python -m src.streamliner.cli monitorConfiguration
Kick API Setup
- Create an application at Kick Developer Portal
- Set Redirect URL to
http://localhost(required but not used) - Select scopes:
channel:read,user:read - Copy your
Client IDandClient Secret - Add credentials to
.env:
KICK_CLIENT_ID="your_client_id"
KICK_CLIENT_SECRET="your_client_secret"TikTok API Setup
- Register your application at TikTok Developer Center
- Configure a valid Redirect URI (e.g.,
https://www.example.com/oauth) - Add credentials to
.env:
TIKTOK_CLIENT_KEY=your_client_key
TIKTOK_CLIENT_SECRET=your_client_secret
TIKTOK_ENVIRONMENT=sandbox # or 'production'- Generate initial tokens:
python scripts/generate_tiktok_tokens.pyFollow the prompts to authorize the application and paste the authorization code.
Application Configuration
Edit config.yaml to customize:
- streamers: List of Kick usernames to monitor
- detection: Highlight detection parameters (thresholds, keywords, scoring weights)
- transcription: Whisper model settings (model size, device, compute type)
- rendering: Video rendering options (logo, subtitle style, fonts)
- publishing: TikTok upload strategy and description template
Usage
Monitor Mode (Production)
Continuously monitors configured streamers and processes highlights automatically:
python -m src.streamliner.cli monitorPress Ctrl+C to stop gracefully.
Process VOD (Testing)
Process a downloaded video file or URL:
# Process local file
python -m src.streamliner.cli process "path/to/video.mp4" --streamer "streamer_name" --dry-run
# Process from URL
python -m src.streamliner.cli process "https://kick.com/video/..." --streamer "streamer_name"Upload Clip
Upload a pre-rendered clip to TikTok:
python -m src.streamliner.cli upload \
--file "data/clips/my_clip_rendered.mp4" \
--streamer "test" \
--strategy MULTIPARTTikTok Diagnostics
Check sandbox state and backoff status:
# View current state
python -m src.streamliner.cli tiktok-diagnose
# Clear sandbox state
python -m src.streamliner.cli tiktok-clear-sandbox-state
# Upload with automatic backoff handling
python -m src.streamliner.cli upload-when-ready \
--file "data/clips/my_clip.mp4" \
--streamer "test" \
--max-wait-seconds 2400Docker Deployment
Docker simplifies deployment by packaging the application with all dependencies including FFmpeg:
# Build the image
docker-compose build
# Start the service
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the service
docker-compose downDevelopment
VS Code Setup
Create .vscode/settings.json for automatic formatting:
{
"python.defaultInterpreterPath": "${workspaceFolder}/venv/bin/python",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
}
}
}Code Quality
# Check for errors
ruff check .
# Format code
ruff format .Testing
# Run all tests
pytest
# Run specific test file
pytest tests/test_detector.py
# Run with coverage
pytest --cov=src/streamlinerTechnical Deep Dive
Async-First Architecture
The choice of asyncio enables handling multiple I/O operations (API calls, downloads, uploads) concurrently in a single thread, which is far more resource-efficient than traditional thread-based approaches.
- Non-blocking Subprocesses: Uses
asyncio.create_subprocess_execfor FFmpeg and Streamlink, allowing the main program to continue while external processes run - Concurrent Monitoring: Single process monitors multiple streamers simultaneously
- Efficient Resource Usage: Minimal CPU overhead during I/O-bound operations
Optimized Detection
The decision not to transcribe the entire VOD is the system's most important optimization:
- RMS Energy Analysis: Computationally cheap, acts as a high-speed filter
- Selective Transcription: Only processes "interesting" audio segments with Whisper
- Keyword Scoring: Combines audio energy with 200+ contextual keywords
- Scene Detection: Bonus scoring for highlights coinciding with scene changes
This approach reduces hours of VOD to minutes of processing time.
OAuth2 Implementation
The project evolved from initial attempts using unofficial endpoints (blocked by Cloudflare) to the official OAuth2 Client Credentials flow:
- Requests an App Access Token from
https://id.kick.com/oauth/token - Stores token in memory and refreshes automatically before expiration
- Uses token for authenticated calls to
/public/v1/channels
This approach is more stable, lightweight, and respectful of the platform.
Future Improvements
- Advanced Token Management: Persist access tokens to Redis or database for state preservation across restarts
- Real-time Processing Enhancement: Redesign downloader to work with video chunks for near-instant clip creation
- Metrics Dashboard: Integrate Prometheus and Grafana for monitoring and visualization
- Machine Learning Scoring: Train advanced models analyzing chat velocity and game events
- Multi-platform Support: Abstract modules to support Twitch, YouTube, and other platforms
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
This project represents an intensive development journey from initial concept to a robust, functional solution. The development process involved exploring different architectures and solving complex technical challenges, including bypassing anti-bot protections and ultimately implementing the official Kick API.
