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.0

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.0
File Size Uploaded
cleanit-0.5.0.tar.gz 33.1 kB Details

Built distribution (wheel)

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

Total release size: 65.2 kB

Release files / cleanit-0.5.0.tar.gz

Download URL cleanit-0.5.0.tar.gz
Size 33.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c3acb030ec31313955860154c89047faac581fd6833329baacf91ba2e5128ba7
BLAKE2b-256 checksum
How to use checksums
4ac09f9dd29cac9d8eeed43e554d2b427b3aba0aa8577769b6b64c6dca20e060
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.16 {"installer":{"name":"uv","version":"0.12.16","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.0-py3-none-any.whl

Download URL cleanit-0.5.0-py3-none-any.whl
Size 32.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d94b5ec2d0432429b487c6f78444a429a75ab0d327de8d7eff7016ac47feada1
BLAKE2b-256 checksum
How to use checksums
6983ea505c82711b927d6415170b1241d7440e424aabb68af5804a498faf36db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.16 {"installer":{"name":"uv","version":"0.12.16","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

0.5.1

2 release files

This release

0.5.0 This release

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