srt


Namesrt JSON
Version 3.5.3 PyPI version JSON
download
home_pagehttps://github.com/cdown/srt
SummaryA tiny library for parsing, modifying, and composing SRT files.
upload_time2023-03-28 02:35:44
maintainer
docs_urlNone
authorChris Down
requires_python>=2.7
licenseMIT
keywords srt
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            |ghactions| |coveralls|

.. |ghactions| image:: https://img.shields.io/github/actions/workflow/status/cdown/srt/ci.yml?branch=develop
  :target: https://github.com/cdown/srt/actions?query=branch%3Adevelop
  :alt: Tests

.. |coveralls| image:: https://img.shields.io/coveralls/cdown/srt/develop.svg?label=test%20coverage
  :target: https://coveralls.io/github/cdown/srt?branch=develop
  :alt: Coverage

srt is a tiny but featureful Python library for parsing, modifying, and
composing `SRT files`_. Take a look at the quickstart_ for a basic overview of
the library. `Detailed API documentation`_ is also available.

Want to see some examples of its use? Take a look at the `tools shipped with
the library`_. This library is also used internally by projects like
`subsync`_, `NVIDIA RAD-TTS`_, `manim`_, `kinobot`_, `bw_plex`_, and many more.

.. _subsync: https://github.com/smacke/subsync
.. _`NVIDIA RAD-TTS`: https://github.com/NVIDIA/radtts
.. _bw_plex: https://github.com/Hellowlol/bw_plex
.. _manim: https://github.com/ManimCommunity/manim
.. _kinobot: https://github.com/vitiko98/kinobot

Why choose this library?
------------------------

- Can parse many broken SRT files which other SRT libraries cannot, and fix them
- Extremely lightweight, ~200 lines of code excluding docstrings
- Simple, intuitive API
- High quality test suite using Hypothesis_
- `100% test coverage`_ (including branches)
- `Well documented API`_, at both a high and low level
- `~30% faster than pysrt on typical workloads`_
- Full support for `PyPy`_
- No dependencies outside of the standard library
- Tolerant of many common errors found in real-world SRT files
- Support for Asian-style SRT formats (ie. "fullwidth" SRT format)
- Completely Unicode compliant
- Released under a highly permissive license (MIT)
- Real world tested — used in production to process thousands of SRT files
  every day
- Portable — runs on Linux, OSX, and Windows
- Tools included — contains lightweight tools to perform generic tasks with the
  library

.. _quickstart: http://srt.readthedocs.org/en/latest/quickstart.html
.. _`SRT files`: https://en.wikipedia.org/wiki/SubRip#SubRip_text_file_format
.. _Hypothesis: https://github.com/DRMacIver/hypothesis
.. _`100% test coverage`: https://coveralls.io/github/cdown/srt?branch=develop
.. _`Well documented API`: http://srt.readthedocs.org/en/latest/index.html
.. _PyPy: http://pypy.org/
.. _`~30% faster than pysrt on typical workloads`: https://paste.pound-python.org/raw/8nQKbDW0ROWvS7bOeAb3/

Usage
-----

Tools
=====

There are a number of `tools shipped with the library`_ to manipulate, process,
and fix SRT files. Here's an example using `hanzidentifier`_ to strip out
non-Chinese lines:

.. code::

    $ cat pe.srt
    1
    00:00:33,843 --> 00:00:38,097
    Only 3% of the water on our planet is fresh.
    地球上只有3%的水是淡水

    2
    00:00:40,641 --> 00:00:44,687
    Yet, these precious waters are rich with surprise.
    可是这些珍贵的淡水中却充满了惊奇

    $ srt lines-matching -m hanzidentifier -f hanzidentifier.has_chinese -i pe.srt
    1
    00:00:33,843 --> 00:00:38,097
    地球上只有3%的水是淡水

    2
    00:00:40,641 --> 00:00:44,687
    可是这些珍贵的淡水中却充满了惊奇


These tools are easy to chain together, for example, say you have one subtitle
with Chinese and English, and other with French, but you want Chinese and
French only. Oh, and the Chinese one is 5 seconds later than it should be.
That's easy enough to sort out:

