VOOZH about

URL: https://pypi.org/project/srt/

⇱ srt Β· PyPI


Skip to main content

srt 3.5.3

pip install srt

Latest release

Released:

A tiny library for parsing, modifying, and composing SRT files.

Navigation

Verified details

These details have been verified by PyPI
Maintainers
πŸ‘ Avatar for cdown from gravatar.com
cdown

Unverified details

These details have not been verified by PyPI
Project links
Meta
  • License: MIT License (MIT)
  • Author: Chris Down
  • Tags srt
  • Requires: Python >=2.7

Project description

πŸ‘ Tests
πŸ‘ Coverage

srt is a tiny but featureful Python library for parsing, modifying, and composing SRT files. Take a look at the quickstart for a basic overview of the library. Detailed API documentation is also available.

Want to see some examples of its use? Take a look at the tools shipped with the library. This library is also used internally by projects like subsync, NVIDIA RAD-TTS, manim, kinobot, bw_plex, and many more.

Why choose this library?

  • Can parse many broken SRT files which other SRT libraries cannot, and fix them

  • Extremely lightweight, ~200 lines of code excluding docstrings

  • Simple, intuitive API

  • High quality test suite using Hypothesis

  • 100% test coverage (including branches)

  • Well documented API, at both a high and low level

  • ~30% faster than pysrt on typical workloads

  • Full support for PyPy

  • No dependencies outside of the standard library

  • Tolerant of many common errors found in real-world SRT files

  • Support for Asian-style SRT formats (ie. β€œfullwidth” SRT format)

  • Completely Unicode compliant

  • Released under a highly permissive license (MIT)

  • Real world tested β€” used in production to process thousands of SRT files every day

  • Portable β€” runs on Linux, OSX, and Windows

  • Tools included β€” contains lightweight tools to perform generic tasks with the library

Usage

Tools

There are a number of tools shipped with the library to manipulate, process, and fix SRT files. Here’s an example using hanzidentifier to strip out non-Chinese lines:

$ cat pe.srt
1
00:00:33,843 --> 00:00:38,097
Only 3% of the water on our planet is fresh.
εœ°ηƒδΈŠεͺζœ‰3%ηš„ζ°΄ζ˜―ζ·‘ζ°΄

2
00:00:40,641 --> 00:00:44,687
Yet, these precious waters are rich with surprise.
ε―ζ˜―θΏ™δΊ›ηθ΄΅ηš„ζ·‘ζ°΄δΈ­ε΄ε……ζ»‘δΊ†ζƒŠε₯‡

$ srt lines-matching -m hanzidentifier -f hanzidentifier.has_chinese -i pe.srt
1
00:00:33,843 --> 00:00:38,097
εœ°ηƒδΈŠεͺζœ‰3%ηš„ζ°΄ζ˜―ζ·‘ζ°΄

2
00:00:40,641 --> 00:00:44,687
ε―ζ˜―θΏ™δΊ›ηθ΄΅ηš„ζ·‘ζ°΄δΈ­ε΄ε……ζ»‘δΊ†ζƒŠε₯‡

These tools are easy to chain together, for example, say you have one subtitle with Chinese and English, and other with French, but you want Chinese and French only. Oh, and the Chinese one is 5 seconds later than it should be. That’s easy enough to sort out:

$ srt lines-matching -m hanzidentifier -f hanzidentifier.has_chinese -i chs+eng.srt |
> srt fixed-timeshift --seconds -5 |
> srt mux --input - --input fra.srt

See the srt_tools/ directory for more information.

Library

Detailed API documentation is available, but here are the basics.

Here’s how you convert SRT input to Subtitle objects which you can manipulate:

>>> data = '''\
1
00:00:33,843 --> 00:00:38,097
εœ°ηƒδΈŠεͺζœ‰3%ηš„ζ°΄ζ˜―ζ·‘ζ°΄

2
00:00:40,641 --> 00:00:44,687
ε―ζ˜―θΏ™δΊ›ηθ΄΅ηš„ζ·‘ζ°΄δΈ­ε΄ε……ζ»‘δΊ†ζƒŠε₯‡

3
00:00:57,908 --> 00:01:03,414
ζ‰€ζœ‰ι™†εœ°η”Ÿε‘½ε½’ζ Ήη»“εΊ•ιƒ½δΎθ΅–ζ–Όζ·‘ζ°΄

'''>>> for sub in srt.parse(data):... print(sub)Subtitle(index=1, start=datetime.timedelta(seconds=33, microseconds=843000), end=datetime.timedelta(seconds=38, microseconds=97000), content='εœ°ηƒδΈŠεͺζœ‰3%ηš„ζ°΄ζ˜―ζ·‘ζ°΄', proprietary='')Subtitle(index=2, start=datetime.timedelta(seconds=40, microseconds=641000), end=datetime.timedelta(seconds=44, microseconds=687000), content='ε―ζ˜―θΏ™δΊ›ηθ΄΅ηš„ζ·‘ζ°΄δΈ­ε΄ε……ζ»‘δΊ†ζƒŠε₯‡', proprietary='')Subtitle(index=3, start=datetime.timedelta(seconds=57, microseconds=908000), end=datetime.timedelta(seconds=63, microseconds=414000), content='ζ‰€ζœ‰ι™†εœ°η”Ÿε‘½ε½’ζ Ήη»“εΊ•ιƒ½δΎθ΅–ζ–Όζ·‘ζ°΄', proprietary='')

And here’s how you go back from Subtitle objects to SRT output:

>>> subs = list(srt.parse(data))>>> subs[1].content = "Changing subtitle data is easy!">>> print(srt.compose(subs))100:00:33,843 --> 00:00:38,097εœ°ηƒδΈŠεͺζœ‰3%ηš„ζ°΄ζ˜―ζ·‘ζ°΄200:00:40,641 --> 00:00:44,687Changing subtitle data is easy!300:00:57,908 --> 00:01:03,414ζ‰€ζœ‰ι™†εœ°η”Ÿε‘½ε½’ζ Ήη»“εΊ•ιƒ½δΎθ΅–ζ–Όζ·‘ζ°΄

Installation

To install the latest stable version from PyPi:

pip install -U srt

To install the latest development version directly from GitHub:

pip install -U git+https://github.com/cdown/srt.git@develop

Testing

tox

Project details

Verified details

These details have been verified by PyPI
Maintainers
πŸ‘ Avatar for cdown from gravatar.com
cdown

Unverified details

These details have not been verified by PyPI
Project links
Meta
  • License: MIT License (MIT)
  • Author: Chris Down
  • Tags srt
  • Requires: Python >=2.7

Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

srt-3.5.3.tar.gz (28.3 kB view details)

Uploaded Source

File details

Details for the file srt-3.5.3.tar.gz.

File metadata

  • Download URL: srt-3.5.3.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.2

File hashes

Hashes for srt-3.5.3.tar.gz
Algorithm Hash digest
SHA256 4884315043a4f0740fd1f878ed6caa376ac06d70e135f306a6dc44632eed0cc0
MD5 102ba419fc500b7586eb3cdab7ac819f
BLAKE2b-256 66b74a1bc231e0681ebf339337b0cd05b91dc6a0d701fa852bb812e244b7a030

See more details on using hashes here.

Supported by

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