Metadata-Version: 2.4
Name: scene-otsu
Version: 0.1.5
Summary: SRT subtitle scene splitter using Otsu method with OpenAI embeddings
Project-URL: Homepage, https://github.com/yukiharada1228/scene-otsu
Project-URL: Documentation, https://github.com/yukiharada1228/scene-otsu#readme
Project-URL: Repository, https://github.com/yukiharada1228/scene-otsu
Project-URL: Issues, https://github.com/yukiharada1228/scene-otsu/issues
Author-email: Yuki Harada <yukiharada1228@gmail.com>
License: MIT
Keywords: embeddings,openai,otsu,scene-split,srt,subtitle
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.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Video
Classifier: Topic :: Text Processing :: Markup
Requires-Python: >=3.11
Requires-Dist: numpy>=2.3.5
Requires-Dist: openai>=2.8.1
Requires-Dist: scikit-learn>=1.7.2
Requires-Dist: tiktoken>=0.12.0
Requires-Dist: tqdm>=4.67.1
Provides-Extra: dev
Requires-Dist: black>=25.11.0; extra == 'dev'
Requires-Dist: isort>=7.0.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Description-Content-Type: text/markdown

# scene-otsu

A Python library for scene splitting SRT subtitle files using the Otsu method. Uses OpenAI's embedding models to find semantically appropriate scene boundaries.

## Features

- **SRT Subtitle Parsing**: Parse SRT format subtitle files
- **Otsu Method Scene Splitting**: Recursively apply multi-dimensional Otsu method to detect semantically appropriate scene boundaries
- **OpenAI Embeddings**: Use OpenAI's embedding models to calculate semantic similarity of text
- **Token Limit Support**: Split scenes based on specified maximum token count

## Installation

```bash
pip install scene-otsu
```

## Usage

### Basic Example

```python
from scene_otsu import SceneSplitter

# Set OpenAI API key
api_key = "your-openai-api-key"

# Initialize SceneSplitter
splitter = SceneSplitter(api_key=api_key)

# Process SRT string
srt_content = """
1
00:00:00,000 --> 00:00:05,000
Hello, welcome to this video.

2
00:00:05,000 --> 00:00:10,000
Today we will discuss machine learning.

3
00:00:10,000 --> 00:00:15,000
Let's start with the basics.
"""

# Execute scene splitting (max 200 tokens)
result = splitter.process(srt_content, max_tokens=200)
print(result)
```

### Using SubtitleParser

```python
from scene_otsu import SubtitleParser

# Parse SRT string
srt_content = """
1
00:00:00,000 --> 00:00:05,000
First subtitle

2
00:00:05,000 --> 00:00:10,000
Second subtitle
"""

# Basic parsing
subtitles = SubtitleParser.parse_srt_string(srt_content)
# Returns: [("00:00:00,000", "00:00:05,000", "First subtitle"), ...]

# Parse as scene information
scenes = SubtitleParser.parse_srt_scenes(srt_content)
# Returns: [{"index": 1, "start_time": "00:00:00,000", "end_time": "00:00:05,000", ...}, ...]
```

## API Reference

### SceneSplitter

#### `__init__(api_key: str, model: str = "text-embedding-3-small", batch_size: int = 16)`

Initialize SceneSplitter.

**Parameters:**
- `api_key`: OpenAI API key
- `model`: OpenAI embedding model to use (default: "text-embedding-3-small")
- `batch_size`: Batch size for embedding generation (default: 16)

#### `process(srt_string: str, max_tokens: int = 200) -> str`

Process SRT string and return scene-split SRT string.

**Parameters:**
- `srt_string`: Input SRT string
- `max_tokens`: Maximum tokens per chunk (default: 200)

**Returns:**
- Scene-split SRT string

### SubtitleParser

#### `parse_srt_string(srt_string: str) -> List[Tuple[str, str, str]]`

Parse SRT string.

**Returns:**
- List in the format `[(start_timestamp, end_timestamp, text), ...]`

#### `parse_srt_scenes(srt_string: str) -> List[Dict[str, Any]]`

Convert SRT to scene-based dictionary.

**Returns:**
- List in the format `[{index, start_time, end_time, start_sec, end_sec, text}]`

#### `parse_timestamp(timestamp: str) -> float`

Convert timestamp string to seconds.

**Parameters:**
- `timestamp`: Timestamp string (e.g., "00:00:05,000")

**Returns:**
- Seconds (float, including milliseconds)

## Requirements

- Python 3.11 or higher
- OpenAI API key

## Dependencies

- numpy >= 2.3.5
- openai >= 2.8.1
- scikit-learn >= 1.7.2
- tiktoken >= 0.12.0
- tqdm >= 4.67.1

## License

MIT License

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## Author

Yuki Harada
