srt3 is a simple yet 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.
Why choose this library?
Parses broken SRT files other libraries can’t and fixes them
Support for Asian-style SRT formats (ie. “fullwidth” SRT format)
Extremely lightweight with a Well Documented API
Includes tools that allow you to perform tasks using the library
No Dependencies outside of the Standard Library
High quality test suite using Hypothesis
100% Unicode Compliant
Portable — runs on Windows, OSX, and Linux
Released under a highly permissive license (MIT)
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 match -m hanzidentifier -fm 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, you have a subtitle containing Chinese and English, and another containing French. You only want Chinese French. The Chinese and English subtitle is also 5 seconds late. That’s easy enough to sort out:
$ srt match -m hanzidentifier -fm 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:
>>> # list() is needed as srt.parse creates a generator
>>> subs = list(srt.parse('''\
... 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
... 所有陆地生命归根结底都依赖於淡水
...
... '''))
>>> subs
[Subtitle(index=1, start=datetime.timedelta(0, 33, 843000), end=datetime.timedelta(0, 38, 97000), content='地球上只有3%的水是淡水', proprietary=''),
Subtitle(index=2, start=datetime.timedelta(0, 40, 641000), end=datetime.timedelta(0, 44, 687000), content='可是这些珍贵的淡水中却充满了惊奇', proprietary=''),
Subtitle(index=3, start=datetime.timedelta(0, 57, 908000), end=datetime.timedelta(0, 63, 414000), content='所有陆地生命归根结底都依赖於淡水', proprietary='')]
>>> print(srt.compose(subs))
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
所有陆地生命归根结底都依赖於淡水
Installation
To install the latest stable version from PyPi:
pip install -U srt3
To install the latest development version directly from GitHub:
pip install -U git+https://github.com/switchupcb/srt3.git@develop
Contribute
You can contribute to this repository using its Contribution Guidelines.
Metadata
Release files for srt3 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| srt3-1.0.1.tar.gz | 22.2 kB | Without provenance | Details for srt3-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| srt3-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for srt3-1.0.1-py3-none-any.whl |
Total release size: 48.9 kB
Release files / srt3-1.0.1.tar.gz
| Download URL | srt3-1.0.1.tar.gz |
|---|---|
| Size | 22.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e37b394d0728a85eec3df5d6055b0d8b50d844f074eceece73f04a85bb521ada
|
|
BLAKE2b-256 checksum How to use checksums |
9cca9f623b40fcd4a16d52ed3de08afe6c7dfb395cc1fb604ef92d444d2abcc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.4
|
Release files / srt3-1.0.1-py3-none-any.whl
| Download URL | srt3-1.0.1-py3-none-any.whl |
|---|---|
| Size | 26.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f543a7a75ff5f121e0d986fe7f0595a5cd94b16adc624e2cb8e1da5d2fb71541
|
|
BLAKE2b-256 checksum How to use checksums |
b45c8cec7b37d31e45b11716387c34662826418e78f0b599435b233598c7a72a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.4
|
Security for srt3 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.