Montag is a utility which reads e-book files and scrubs them of profanity.
Project description
Montag
"Didn't firemen prevent fires rather than stoke them up and get them going?"
montag is a utility which reads an e-book file (in any format supported by Calibre's ebook-convert) and scrubs it of profanity (or words from any other list you can provide).
There are all sorts of arguments to be had about obscenity filters, censorship, etc. That's okay! I'm not really interested in having those arguments. My 13 year-old daughter asked me if I could take some swear words out of a young adult novel she was reading so I wrote this for her. If it's useful to you, great. If not, carry on my wayward son.
montag is part of a family of projects with similar goals:
- 📼 cleanvid for video files
- 🎤 monkeyplug for audio files
- 📕 montag for ebooks
Installation
Using pip
, to install the latest release from PyPI:
python3 -m pip install -U montag-cleaner
Or to install directly from GitHub:
python3 -m pip install -U 'git+https://github.com/mmguero/montag'
Prerequisites
Python Prerequisites
Montag requires Python 3 and the EbookLib and python-magic libraries. It also uses some utilities from the Calibre project.
On a Debian-based Linux distribution, these requirements could be installed with:
$ sudo apt-get install libmagic1 imagemagick calibre-bin python3 python3-magic python3-ebooklib
On Windows, you'll need DLLs for libmagic
. One option for installing these libraries is python-magic-bin
:
python3 -m pip install python-magic-bin
The Python dependencies should be installed automatically if you are using pip
to install montag.
Docker
Alternately, a Dockerfile is provided to allow you to run Montag in Docker. You can build the ghcr.io/mmguero/montag:latest
Docker image with build_docker.sh
, then use montag-docker.sh
to process your e-book files.
Usage
Montag is easy to use. Specify the input and output e-book filenames, and, optionally, the file containing the words to be censored (one per line) and the text encoding.
$ ./montag.py
usage: montag.py [options]
e-book profanity scrubber
required arguments:
-i <STR>, --input <STR>
Input file
-o <STR>, --output <STR>
Output file
-w <STR>, --word-list <STR>
Profanity list text file (default: swears.txt)
-e <STR>, --encoding <STR>
Text encoding (default: utf-8)
So, using Andy Weir's "The Martian" as an example:
$ ./montag.py -i "The Martian - Andy Weir.mobi" -o "The Martian - Andy Weir (scrubbed).mobi"
Processing "The Martian - Andy Weir.mobi" of type "Mobipocket E-book "The Martian", 775003 bytes uncompressed, version 6, codepage 65001"
Extracting metadata...
Converting to EPUB...
Processing book contents...
Generating output...
Converting...
Restoring metadata...
Upon opening the book, you will find the text reads something like this:
CHAPTER 1
LOG ENTRY: SOL 6
I’m pretty much ******.
That’s my considered opinion.
******.
Six days into what should be the greatest two months of my life, and it’s turned into a nightmare.
...
Alternately, if you are using the Docker method described above, use montag-docker.sh
rather than montag.py
directly.
Known Limitations
Montag is not smart enough to do any in-depth language analysis or deep filtering. For a while I was trying to use the rominf/profanity-filter library for the word detection and filtering, but I ran into issues and ended up just going with a simpler method that works but presents a few limitations:
- Only whole words are matched and censored. In other words, if the word
frick
is in your list of profanity,Frick you!
will be censored, butAbsofrickenlutely
will not. As such if you wish to catch all of the variations of the wordfrick
, you'd have to list them individually in yourswears.txt
word list. - Having phrases (eg., multiple space-separated words) in your
swears.txt
word list won't do you any good. - Montag can't tell the difference between different meanings of the same word. For example, if the word
ass
is in your list, both "And he said unto his sons, Saddle me the ass. So they saddled him the ass: and he rode thereon" (from the KJV of The Bible) and "Then the high king carefully turned the golden screw. Once: Nothing. Twice: Nothing. Then he turned it the third time, and the boy’s ass fell off" (from Patrick Rothfuss' The Wise Man's Fear) will be censored.
Contributing
If you'd like to help improve Montag, pull requests will be welcomed!
Authors
- Seth Grover - Initial work - mmguero
License
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
Acknowledgments
Thanks to:
- Calibre developer Kovid Goyal and contributors
- the contributors to EbookLib
- python-magic developer Adam Hupp and contributors
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
Built Distribution
File details
Details for the file montag-cleaner-1.0.4.tar.gz
.
File metadata
- Download URL: montag-cleaner-1.0.4.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d23392206473aec84f317e856b5ff66a7637dc01ff15f26c6a8db60066d9b97 |
|
MD5 | 6e15ea63fb98147efd804c0d756f5e69 |
|
BLAKE2b-256 | 2934e6cb8849467949bd219c0578be5d544e6f0f164fce7cb62ab23b87f15c8c |
File details
Details for the file montag_cleaner-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: montag_cleaner-1.0.4-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 884b49059077d13cfa79f6beb60a44c57d7b59b95fc0b46a9acd2c071ef9031b |
|
MD5 | d2c1e6c96cd174aa7a5f84955561f05c |
|
BLAKE2b-256 | 240a9414aa9ab0a0c1426310b1c6482d034f27fc51ed73786e41915d4199e41c |