.. code::

   $ srt lines-matching -m hanzidentifier -f hanzidentifier.has_chinese -i chs+eng.srt |
   >     srt fixed-timeshift --seconds -5 |
   >     srt mux --input - --input fra.srt

See the srt_tools/ directory for more information.

.. _hanzidentifier: https://github.com/tsroten/hanzidentifier

Library
=======

`Detailed API documentation`_ is available, but here are the basics.

Here's how you convert SRT input to Subtitle objects which you can manipulate:

.. code:: python

    >>> data = '''\
    1
    00:00:33,843 --> 00:00:38,097
    地球上只有3%的水是淡水

    2
    00:00:40,641 --> 00:00:44,687
    可是这些珍贵的淡水中却充满了惊奇

    3
    00:00:57,908 --> 00:01:03,414
    所有陆地生命归根结底都依赖於淡水

    '''
    >>> for sub in srt.parse(data):
    ...     print(sub)
    Subtitle(index=1, start=datetime.timedelta(seconds=33, microseconds=843000), end=datetime.timedelta(seconds=38, microseconds=97000), content='地球上只有3%的水是淡水', proprietary='')
    Subtitle(index=2, start=datetime.timedelta(seconds=40, microseconds=641000), end=datetime.timedelta(seconds=44, microseconds=687000), content='可是这些珍贵的淡水中却充满了惊奇', proprietary='')
    Subtitle(index=3, start=datetime.timedelta(seconds=57, microseconds=908000), end=datetime.timedelta(seconds=63, microseconds=414000), content='所有陆地生命归根结底都依赖於淡水', proprietary='')

And here's how you go back from Subtitle objects to SRT output:

.. code:: python

    >>> subs = list(srt.parse(data))
    >>> subs[1].content = "Changing subtitle data is easy!"
    >>> print(srt.compose(subs))
    1
    00:00:33,843 --> 00:00:38,097
    地球上只有3%的水是淡水

    2
    00:00:40,641 --> 00:00:44,687
    Changing subtitle data is easy!

    3
    00:00:57,908 --> 00:01:03,414
    所有陆地生命归根结底都依赖於淡水

Installation
------------

To install the latest stable version from PyPi:

.. code::

    pip install -U srt

To install the latest development version directly from GitHub:

.. code::

    pip install -U git+https://github.com/cdown/srt.git@develop

Testing
-------

.. code::

   tox

