Python script to detect toot screenshots in Mastodon public timelines
Find a file
2024-10-28 20:08:44 +01:00
bot_mastodon.py Atualizar bot_mastodon.py 2024-10-28 19:46:21 +01:00
LICENSE Enviar arquivos para "/" 2024-10-28 19:42:07 +01:00
Readme.md Atualizar Readme.md 2024-10-28 20:08:44 +01:00

Mastodon Screenshot Detection Bot

Overview

This script is a bot designed to monitor your personal Mastodon instance for potential screenshots of your posts. It utilizes Optical Character Recognition (OCR) to analyze images shared in toots and checks if they contain any fragments of your username or other specified text. This is particularly useful for individuals who want to track unauthorized sharing or reposting of their content across their instance.

Features

  • Image Monitoring: The bot listens for images shared in toots across your Mastodon instance, including posts from multiple accounts you manage.
  • Text Recognition: It employs the pytesseract library to extract text from images using OCR, allowing it to detect your username or any specified text.
  • Real-Time Notifications: When a potential screenshot of your post is detected, the bot sends a direct notification to your Mastodon account, ensuring you're always informed about how your content is being used.
  • Customizable Usernames: You can easily modify the list of usernames or keywords the bot should look for, making it adaptable to your specific needs.

Dependencies

To run this script, you need to have the following dependencies installed on your server:

  1. Python 3.x
  2. Pillow: For image processing.
    • pip3 install pillow
  3. pytesseract: For Optical Character Recognition.
    • pip3 install pytesseract
  4. requests: For making HTTP requests.
    • pip3 install requests
  5. Mastodon.py: The Mastodon API wrapper for Python.
    • pip3 install Mastodon.py
  6. Tesseract OCR: Ensure Tesseract is installed on your system. Installation instructions vary by operating system:
    • Ubuntu/Debian:
      • sudo apt install tesseract-ocr

Implementation

To set up the bot with your Mastodon account, follow these steps:

  1. Create a New Application:

    • Go to your Mastodon instance in a web browser.
    • Log in to your account.
    • Navigate to Settings > Development > New Application.
    • Fill in the necessary details (you can use any name and redirect URI).
    • Click Save, and note down the Access Token provided.
  2. Configure the Script: Open the script file and replace the placeholders with your actual Mastodon API token and instance URL:

    mastodon = Mastodon(
        access_token='YOUR_API_TOKEN',
        api_base_url='https://YOUR_MASTODON_INSTANCE'
    )
    
  3. Configure the Script: Replace the words that identify your account and you are looking for:

    # Check if it contains fragments of your posts
    if 'nickname' in text_in_image or 'Name' in text_in_image:
    
  4. Run the bot: Execute the script to start monitoring for screenshots.

    • python3 bot_mastodon.py