Skip to main content

subtitle-filter

PyPI version

Filter .srt subtitle files to remove SDH (Deaf or Hard-of-Hearing) entries and other tags.

Installation

pip install subtitle-filter

Usage

subtitle-filter can be used either as a script or a module.

By default, this module filters the following (in order):

  1. Removes font tags and text contained within, e.g. <font color="#DF01D7">Hey\</font> is removed.
  2. Removes subtitle entries containing only asterisks: *.
  3. Removes subtitle lines containing or #.
  4. Removes sound effects: text contained with and including parenthesis (BANG), asterisks *whisper*, brackets [boom], and text contained within forward slashes /POW/.
  5. Replaces names with dashes, e.g. GARY: Hey or Gary: Hey to - Hey.
  6. Removes author tags e.g. XoXo Subtitles by PwnedDude967 XoXo.
  7. Fixes erroneous comma spacing, e.g. Hey , what's up? Nothing,my man to Hey, what's up? Nothing, my man.
  8. Removes lone symbols such as ?, -, #, _.
  9. Remove leading dashes - if there is only one line present.

Script Usage

Bring up the help display:

filter-subtitles.py -h

Filter a subtitle in place (overwrites original subtitle) with default options.

filter-subtitles.py -s /path/to/sub.srt

Instead of saving to disk, print the output.

filter-subtitles.py -s /path/to/sub.srt -p

Save the output to a different filepath.

filter-subtitles.py -s /path/to/sub.srt -o /path/to/outsub.srt

Custom filter flags.

--keep-fonts          Do not remove font tags and text contained within.
--keep-ast            Do not remove subtitles containing asterisks: (*).
--keep-music          Do not lines containing 1 or more "♪" symbols.
--keep-effects        Do not remove text between and including parenthesis
                        () or brackets []
--keep-names          Do not replace names in CAPITALS with "-" tags
--keep-author         Do not remove author tags, eg. Subtitles by some guy.
--keep-lone-dashes    Do not remove the dash if only one dashed line is present.
--keep-commas         Do not fix comma spacings.

Module Usage

Filter a subtitle in place (overwrites original subtitle) with default options

from subtitle_filter import Subtitles

subs = Subtitles('/path/to/sub.srt')
subs.filter()
subs.save()

Instead of saving to disk, print the output.

subs.print()

Save the output to a different filepath.

subs.save('/path/to/newsub.srt')

Use custom filter flags.

subs.filter(
    rm_fonts=True,
    rm_ast=False,
    rm_music=True,
    rm_effects=True,
    rm_names=False,
    rm_author=False,
)

Issues & Requests

If you spot any issues with the filtered subtitles, or would like to request new features, please create an issue on GitHub and provide examples.

Release files for subtitle-filter 1.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 subtitle-filter 1.5.1
File Size Uploaded
subtitle_filter-1.5.1.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for subtitle-filter 1.5.1
File Interpreter ABI Platform
subtitle_filter-1.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.3 kB

Release files / subtitle_filter-1.5.1.tar.gz

Download URL subtitle_filter-1.5.1.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3923f5e67f5358651e79974ccda325a84add96d5777cb6c71fc61b0d40badd73
BLAKE2b-256 checksum
How to use checksums
476c2a6200013d673700dd60562796560677c06822b09a05f2b35b6b754ec92a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / subtitle_filter-1.5.1-py3-none-any.whl

Download URL subtitle_filter-1.5.1-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
193d4f087dd044b63cfa037e3ec4ffec284c7192c6b3360426ced0b9bf9f0f0f
BLAKE2b-256 checksum
How to use checksums
c4d4268b7ad0099a6825c93476301be07eebe63f4e9e85b050e01f4c4560911d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

1.5.1 This release

2 release files

1.5.0

2 release files

1.4.10

2 release files

1.4.9

2 release files

1.4.8

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

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