Skip to main content

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

Project description

Github Actions LGTM Coverage Dependencies

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

  • ~30% faster than pysrt on typical workloads

  • 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 -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, 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 -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:

>>> # 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

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

srt3-1.0.0.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

srt3-1.0.0-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file srt3-1.0.0.tar.gz.

File metadata

  • Download URL: srt3-1.0.0.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for srt3-1.0.0.tar.gz
Algorithm Hash digest
SHA256 915f3a2224270c6f169835e0179045087fa531c541059614993e692f1fe4622a
MD5 e3a05d99b77bbd6eaa3b9ab6e78f8168
BLAKE2b-256 79bceca3330f75acf129b9c9f73a9c58f6519b9b0508c4614a509e24d1994c08

See more details on using hashes here.

File details

Details for the file srt3-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: srt3-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for srt3-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24362d141f024127d9d394e72a359908c348dddb98ae68e0c7df2abd862a1433
MD5 d649de3e3ca96f903d070a95a1961e06
BLAKE2b-256 6a10d0597a9374e0a7c8b50176feb29163113c765dca1a56ef5c99fe4ac2a6c0

See more details on using hashes here.

Supported by

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