{"id":13827672,"url":"https://github.com/cdown/srt","last_synced_at":"2025-05-14T23:06:38.872Z","repository":{"id":25128438,"uuid":"28550291","full_name":"cdown/srt","owner":"cdown","description":"A simple library and set of tools for parsing, modifying, and composing SRT files.","archived":false,"fork":false,"pushed_at":"2024-03-19T05:34:53.000Z","size":416,"stargazers_count":499,"open_issues_count":7,"forks_count":45,"subscribers_count":16,"default_branch":"develop","last_synced_at":"2025-04-13T19:50:03.835Z","etag":null,"topics":["command-line","command-line-tool","library","mit-license","python","srt","subtitle","subtitle-fixer","subtitle-parser","subtitles","subtitles-parsing","text-extraction","tools"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdown.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-28T01:05:38.000Z","updated_at":"2025-04-13T16:41:37.000Z","dependencies_parsed_at":"2023-01-14T02:10:39.557Z","dependency_job_id":"be66ddee-5dda-43b0-b541-3549c8464c50","html_url":"https://github.com/cdown/srt","commit_stats":{"total_commits":645,"total_committers":6,"mean_commits":107.5,"dds":0.007751937984496138,"last_synced_commit":"434d0c1c9d5c26d5c3fb1ce979fc05b478e9253c"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdown%2Fsrt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdown%2Fsrt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdown%2Fsrt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdown%2Fsrt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdown","download_url":"https://codeload.github.com/cdown/srt/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243360,"owners_count":22038046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line","command-line-tool","library","mit-license","python","srt","subtitle","subtitle-fixer","subtitle-parser","subtitles","subtitles-parsing","text-extraction","tools"],"created_at":"2024-08-04T09:02:04.996Z","updated_at":"2025-05-14T23:06:33.858Z","avatar_url":"https://github.com/cdown.png","language":"Python","readme":"|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 — used in production to process thousands of SRT files\n  every day\n- Portable — runs on Linux, OSX, and Windows\n- Tools included — 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 --\u003e 00:00:38,097\n    Only 3% of the water on our planet is fresh.\n    地球上只有3%的水是淡水\n\n    2\n    00:00:40,641 --\u003e 00:00:44,687\n    Yet, these precious waters are rich with surprise.\n    可是这些珍贵的淡水中却充满了惊奇\n\n    $ srt lines-matching -m hanzidentifier -f hanzidentifier.has_chinese -i pe.srt\n    1\n    00:00:33,843 --\u003e 00:00:38,097\n    地球上只有3%的水是淡水\n\n    2\n    00:00:40,641 --\u003e 00:00:44,687\n    可是这些珍贵的淡水中却充满了惊奇\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   \u003e     srt fixed-timeshift --seconds -5 |\n   \u003e     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    \u003e\u003e\u003e data = '''\\\n    1\n    00:00:33,843 --\u003e 00:00:38,097\n    地球上只有3%的水是淡水\n\n    2\n    00:00:40,641 --\u003e 00:00:44,687\n    可是这些珍贵的淡水中却充满了惊奇\n\n    3\n    00:00:57,908 --\u003e 00:01:03,414\n    所有陆地生命归根结底都依赖於淡水\n\n    '''\n    \u003e\u003e\u003e 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='地球上只有3%的水是淡水', proprietary='')\n    Subtitle(index=2, start=datetime.timedelta(seconds=40, microseconds=641000), end=datetime.timedelta(seconds=44, microseconds=687000), content='可是这些珍贵的淡水中却充满了惊奇', proprietary='')\n    Subtitle(index=3, start=datetime.timedelta(seconds=57, microseconds=908000), end=datetime.timedelta(seconds=63, microseconds=414000), content='所有陆地生命归根结底都依赖於淡水', proprietary='')\n\nAnd here's how you go back from Subtitle objects to SRT output:\n\n.. code:: python\n\n    \u003e\u003e\u003e subs = list(srt.parse(data))\n    \u003e\u003e\u003e subs[1].content = \"Changing subtitle data is easy!\"\n    \u003e\u003e\u003e print(srt.compose(subs))\n    1\n    00:00:33,843 --\u003e 00:00:38,097\n    地球上只有3%的水是淡水\n\n    2\n    00:00:40,641 --\u003e 00:00:44,687\n    Changing subtitle data is easy!\n\n    3\n    00:00:57,908 --\u003e 00:01:03,414\n    所有陆地生命归根结底都依赖於淡水\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","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdown%2Fsrt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdown%2Fsrt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdown%2Fsrt/lists"}