PyCaptions
PyCaptions is a caption reading/writing library.Why LGPL-3.0? This is just to ensure that source code for the library is always under the same licence and cannot be closed-sourced. All the conditions for this licence only apply for the the library itself and it's modifications. We reccomend to just contribute to the project if you are making modifications, unless they are drastic and specific to your case.
Table of Contents
Read the Wiki
Installation
- PIP
pip install --upgrade pycaptions - Source
git clone https://github.com/adfreelife/PyCaptions.git cd PyCaptions python setup.py install
Supported Formats
- SubRip (SRT) (reader + writer)
- MicroDVD (SUB) (reader + writer)
- Timed Text Markup Language (TTML, DFXP, XML) (reader* + writer*)
- Web Video Text Tracks Format (VTT) (reader + writer*)
*Limited functionality
Future plans
- add writers to all supported formats
- auto-fit lines into multilines or split captions blocks into two parts
- add support for more formats
- Synchronized Accessible Media Interchange (SAMI)
- Universal Subtitle Format (USF)
- LyRiCs (LRC)
- open an issue with "enhancement" label for more
Examples
Generic from file name
from pycaptions import Captions
with Captions("tests/test.en.srt") as captions:
captions.saveVTT("test")
Generic from file stream
with open("tests/test.en.srt", encoding="UTF-8") as f:
captions = Captions(f) # or captions = Captions()
# captions.read(f)
captions.saveVTT("test")
Generic from string
srt = """1
00:00:00,500 --> 00:00:02,000
This is a test file
"""
captions = Captions(srt) # or captions = Captions()
# captions.detect(srt)
captions.saveVTT("test")
Specific reader
Have the same functions as generic, except
from pycaptions import SubRip, detectSRT
with open("tests/test.en.srt", encoding="UTF-8") as f:
if detectSRT(f): # or SubRip.detect(f)
captions = SubRip().read(f)
captions.saveVTT("test")
Multilingual
from pycaptions import Captions
# if the format supports multiple languages
with Captions("tests/test.ttml") as captions:
# first line will be in english, second one in spanish
captions.saveSRT("test", ["en","es"] lines=1) # recomended to specify lines=1
# if you have multiple files and you want to make multilingual one
with Captions("tests/test.en.srt") as captions:
with Captions("tests/test.es.srt") as captions2:
# only subtitle text and comments (if format supports them) are added
captions+=captions2
# first line will be in english, second one in spanish
captions.save("test", ["en","es"], lines=1) # recomended to specify lines=1
Combine files
with Captions("tests/test.en.srt") as captions:
captions.joinFile("tests/test.en.srt", add_end_time=True)
captions.save("test")
Changelog
v0.7.0
Release date: 2024-02-06
Changes:
- Added cli support (e.g
pycaptions "path/to/file/file.srt" -f vtt) - Added autoformat for all values of
lines - Added function
CaptionsFormat.getLanguagesAndFilename - Added function
CaptionsFormat.getFilename - Added
MicroTime.fromMicrotimecreates a MicroTime from a list - Added
MicroTime.toMicrotimereturns a MicroTime as a list - Added
MicroTime.fromAnyFormatreturns a MicroTime from provided format (case insensitive) MicroTime.fromSUBTimeandMicroTime.toSUBTimenow supports framerate as stringCaptions.saveoutput_format is now case insensitive- Improved MicroDVD style conversion
- Internal restructure for faster development
- Invalid
styleargument will result instyle=None - Added
style_optionsfor changing style globaly, defaultstyle="full"lines=-1, this affects how the style is parsed. (e.g.style_options.style=Noneand then using argumentstyle="full"will not convert any style due to optimizations for faster conversion) - Hypens at the end of the lines (e.g "Some-
thing") will be removed iflinesis >-1 Stylingis now split intoStyleFormatandStyling(StyleFormat)
Fixes:
- Fixed "lxml is not installed" error
- Fixed
Styling.getTTMLconverting invalid css properties into ttml properties. To-do: add value checks for these properties. - Fixed
CaptionsFormat.getLanguagesFromFilenamegetting languages from directory path (e.g.\path.to.file\file.en.srt->["to", "en"]) - Fixed width and height not being saved to json
Read past changes here.
Metadata
Release files for pycaptions 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pycaptions-0.7.0.tar.gz | 36.0 kB | Without provenance | Details for pycaptions-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pycaptions-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for pycaptions-0.7.0-py3-none-any.whl |
Total release size: 82.2 kB
Release files / pycaptions-0.7.0.tar.gz
| Download URL | pycaptions-0.7.0.tar.gz |
|---|---|
| Size | 36.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de85f4a6db588af4a8925f3751adfd080cacfee9590897030a721b706c61bb10
|
|
BLAKE2b-256 checksum How to use checksums |
12abae7701ce74ccf73d64fadd3ef8c5e401b1160dfc4af88f3026bf3231fb21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Release files / pycaptions-0.7.0-py3-none-any.whl
| Download URL | pycaptions-0.7.0-py3-none-any.whl |
|---|---|
| Size | 46.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4815c5b8dbee636921df9606f4461786126281d8d6c0601f2e7339cb140a4b4f
|
|
BLAKE2b-256 checksum How to use checksums |
001b31ba2fcd77f61247a2ad6ef2b59c1b7b71be9cf26bd9954e127f8d84cf17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Security for pycaptions 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.