Skip to main content

Pure-Python MKV subtitle extractor

Project description

py_subtitle_extractor

PyPI version Python versions License

Pure-Python MKV subtitle extractor library
Zero external dependencies, single-pass streaming, supports raw and SRT output.


🚀 Features

  • extract_subtitle_tracks(path) → List of subtitle-track metadata (track number, codec, language, name)
  • extract_subtitles(path, track) → List of (timestamp_ms, text) tuples
  • extract_subtitles_as_srt(path, track) → Complete SRT file as a string

📦 Installation

From PyPI

pip install py_subtitle_extractor

From source

git clone https://github.com/re999/py_subtitle_extractor.git
cd py_subtitle_extractor
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip build
pip install .

🛠️ Usage

from py_subtitle_extractor import (
    extract_subtitle_tracks,
    extract_subtitles,
    extract_subtitles_as_srt,
)

# List available subtitle tracks
tracks = extract_subtitle_tracks("movie.mkv")
for t in tracks:
    print(f"Track #{t['track_number']}: {t['codec_id']} [{t['language']}] – {t['name']}")

# Extract raw entries from track #3
entries = extract_subtitles("movie.mkv", 3)
for ts, text in entries:
    print(ts, text)

# Get full SRT text for track #3
srt_text = extract_subtitles_as_srt("movie.mkv", 3)
print(srt_text)

🖥️ CLI Usage

# List available subtitle tracks via CLI
python -m py_subtitle_extractor movie.mkv

# Extract full SRT from track #3
python -m py_subtitle_extractor movie.mkv -t 3 > subs.srt

📂 Bundling in a Kodi Add-on

Kodi auto-includes resources/lib in its Python path. To vendor the library:

pip install . --upgrade --no-deps -t /path/to/your.addon.id/resources/lib

📄 License

This project is licensed under the MIT License. See LICENSE for details.

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

py_subtitle_extractor-1.0.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_subtitle_extractor-1.0.4-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file py_subtitle_extractor-1.0.4.tar.gz.

File metadata

  • Download URL: py_subtitle_extractor-1.0.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for py_subtitle_extractor-1.0.4.tar.gz
Algorithm Hash digest
SHA256 85cf76a3c7b70528e6e5b1c3ee5f78cbd3ad514254f4a0485cdc026d7024a157
MD5 12094d2b5ac48dca53497bae20d36f76
BLAKE2b-256 8caa8bd0df05bd0b10e2df6c8bb8d488707be32e9566844988df82dc8ad6effa

See more details on using hashes here.

File details

Details for the file py_subtitle_extractor-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for py_subtitle_extractor-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 25fa0aced2b34226bc79617af3d87c2629c534408d1de487db34eda2e4b33e09
MD5 3fa08cca5e388fc6f37d2e5e629af6dc
BLAKE2b-256 5c75c070c6dafc441aad8aa2b616b2813186b4a830c87ae5a74d87d802c03012

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page