Skip to main content

A small package and CLI for manipulating and creating subtitles (SubRip, .srt, etc.)

Project description

Pyzub: Manipulate subtitles

Pyzub is a small package and CLI for manipulating subtitles

Suported Formats:

  • SubRip [.srt].

Plans to Support:

  • SubStation Alpha [.ssa]
  • SubViewer [.sub]
  • Universal Subtitle Format [.usf]

Installation:

Run pip install pyzub

Command Line Interface:

At the moment only the slide command is available (arguably the most important feature). The slide command of pyzub lets you move your subtitles so you can synchronize them manually.

$ pyzub slide -h
Usage: pyzub slide [OPTIONS] FILEPATH

Options:
  --hours FLOAT
  --minutes FLOAT
  --seconds FLOAT
  --milliseconds FLOAT
  --microseconds FLOAT
  --overwrite           Modifies the subtitle file in place.
  --verbose             Displays a progress bar and a message when finished.
  --help, -h            Show this message and exit.

Example:

This will move your subtitles by 2.5 seconds (you can also give negative values):

$ pyzub slide Game_of_Thrones_s03ep09.srt --seconds 2 --milliseconds 500

By default pyzub will generate an output file named Game_of_Thrones_s03ep09_MODIFIED.srt, unless --overwrite is used. The output file will always be in utf-8 encoding and use your system new line character.

This is OK too:

$ pyzub slide Game_of_Thrones_s03ep09.srt --seconds -70.5 --milliseconds 5000

This would move your subtitles 65.5 seconds back in time.

Package:

You can read a subtitle file:

from pyzub.subfiles import SRTFile

filepath = '/home/user/mysubtitle.srt'
subfile = SRTFile(filepath)

Iterate over the file:

for subtitle in subfile:
	print(subtitle)

Print a SRTFile:

print(subfile)
Relative Path: /home/user/mysubtitle.srt
Codec: ISO-8859-1
No. of Subtitles: 451

Get a subtitle:

# idx could be a number from 1 to 451 in this case
subtitle = subfile.get_subtitle(idx)

Print the subtitle:

print(subtitle)
Index: 1
Start Time: 00:00:04,605
End Time: 00:00:06,105
Text: En un día cualquiera,

An of course modify anything you want directly:

# modify the text
subtile.text = 'modified subtitle'

# times use timedelta from the datetime package
subtitle.start_time = timedelta(minutes=10)
# also, you can assign directly a string
subtitle.end_time = '01:25:59,650'

# write the changes to disk
subfile.dump('/home/user/mysubtitle_modified.srt')

And finally:

print(len(subfile))
# output: 451 (i.e, the number of subtitles in the file)
print(len(subtitle))
# output: 21 (i.e, the number of chars in the subtitle's text attribute)

Planned features:

  • Insert, delete subtitles, etc.
  • Automatic grammar and syntax correction

License

MIT

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

pyzub-0.1.6.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

pyzub-0.1.6-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pyzub-0.1.6.tar.gz.

File metadata

  • Download URL: pyzub-0.1.6.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyzub-0.1.6.tar.gz
Algorithm Hash digest
SHA256 6624030d1ed8297a691c48135b918ab27e5d9c57071a5d1ae1bbcd1a0513dcb6
MD5 b9b3306044f593cd10f68c3519b1f74c
BLAKE2b-256 1081530078f3b4c85265859458e027b0ddb6f982d2b943f6c2c286dcff8c7f90

See more details on using hashes here.

File details

Details for the file pyzub-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for pyzub-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8923991e385579684391dd1378e74b814e6c503e45d7609d10606617a068436a
MD5 4738ce91ac6837a703da42f8b54bc25c
BLAKE2b-256 af1dcf8c0109b15a9e591f395610c54fa39f08a266718a1647a949646ca3f783

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