Skip to main content

SubRip (.srt) subtitle parser and writer

Project description

pysrt

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

https://secure.travis-ci.org/byroot/pysrt.png?branch=master https://coveralls.io/repos/byroot/pysrt/badge.png?branch=master https://pypip.in/v/pysrt/badge.png https://pypip.in/d/pysrt/badge.png

Foreword

pysrt is mainly designed as a library, but if you are experiencing troubles with bad subtitles you can first try to use ruby-osdb which will try to find the best subtitle for your movie. If you are still unlucky pysrt also provide an srt command useful for either shift, split, or rescale a .srt file.

Command Usage

Shifting:

$ srt -i shift 2s500ms movie.srt

Spliting:

$ srt split 58m26s movie.srt

Rescaling:

$ srt -i rate 23.9 25 movie.srt

Installation

pysrt is available on pypi. To intall it you can use either

pip:

$ sudo pip install pysrt

or distutils:

$ sudo easy_install pysrt

It is compatible with python >= 2.6 and 3.

Library Usage

Import:

>>> import pysrt

Parsing:

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

SubRipFile are list-like objects of SubRipItem instances:

>>> len(subs)
>>> 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
>>> subs.shift(ratio=25/23.9) # convert a 23.9 fps subtitle in 25 fps
>>> 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-1.0.1.tar.gz (11.7 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for pysrt-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5300a1584c8d15a1c49ef8880fa1ef7a4274ce3f24dde83ad581d12d875f6784
MD5 2ba064c33026bac4b528063f67bd8ebc
BLAKE2b-256 03d92f9b0ed523a1423987d2a73d94d73a00b2f41f3b24b17fd1eba8e0d1a5dd

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