Refinarr is a command-line tool that goes beyond filtering and deleting torrents from qBittorrent. In addition to its original functionality, Refinarr now integrates with Sonarr to handle tasks such as renaming episode files based on updated series information. (Radarr integration is also included as a framework for future enhancements.) The project leverages environment variables to manage sensitive data and configuration details.
- Login: Connects to the qBittorrent WebUI API.
- Torrent Filtering: Lists and filters torrents based on configurable thresholds (age, last activity, popularity, etc.).
- Pretty-Printed Output: Displays torrent details in a colorful, boxed format.
- Interactive Deletion: Provides a prompt to confirm deletion, skip torrents, or delete all remaining torrents interactively.
- Series Processing: Retrieves series data from Sonarr.
- Episode Renaming: Identifies episodes (via a defined set of criteria) and issues rename commands so that files are renamed based on updated series metadata.
- Framework Ready: Radarr functionality is added as a basis for future development. (Currently, Radarr methods are stubbed and do nothing.)
- All configuration and credentials are managed via environment variables.
- For local usage, a .env file can be used.
- For Docker deployments, environment variables are supplied via Docker Compose (or other container orchestration tools).
For most users, the recommended approach is to deploy Refinarr using Docker Compose. This method avoids the need to manage a local Python environment manually and allows you to easily supply environment variables.
-
Create a
docker-compose.ymlfile in the project root with the following content:services: refinarr: image: hrolgar/refinearr:latest environment: # qBittorrent Configuration - QBIT_BASE_URL=${QBIT_BASE_URL} - QBIT_USERNAME=${QBIT_USERNAME} - QBIT_PASSWORD=${QBIT_PASSWORD} - QBIT_INTERVAL_MINUTES=120 # Use either QBIT_RUN_TIME or QBIT_INTERVAL_MINUTES, but not both. - QBIT_AGE_THRESHOLD_DAYS=16 - QBIT_LAST_ACTIVITY_THRESHOLD_DAYS=10 # SONARR Configuration - SONARR_BASE_URL=${SONARR_BASE_URL} - SONARR_API_KEY=${SONARR_API_KEY} - SONARR_RUN_TIME=04:00 # Use either SONARR_INTERVAL_MINUTES or SONARR_RUN_TIME, but not both. # RADARR Configuration - RADARR_BASE_URL=${RADARR_BASE_URL} - RADARR_API_KEY=${RADARR_API_KEY} - RADARR_RUN_TIME=04:00 # Use either RADARR_INTERVAL_MINUTES or RADARR_RUN_TIME, but not both. - SLEEP_INTERVAL=60
-
Supply Environment Variables: Set your sensitive environment variables (e.g., QBIT_USERNAME, QBIT_PASSWORD, SONARR_API_KEY, and RADARR_API_KEY) via your host’s environment or by using an .env file that Docker Compose can load.
-
Run Docker Compose:
docker-compose up -d
This will pull (or build) the Refinarr image, launch the container with your specified configuration, and run the application in schedule mode by default.
If you prefer not to use Docker Compose, you can run the container using a single docker run command.
For example:
docker run -d \
-e QBIT_BASE_URL=${QBIT_BASE_URL} \
-e QBIT_USERNAME="${QBIT_USERNAME}" \
-e QBIT_PASSWORD="${QBIT_PASSWORD}" \
-e QBIT_INTERVAL_MINUTES=120 \
-e QBIT_AGE_THRESHOLD_DAYS=16 \
-e QBIT_LAST_ACTIVITY_THRESHOLD_DAYS=10 \
-e SONARR_BASE_URL=${SONARR_BASE_URL} \
-e SONARR_API_KEY="${SONARR_API_KEY}" \
-e SONARR_RUN_TIME="04:00" \
-e RADARR_BASE_URL=${RADARR_BASE_URL} \
-e RADARR_API_KEY="${RADARR_API_KEY}" \
-e RADARR_RUN_TIME="04:00" \
-e SLEEP_INTERVAL=60 \
hrolgar/refinearr:latestIn this setup, the container will always run in schedule mode since its ENTRYPOINT is configured with the --schedule flag.
If you wish to fork Refinarr or run it in a local development environment without Docker Compose: You can set up the project in one of two ways: manually or by using an automated setup script.
If you prefer a one-command setup, you can use the provided shell or batch script. The scripts will:
-
Create the virtual environment (if it does not exist)
-
Activate the virtual environment
-
Install dependencies from
requirements.txt -
Create the
.envfile with default values (if it doesn’t already exist)
Run the following command from the project root:
setup\file.batRun the batch script by either double-clicking the file or executing it from a command prompt:
setup\file.batOnce the appropriate setup script finishes, you can run the main script:
python main.py-
Clone the Repository
git clone https://github.com/Hrolgar/Refinearr.git cd Refinarr -
Create and Activate a Virtual Environment:
-
Unix/macOS:
python -m venv venv source venv/bin/activate- Windows: python -m venv venv venv\Scripts\activate
-
-
Install Dependencies:
pip install -r requirements.txt
-
Create the .env File:
Create a file named .env in the project root and add the environment variables you need. You can use the provided .env.example as a template.
-
Run the Script:
python main.py
This application uses Python’s built-in argparse module to allow configuration via command-line arguments. Currently, we support the following options:
-
--non-interactive: Runs the application in non-interactive mode. In this mode the program automatically deletes all filtered torrents without prompting the user. -
--schedule: Runs the job on a continuous schedule, allowing the application to trigger a daily run for torrent cleanup. The scheduled run time is specified via the RUN_TIME environment variable (default is "02:00").
-
Run once, prompting the user interactively:
python main.py
-
Run once, automatically deleting without user input:
python main.py --non-interactive
-
Run continuously with daily scheduling (non-interactive, recommended for Docker deployments):
python main.py --schedule