A TUI tool for organizing video files, converting VTT subtitles to SRT format, and translating SRT files using Google Gemini AI.
Project description
Video File Organizer with AI Translation
A TUI video file organizer with Google Gemini AI-powered translation capabilities for SRT subtitle files. This tool helps you organize your video files and translate subtitle files to any supported language with AI translation.
Features
Core Features
- File Organization: Organize video files by language and format
- VTT to SRT Conversion: Convert WebVTT subtitle files to SRT format
- Interactive TUI: Beautiful terminal user interface with Rich library
AI Translation Features ✨
- SRT Translation: Translate subtitle files using Google Gemini AI
- Batch Translation: Translate multiple SRT files simultaneously
- Smart Language Detection: Automatically detect source language from filenames
- Concurrent Processing: Fast translation with concurrent batch processing
- Error Handling: Robust retry logic with exponential backoff
- Progress Tracking: Real-time progress indication with detailed statistics
- 20+ Language Support: Support for major world languages
Project Structure
.
├── LICENSE
├── README.md
├── pyproject.toml
├── poetry.lock
└── src
├── __init__.py
├── main.py
└── nichi
├── __init__.py
├── config/
│ ├── __init__.py
│ └── config_manager.py
├── core/
│ ├── __init__.py
│ ├── converter.py
│ ├── organizer.py
│ ├── operations.py
│ ├── srt_parser.py
│ ├── timing_adjuster.py
│ └── translator.py
├── exceptions/
│ └── __init__.py
├── models/
│ └── __init__.py
├── services/
│ ├── __init__.py
│ ├── gemini_translator.py
│ └── jellyfin_parser.py
└── ui/
├── __init__.py
├── tui.py
├── ui_components.py
└── user_input.py
Installation
Via PyPI (Recommended)
pip install nichi
From Source
1. Install Dependencies
This project now uses Poetry for dependency management. If you don't have Poetry installed, you can install it by following the official instructions.
# Install dependencies with Poetry
poetry install
2. Set up Google AI API Key
- Visit Google AI Studio
- Create a new API key for Google Gemini
- Create a
.envfile in your project root:
# Copy the example file
cp .env.example .env
# Edit .env and add your configuration
GOOGLE_AI_API_KEY=your_actual_api_key_here
GEMINI_MODEL_NAME=gemini-2.0-flash-exp
3. Install the Package
# Activate the Poetry shell and run the application directly
poetry shell
python src/main.py
# Or run without activating the shell
poetry run python src/main.py
# To install in development mode
poetry install
# To build and install the package
poetry build
pip install dist/*.whl
Usage
Running the Application
# Run from current directory
python src/main.py
# Or if installed as package
nichi
# Show environment variables
python src/main.py --env
Menu Options
- Convert VTT files to SRT format - Convert WebVTT subtitle files to SRT format
- Organize MP4 and subtitle files into folders - Group video files with their corresponding subtitle files
- Convert VTT files and then organize - Perform both conversion and organization in sequence
- Show current directory contents - Display the files in the current working directory
- Change working directory - Navigate to a different directory
- Translate SRT file to another language - Translate a single SRT file using Google Gemini AI
- Show available languages for translation - Display all supported languages for translation
- Adjust subtitle timing - Shift subtitle timing forward or backward
- Compare two Subtitle files - Use git difftool to compare two SRT files
- Manage translation cache - View and clear the translation cache
- Show environment variables - Display relevant environment variables
- Exit - Close the application
Translation Features
The AI translation system offers:
- Fast Processing: Concurrent batch processing with configurable batch sizes (default: 200 entries)
- Smart Retry: Automatic retry with exponential backoff for failed requests
- Progress Tracking: Real-time progress bars with success/failure statistics
- Language Auto-detection: Automatically detects source language from filenames
- Terminal User Interface: Beautiful TUI with Rich library
Supported Languages
| Code | Language | Code | Language | Code | Language |
|---|---|---|---|---|---|
| en | English | es | Spanish | fr | French |
| de | German | it | Italian | pt | Portuguese |
| ru | Russian | ja | Japanese | ko | Korean |
| zh | Chinese | ar | Arabic | hi | Hindi |
| th | Thai | vi | Vietnamese | nl | Dutch |
| sv | Swedish | da | Danish | no | Norwegian |
| fi | Finnish | pl | Polish | tr | Turkish |
Configuration
Environment Variables
Create a .env file with:
# Required Configuration
GOOGLE_AI_API_KEY=your_google_ai_api_key_here
GEMINI_MODEL_NAME=gemini-2.0-flash-exp
# Optional Configuration
# GOOGLE_AI_PROJECT_ID=your_project_id_here
# TRANSLATION_BATCH_SIZE=10
# DEFAULT_TARGET_LANGUAGE=id
# Optional Configuration (Gemini)
# GEMINI_MAX_RETRIES=3
# GEMINI_BASE_DELAY=1
# GEMINI_MAX_DELAY=60
Performance
The translation system is optimized for speed:
- Large Batches: Processes 200 subtitle entries per batch by default
- Concurrent Processing: Handles up to 5 batches simultaneously
- Smart Retry: Exponential backoff prevents API rate limiting
- Progress Tracking: Real-time feedback on translation progress
Troubleshooting
Translation Not Available
If translation features are unavailable:
- Check API Key: Ensure
.envfile exists with validGOOGLE_AI_API_KEY - Verify Installation: Run
pip list | grep google-generativeai - Test Connection: Check internet connectivity
- API Quota: Verify your Google AI API has remaining quota
Common Issues
Encoding Errors: The translator automatically handles UTF-8, Latin-1, and CP1252 encodings Rate Limiting: The system includes automatic retry with exponential backoff Large Files: For very large subtitle files, the system automatically splits them into manageable batches
Security
- Keep your
.envfile secure and never commit it to version control - Add
.envto your.gitignorefile - API keys are only used for Google Gemini translation requests
- No subtitle content is stored or logged
Development
Code Structure
The project follows a clean architecture pattern:
config/- Configuration managementcore/- Business logic and core functionalityexceptions/- Custom exception classesmodels/- Data models and structuresservices/- External service integrationsui/- User interface components
Code Quality
- Type hints for all functions and classes
- Comprehensive docstrings for all public interfaces
- Consistent naming conventions
- Modular design with clear separation of concerns
Running Tests
# Run tests with Poetry
poetry run pytest
Code Formatting
# Format code with black
poetry run black src/
# Sort imports with isort
poetry run isort src/
Managing Dependencies
# Add a new dependency
poetry add package_name
# Add a new development dependency
poetry add --group dev package_name
# Update dependencies
poetry update
# Export dependencies to requirements.txt (if needed)
poetry export -o requirements.txt -f requirements.txt --without-hashes
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nichi-2.0.6.tar.gz.
File metadata
- Download URL: nichi-2.0.6.tar.gz
- Upload date:
- Size: 33.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db280b4efe4deb19614cb042c1c48f72abf7a10e0de8a0e0bd7ebaec1260578f
|
|
| MD5 |
ab0791804559ea6949c2f37aeba9058e
|
|
| BLAKE2b-256 |
d714a6dec65cd8e4657790166b5b76d72e547178046534bc0982a8b8205354eb
|
File details
Details for the file nichi-2.0.6-py3-none-any.whl.
File metadata
- Download URL: nichi-2.0.6-py3-none-any.whl
- Upload date:
- Size: 41.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6524d3680b835dedd4aca662a564ed336360bf701a2daa6dd982de3335575e5d
|
|
| MD5 |
db5e2136ddd9c2427738e4af1c08c97c
|
|
| BLAKE2b-256 |
92ee1df9e607392eaf2585c77c661e6b53a0e14e6a3842ef772d2a3f7df81f40
|