Skip to main content

SubRip (.srt) subtitle parser and writer

Project description

pysrt is a Python library used to edit or create SubRip files.

Basic Usage

Import:

>>> from pysrt import SubRipFile

Parsing:

>>> subs = SubRipFile.open('some/file.srt')
# If you get a UnicodeDecodeError try to specify the encoding
>>> subs = SubRipFile.open('some/file.srt', encoding='iso-8859-1')

SubRipFile are list-like objects of SubRipItem instances:

>>> len(first_sub)
>>> first_sub = subs[0]

SubRipItem instances are editable just like pure Python objects:

>>> first_sub.text = "Hello World !"
>>> first_sub.start.seconds = 20
>>> first_sub.end.minutes = 5

Shifting:

>>> subs.shift(seconds=-2) # Move all subs 2 seconds earlier
>>> subs.shift(minutes=1)  # Move all subs 1 minutes later
>>> first_sub.shift(seconds=1) # Move the first sub 1 second later
>>> first_sub.start += {'seconds': -1} # Make the first sub start 1 second earlier

Removing:

>>> del subs[12]

Slicing:

>>> part = subs.slice(starts_after={'minutes': 2, seconds': 30}, ends_before={'minutes': 3, 'seconds': 40})
>>> part.shift(seconds=-2)

Saving changes:

>>> subs.save('other/path.srt', encoding='utf-8')

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

pysrt-0.2.7.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

pysrt-0.2.7-py2.6.egg (25.9 kB view details)

Uploaded Source

File details

Details for the file pysrt-0.2.7.tar.gz.

File metadata

  • Download URL: pysrt-0.2.7.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pysrt-0.2.7.tar.gz
Algorithm Hash digest
SHA256 dd67e15571f171acfbc903830b971c466f167ab264a941fa1356eabd3cbd210b
MD5 655117f9cf23bf36fd17fab157100f01
BLAKE2b-256 8470ece911465088211ac97895bae14874f4a74423814e00c5447f45ce344301

See more details on using hashes here.

File details

Details for the file pysrt-0.2.7-py2.6.egg.

File metadata

  • Download URL: pysrt-0.2.7-py2.6.egg
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pysrt-0.2.7-py2.6.egg
Algorithm Hash digest
SHA256 7aa88f5c00493d40ad5bf2279a56c3bcd652e413da83e41a1b065b5e45156d04
MD5 39cdd09bd1ae2160e8b21af03a7ad4ba
BLAKE2b-256 f142919860d1f7705cb8c546425903ee436e30158ea6c56d68f486dfc7b99830

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