.. _Tox: https://tox.readthedocs.org
.. _`Detailed API documentation`: http://srt.readthedocs.org/en/latest/api.html
.. _`tools shipped with the library`: https://github.com/cdown/srt/tree/develop/srt_tools



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cdown/srt",
    "name": "srt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.7",
    "maintainer_email": "",
    "keywords": "srt",
    "author": "Chris Down",
    "author_email": "chris@chrisdown.name",
    "download_url": "https://files.pythonhosted.org/packages/66/b7/4a1bc231e0681ebf339337b0cd05b91dc6a0d701fa852bb812e244b7a030/srt-3.5.3.tar.gz",
    "platform": null,
    "description": "|ghactions| |coveralls|\n\n.. |ghactions| image:: https://img.shields.io/github/actions/workflow/status/cdown/srt/ci.yml?branch=develop\n  :target: https://github.com/cdown/srt/actions?query=branch%3Adevelop\n  :alt: Tests\n\n.. |coveralls| image:: https://img.shields.io/coveralls/cdown/srt/develop.svg?label=test%20coverage\n  :target: https://coveralls.io/github/cdown/srt?branch=develop\n  :alt: Coverage\n\nsrt is a tiny but featureful Python library for parsing, modifying, and\ncomposing `SRT files`_. Take a look at the quickstart_ for a basic overview of\nthe library. `Detailed API documentation`_ is also available.\n\nWant to see some examples of its use? Take a look at the `tools shipped with\nthe library`_. This library is also used internally by projects like\n`subsync`_, `NVIDIA RAD-TTS`_, `manim`_, `kinobot`_, `bw_plex`_, and many more.\n\n.. _subsync: https://github.com/smacke/subsync\n.. _`NVIDIA RAD-TTS`: https://github.com/NVIDIA/radtts\n.. _bw_plex: https://github.com/Hellowlol/bw_plex\n.. _manim: https://github.com/ManimCommunity/manim\n.. _kinobot: https://github.com/vitiko98/kinobot\n\nWhy choose this library?\n------------------------\n\n- Can parse many broken SRT files which other SRT libraries cannot, and fix them\n- Extremely lightweight, ~200 lines of code excluding docstrings\n- Simple, intuitive API\n- High quality test suite using Hypothesis_\n- `100% test coverage`_ (including branches)\n- `Well documented API`_, at both a high and low level\n- `~30% faster than pysrt on typical workloads`_\n- Full support for `PyPy`_\n- No dependencies outside of the standard library\n- Tolerant of many common errors found in real-world SRT files\n- Support for Asian-style SRT formats (ie. \"fullwidth\" SRT format)\n- Completely Unicode compliant\n- Released under a highly permissive license (MIT)\n- Real world tested \u2014 used in production to process thousands of SRT files\n  every day\n- Portable \u2014 runs on Linux, OSX, and Windows\n- Tools included \u2014 contains lightweight tools to perform generic tasks with the\n  library\n\n.. _quickstart: http://srt.readthedocs.org/en/latest/quickstart.html\n.. _`SRT files`: https://en.wikipedia.org/wiki/SubRip#SubRip_text_file_format\n.. _Hypothesis: https://github.com/DRMacIver/hypothesis\n.. _`100% test coverage`: https://coveralls.io/github/cdown/srt?branch=develop\n.. _`Well documented API`: http://srt.readthedocs.org/en/latest/index.html\n.. _PyPy: http://pypy.org/\n.. _`~30% faster than pysrt on typical workloads`: https://paste.pound-python.org/raw/8nQKbDW0ROWvS7bOeAb3/\n\nUsage\n-----\n\nTools\n=====\n\nThere are a number of `tools shipped with the library`_ to manipulate, process,\nand fix SRT files. Here's an example using `hanzidentifier`_ to strip out\nnon-Chinese lines:\n\n.. code::\n\n    $ cat pe.srt\n    1\n    00:00:33,843 --> 00:00:38,097\n    Only 3% of the water on our planet is fresh.\n    \u5730\u7403\u4e0a\u53ea\u67093%\u7684\u6c34\u662f\u6de1\u6c34\n\n    2\n    00:00:40,641 --> 00:00:44,687\n    Yet, these precious waters are rich with surprise.\n    \u53ef\u662f\u8fd9\u4e9b\u73cd\u8d35\u7684\u6de1\u6c34\u4e2d\u5374\u5145\u6ee1\u4e86\u60ca\u5947\n\n    $ srt lines-matching -m hanzidentifier -f hanzidentifier.has_chinese -i pe.srt\n    1\n    00:00:33,843 --> 00:00:38,097\n    \u5730\u7403\u4e0a\u53ea\u67093%\u7684\u6c34\u662f\u6de1\u6c34\n\n    2\n    00:00:40,641 --> 00:00:44,687\n    \u53ef\u662f\u8fd9\u4e9b\u73cd\u8d35\u7684\u6de1\u6c34\u4e2d\u5374\u5145\u6ee1\u4e86\u60ca\u5947\n\n\nThese tools are easy to chain together, for example, say you have one subtitle\nwith Chinese and English, and other with French, but you want Chinese and\nFrench only. Oh, and the Chinese one is 5 seconds later than it should be.\nThat's easy enough to sort out:\n\n.. code::\n\n   $ srt lines-matching -m hanzidentifier -f hanzidentifier.has_chinese -i chs+eng.srt |\n   >     srt fixed-timeshift --seconds -5 |\n   >     srt mux --input - --input fra.srt\n\nSee the srt_tools/ directory for more information.\n\n.. _hanzidentifier: https://github.com/tsroten/hanzidentifier\n\nLibrary\n=======\n\n`Detailed API documentation`_ is available, but here are the basics.\n\nHere's how you convert SRT input to Subtitle objects which you can manipulate:\n\n.. code:: python\n\n    >>> data = '''\\\n    1\n    00:00:33,843 --> 00:00:38,097\n    \u5730\u7403\u4e0a\u53ea\u67093%\u7684\u6c34\u662f\u6de1\u6c34\n\n    2\n    00:00:40,641 --> 00:00:44,687\n    \u53ef\u662f\u8fd9\u4e9b\u73cd\u8d35\u7684\u6de1\u6c34\u4e2d\u5374\u5145\u6ee1\u4e86\u60ca\u5947\n\n    3\n    00:00:57,908 --> 00:01:03,414\n    \u6240\u6709\u9646\u5730\u751f\u547d\u5f52\u6839\u7ed3\u5e95\u90fd\u4f9d\u8d56\u65bc\u6de1\u6c34\n\n    '''\n    >>> for sub in srt.parse(data):\n    ...     print(sub)\n    Subtitle(index=1, start=datetime.timedelta(seconds=33, microseconds=843000), end=datetime.timedelta(seconds=38, microseconds=97000), content='\u5730\u7403\u4e0a\u53ea\u67093%\u7684\u6c34\u662f\u6de1\u6c34', proprietary='')\n    Subtitle(index=2, start=datetime.timedelta(seconds=40, microseconds=641000), end=datetime.timedelta(seconds=44, microseconds=687000), content='\u53ef\u662f\u8fd9\u4e9b\u73cd\u8d35\u7684\u6de1\u6c34\u4e2d\u5374\u5145\u6ee1\u4e86\u60ca\u5947', proprietary='')\n    Subtitle(index=3, start=datetime.timedelta(seconds=57, microseconds=908000), end=datetime.timedelta(seconds=63, microseconds=414000), content='\u6240\u6709\u9646\u5730\u751f\u547d\u5f52\u6839\u7ed3\u5e95\u90fd\u4f9d\u8d56\u65bc\u6de1\u6c34', proprietary='')\n\nAnd here's how you go back from Subtitle objects to SRT output:\n\n.. code:: python\n\n    >>> subs = list(srt.parse(data))\n    >>> subs[1].content = \"Changing subtitle data is easy!\"\n    >>> print(srt.compose(subs))\n    1\n    00:00:33,843 --> 00:00:38,097\n    \u5730\u7403\u4e0a\u53ea\u67093%\u7684\u6c34\u662f\u6de1\u6c34\n\n    2\n    00:00:40,641 --> 00:00:44,687\n    Changing subtitle data is easy!\n\n    3\n    00:00:57,908 --> 00:01:03,414\n    \u6240\u6709\u9646\u5730\u751f\u547d\u5f52\u6839\u7ed3\u5e95\u90fd\u4f9d\u8d56\u65bc\u6de1\u6c34\n\nInstallation\n------------\n\nTo install the latest stable version from PyPi:\n\n.. code::\n\n    pip install -U srt\n\nTo install the latest development version directly from GitHub:\n\n.. code::\n\n    pip install -U git+https://github.com/cdown/srt.git@develop\n\nTesting\n-------\n\n.. code::\n\n   tox\n\n.. _Tox: https://tox.readthedocs.org\n.. _`Detailed API documentation`: http://srt.readthedocs.org/en/latest/api.html\n.. _`tools shipped with the library`: https://github.com/cdown/srt/tree/develop/srt_tools\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A tiny library for parsing, modifying, and composing SRT files.",
    "version": "3.5.3",
    "split_keywords": [
        "srt"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "66b74a1bc231e0681ebf339337b0cd05b91dc6a0d701fa852bb812e244b7a030",
                "md5": "102ba419fc500b7586eb3cdab7ac819f",
                "sha256": "4884315043a4f0740fd1f878ed6caa376ac06d70e135f306a6dc44632eed0cc0"
            },
            "downloads": -1,
            "filename": "srt-3.5.3.tar.gz",
            "has_sig": false,
            "md5_digest": "102ba419fc500b7586eb3cdab7ac819f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7",
            "size": 28296,
            "upload_time": "2023-03-28T02:35:44",
            "upload_time_iso_8601": "2023-03-28T02:35:44.007556Z",
            "url": "https://files.pythonhosted.org/packages/66/b7/4a1bc231e0681ebf339337b0cd05b91dc6a0d701fa852bb812e244b7a030/srt-3.5.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-28 02:35:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "cdown",
    "github_project": "srt",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "srt"
}
        
Elapsed time: 0.04963s