PyCaptions, parser and converter for captions formats
Project description
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
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*)
reader* - does not read styling/layout/metadata
writer* - does not write styling layout/metadata
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"])
# 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"])
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.5.0
Release date: 2024-01-21
Changes:
- SRT writer optimization
- Keyword
with
now supports string/iostream with parameterisFile = False
- budoux version upgrade for Thai formating support
- `languages`` is now not required parameter for readers
- Added basic ttml writer
detectTTML
now detects valid xml with empty lines- Changed
CaptionsFormat.getLayout
toCaptionsFormat.getLayoutById
, original now returns a list - Changed
CaptionsFormat.getStyle
toCaptionsFormat.getStyleById
, original now returns a list - Changed
CaptionsFormat.getMetadata
toCaptionsFormat.getMetadataById
, original now returns a list - Added
CaptionsFormat.removeComments
,CaptionsFormat.removeOptionsComments
,CaptionsFormat.removeAllComments
for removing comment blocks - Implemented
Block.getLines
that returns text in specified number of lines without style.
Read past changes here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pycaptions-0.5.0.tar.gz
(22.3 kB
view hashes)
Built Distribution
pycaptions-0.5.0-py3-none-any.whl
(28.5 kB
view hashes)
Close
Hashes for pycaptions-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a73eae49b1e34305dc79ca50b96c8cd657e054362c61d110765e2c1dc2b97c5b |
|
MD5 | a2de3299c3f24c8f2f10473582bd8aa8 |
|
BLAKE2b-256 | 53ff6b69c77538dd5f2a5818315319c6bda2726e830173aaa0d829e76dd61e03 |