Skip to main content

Clean up SRT subtitle files removing ads and misplaced credits

Project description

SRT Cleaner

A simple tool to clean up SRT subtitle files removing ads and misplaced credits, also fixing their encoding.

Usage

Library

import srtcleaner

srtfiles = ['/data/TVSeries/Cosmos/Cosmos.S01E01.srt',
            '/data/TVSeries/Cosmos/Cosmos.S01E02.srt']

srtcleaner.srtcleaner([srtfiles], in_place=True, backup=False, convert='UTF-8')

Command-line

$ srtcleaner --help

usage: srtcleaner [-h] [-q | -v] [--recursive] [--input-encoding ENCODING]
                  [--input-fallback-encoding FALLBACK_ENCODING]
                  [--convert OUTPUT_ENCODING] [--in-place] [--no-backup]
                  [--no-rebuild-index] [--blacklist BLACKLISTPATH]
                  srtpaths [srtpaths ...]

Clean subtitles deleting items that matches entries in blacklist file. Useful
to remove ads and misplaced credits

positional arguments:
  srtpaths              SRT file(s) or dir(s) to modify

optional arguments:
  -h, --help            show this help message and exit
  -q, --quiet           Suppress informative messages and summary statistics.
  -v, --verbose         Print additional information for each processed file.
  --recursive, -r       recurse inside directories.
  --input-encoding ENCODING, -e ENCODING
                        Encoding used in subtitles, if known. By default tries
                        to autodetect encoding.
  --input-fallback-encoding FALLBACK_ENCODING, -f FALLBACK_ENCODING
                        Fallback encoding to read subtitles if encoding
                        autodetection fails. [Default: windows-1252]
  --convert OUTPUT_ENCODING, -c OUTPUT_ENCODING
                        Convert subtitle encoding. By default output uses the
                        same encoding as the input.
  --in-place, -i        Overwrite original file instead of outputting to
                        standard output
  --no-backup, -B       When using --in-place, do not create a backup file.
  --no-rebuild-index, -I
                        Do not rebuild subtitles indexes after removing items.
                        Resulting SRT will not be strictly valid, although it
                        will work in most players. Useful when debugging for
                        comparing original and modified subtitles
  --blacklist BLACKLISTPATH, -b BLACKLISTPATH
                        Blacklist file path. [Default:
                        /home/user/.config/srtcleaner/srtcleaner.conf]

Copyright (C) 2021 Rodrigo Silva License: GPLv3 or later, at your choice. See
<http://www.gnu.org/licenses/gpl>

$ srtcleaner --in-place -B -c 'UTF-8' '/data/series/Cosmos/Cosmos.S01E01.srt'
[INFO ] Processing subtitle: '/data/series/Cosmos/Cosmos.S01E01.srt'
[INFO ] 27      00:01:00,000 --> 00:01:06,074   Advertise your product or brand here    contact www.OpenSubtitles.org today
[INFO ] 649     00:42:03,305 --> 00:42:09,768   Support us and become VIP member        to remove all ads from www.OpenSubtitles.org
[INFO ] 2 items deleted

Configuring

SRT Cleaner will remove any entries that matches any record on its blacklist file, located by default at ~/.config/srtcleaner/srtcleaner.conf. Create or edit it before using srtcleaner.

A record can span over multiple lines, so use a blank line to separate each record. Its text is matched against each SRT entry by a simple text in entry comparison, in case-insentive way. So if the whole text is found as part of an entry, the whole entry is removed from the SRT file. Escape sequences such as '\n' or '\t' are also interpreted, use it when you want to include a newline at the end of the text to match.

Example of a basic srtcleaner.conf:

OpenSubtitles.org

facebook.com/

fb.com/

@gmail.com

Resync

Legendas:\n

UNITED4EVER

UNITED
Quality is everything

<b>UNITED
Qualidade É Tudo</b>

INSUBS\n

L.O.T.S\n

Requirements

Note: There are (at least) 3 python modules named magic available on PyPI, all wrappers to libmagic, but with very distinct API:

SRT Cleaner supports any of the above libmagic wrappers, and on install pulls the one from the file/libmagic project. And all of them obviously requires libmagic to be installed on your system. It usually ships in the file package and comes pre-installed in most GNU/Linux distributions and MacOS.

On Windows, the following could be used to install libmagic:

Installing

From Git:

git clone https://github.com/MestreLion/srtcleaner
cd stcleaner
pip install --user -e .

From PyPi:

pip install --user srtcleaner

Contributing

Patches are welcome! Fork, hack, request pull!

If you find a bug or have any enhancement request, please open a new issue

Author

Rodrigo Silva (MestreLion) linux@rodrigosilva.com

License and Copyright

Copyright (C) 2021 Rodrigo Silva (MestreLion) <linux@rodrigosilva.com>.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

srtcleaner-1.0.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distributions

srtcleaner-1.0.0-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

srtcleaner-1.0.0-py2-none-any.whl (24.7 kB view details)

Uploaded Python 2

File details

Details for the file srtcleaner-1.0.0.tar.gz.

File metadata

  • Download URL: srtcleaner-1.0.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/2.7.17

File hashes

Hashes for srtcleaner-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6babac6f8e333897857c3d146958e0be6a642311680a4f46d886e4f06ac4542a
MD5 8b48678f6994d5c3993452084c0be8dd
BLAKE2b-256 bde5358169df0bcc605668fbc2960695da11bf72a976fcbd2091cddee77243cc

See more details on using hashes here.

File details

Details for the file srtcleaner-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: srtcleaner-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/2.7.17

File hashes

Hashes for srtcleaner-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f476a1e02ff3ea63bca3c4e982c4b1312cee886f4aa4ee1823c1f13fc03baa1e
MD5 dd57be5f2b3304c88b8296190930651b
BLAKE2b-256 a05b3aaa4d3ffdf0876e61a79cdee4b8da4fd509e7da213b96a2bee20e498069

See more details on using hashes here.

File details

Details for the file srtcleaner-1.0.0-py2-none-any.whl.

File metadata

  • Download URL: srtcleaner-1.0.0-py2-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/2.7.17

File hashes

Hashes for srtcleaner-1.0.0-py2-none-any.whl
Algorithm Hash digest
SHA256 682be27cf857565216464b8593f3ca694bdc43446938f51c6013ef85b9517edb
MD5 738a1f4392758bd9bec75250d0c6122b
BLAKE2b-256 b20bc207cda499730e567a67e38082b7498fd066c69020cfe791ce4547ad89a2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page