pysub-parser
Utility to extract the contents of a subtitle file.
Supported types:
ass: Advanced SubStation Alphassa: SubStation Alphasrt: SubRipsub: MicroDVDtxt: Sub Viewer
For more information: http://write.flossmanuals.net/video-subtitling/file-formats
Usage
The method parse requires the following parameters:
path: location of the subtitle file.subtype: one of the supported file types, by default file extension is used.encoding: encoding of the file,utf-8by default.**kwargs: optional parameters.fps: framerate (only used bysubfiles),23.976by default.
from pysubparser import parser
subtitles = parser.parse('./files/space-jam.srt')
for subtitle in subtitles:
print(subtitle)
Output:
0 > [BALL BOUNCING]
1 > Michael?
2 > What are you doing out here, son? It's after midnight.
3 > MICHAEL: Couldn't sleep, Pops.
Subtitle Class
Each line of a dialogue is represented with a Subtitle object with the following properties:
index: position in the file.start: timestamp of the start of the dialog.end: timestamp of the end of the dialog.text: dialog contents.
for subtitle in subtitles:
print(f'{subtitle.start} > {subtitle.end}')
print(subtitle.text)
print()
Output:
00:00:36.328000 > 00:00:38.329000
[BALL BOUNCING]
00:01:03.814000 > 00:01:05.189000
Michael?
00:01:08.402000 > 00:01:11.404000
What are you doing out here, son? It's after midnight.
00:01:11.572000 > 00:01:13.072000
MICHAEL: Couldn't sleep, Pops.
Cleaners
Currently, 4 cleaners are provided:
asciiwill translate every unicode character to its ascii equivalent.bracketswill remove anything between them (e.g.,[BALL BOUNCING])formattingwill remove formatting keys like<i>and</i>.lower_casewill lower case all text.
from pysubparser.cleaners import ascii, brackets, formatting, lower_case
subtitles = brackets.clean(
lower_case.clean(
subtitles
)
)
for subtitle in subtitles:
print(subtitle)
0 >
1 > michael?
2 > what are you doing out here, son? it's after midnight.
3 > michael: couldn't sleep, pops.
Writers
Given any list of Subtitle and a path it will output those subtitles in a srt format.
Release files for pysub-parser 1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pysub-parser-1.2.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pysub_parser-1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.0 kB
Release files / pysub-parser-1.2.tar.gz
| Download URL | pysub-parser-1.2.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ce83bf461dd12848e4d6ece2b441cc9ae8b8d226a01d49e0935a7d7f97b2ee69
|
|
BLAKE2b-256 checksum How to use checksums |
d730de98f379a8693d40d96771c529df0806272ba5cb55058b591043f859cad6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
|
Release files / pysub_parser-1.2-py3-none-any.whl
| Download URL | pysub_parser-1.2-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c1bcf6608745518be3b27f5dfd9692e188b93bee35637f6c147a4c0904c2eca
|
|
BLAKE2b-256 checksum How to use checksums |
6f2d594f00afc2d479a4ac6f2c01319db8beba9ea9b9ed1fee0319875adfd2ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
|