Skip to main content

CleanIt

Subtitles extremely clean.

Latest Version

Supported versions

tests

License

CleanIt is a command line tool that helps you to keep your subtitles clean. You can specify your own rules to detect entries to be removed or patterns to be replaced. Simple text matching or complex regex can be used. It comes with standard rules out of the box:

  • ocr: Fix common OCR errors
  • tidy: Fix common formatting issues (e.g.: extra/missing spaces after punctuation)
  • no-sdh: Remove SDH descriptions
  • no-lyrics: Remove lyrics
  • no-spam: Remove ads and spams
  • no-style: Remove font style tags like <i> and <b>
  • minimal: includes only ocr and tidy rules
  • default: includes all rules except no-style

Installation

Run it without installing anything, using uv:

$ uvx cleanit --help

To install it as a standalone tool with uv (adds cleanit to your PATH):

$ uv tool install cleanit

Or install it with pip:

$ pip install cleanit

CleanIt is also available as a Docker image:

$ docker run -it --rm ratoaq2/cleanit --help

Usage

CLI

Clean subtitles:

$ cat mysubtitle.srt
1
00:00:46,464 --> 00:00:48,549
-And then what?
-| don't know.

2
00:49:07,278 --> 00:49:09,363
- If you cross the sea
with an army you bought ...


$ cleanit -t default mysubtitle.en.srt
1 subtitle collected / 0 subtitle filtered out / 0 path ignored
1 subtitle saved / 0 subtitle unchanged

$ cat mysubtitle.srt
1
00:00:46,464 --> 00:00:48,549
- And then what?
- I don't know.

2
00:49:07,278 --> 00:49:09,363
If you cross the sea
with an army you bought...


$ cleanit -t ocr -t no-sdh -t tidy -l en -l pt-BR ~/subtitles/
423 subtitles collected / 107 subtitles filtered out / 0 path ignored
Cleaning subtitles  [####################################]  100%
268 subtitles saved / 155 subtitles unchanged

Using docker:

$ docker run -it --rm -v /medias:/medias -u $(id -u username):$(id -g username) ratoaq2/cleanit -t default /medias
1072 subtitles collected / 0 subtitle filtered out / 0 path ignored
Cleaning subtitles  [####################################]  100%
980 subtitle saved / 92 subtitles unchanged

API

from cleanit import Config, Subtitle

sub = Subtitle("/subtitle/path/subtitle.en.srt")
cfg = Config.from_path("/config/path")
rules = cfg.select_rules(tags={"ocr"})
if sub.clean(rules):
    sub.save()

YAML Configuration file

templates:
  - &ocr
    tags:
      - ocr
      - minimal
      - default
    priority: 10000
    languages: en

rules:
  replace-l-to-I-character[ocr:en]:
    <<: *ocr
    patterns: '\bl\b'
    replacement: 'I'
    examples:
      ? |
        And if l refuse?
      : |
        And if I refuse?

Metadata

Release files for cleanit 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cleanit 0.5.1
File Size Uploaded
cleanit-0.5.1.tar.gz 34.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cleanit 0.5.1
File Interpreter ABI Platform
cleanit-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 66.7 kB

Release files / cleanit-0.5.1.tar.gz

Download URL cleanit-0.5.1.tar.gz
Size 34.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ed9c6a7bf6395a5e6204e137c1d587c971dfc32315e52851341f102784b01672
BLAKE2b-256 checksum
How to use checksums
bedc736a354f800d0ecc41f7580b1c09d483287f81c5e77839dcd3cd3d8fba92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / cleanit-0.5.1-py3-none-any.whl

Download URL cleanit-0.5.1-py3-none-any.whl
Size 32.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dda2665fa9a0d151f81c3c814a285af82b9249418d5fb3b831b5df4b8ba1b70a
BLAKE2b-256 checksum
How to use checksums
2f7f4c10216046fab1998f110e2e8b4bbe07694604e8334e859df86ac56f1334
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4

1 release file

0.3

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page