Skip to content

Conversation

@yxrpsrazfyg
Copy link

@yxrpsrazfyg yxrpsrazfyg commented Nov 26, 2025

#2418

How to Enable

OptionsDownloads"Advanced filtering mode"
Configure:

  • Target tag: Select a specific tag to filter only tagged torrents (optional)
  • Min/Max file size: Set file size limits in KB, MB, or GB
  • Whitelist patterns: Add regex patterns (one per line) for files that should always be downloaded
  • Blacklist patterns: Add regex patterns (one per line) for files that should be excluded

Functionality Added

  • When a whitelist is configured: Files matching whitelist patterns are always downloaded; non-whitelisted files are excluded if they violate size constraints or match blacklist patterns
  • When no whitelist is set: Files are excluded if they violate size constraints or match blacklist patterns
  • Size filters support KB, MB, and GB units for user convenience
  • Regex patterns are automatically anchored to match complete filenames

Files Changed

Backend (Core Logic)

  • src/base/bittorrent/session.h
  • src/base/bittorrent/sessionimpl.h
  • src/base/bittorrent/sessionimpl.cpp

Desktop GUI

  • src/gui/optionsdialog.h
  • src/gui/optionsdialog.cpp
  • src/gui/optionsdialog.ui

Web UI

  • src/webui/www/private/views/preferences.html

Web API

  • src/webui/api/appcontroller.cpp

API Changes

Web API Preferences Endpoints

  • advanced_filter_enabled (boolean): Enable/disable the feature
  • advanced_filter_target_tag (string): Tag name for targeted filtering (optional)
  • advanced_filter_min_file_size (integer): Minimum file size (optional)
  • advanced_filter_max_file_size (integer): Maximum file size (optional)
  • advanced_filter_whitelist_patterns (string): whitelist regex patterns (optional)
  • advanced_filter_blacklist_patterns (string): blacklist regex patterns (optional)

Backward Compatibility

  • All changes are fully backward compatible
  • Existing functionality remains unchanged when advanced filter is disabled
  • No breaking changes to existing API methods
  • New API methods extend the interface without modifying existing methods
  • Still hopefully, maintainers or contributors can step in and help out.

Perhaps my code wasn’t quite “maintainer material” 🌱—no worries! It’s been a solid month since the PR, so I’ve rolled my own little sh script (curl + jq, webapi-based) for personal use.

I trimmed a few bits for my own needs (no new features—the PR remains the “full edition”), but it’s easy to tweak if anyone’s interested. Both the PR and this script have clocked 100+ hours on Windows/Linux without a hiccup (that my humble skills could spot, anyway).

Script below

Run: Options-Run external program on torrent added-/path/to/.sh "%K"

#!/bin/sh

WEBUI_URL="http://localhost:000000"
USERNAME="000000"
PASSWORD="000000"
TARGET_TAG="000000"
WHITELIST_PATTERN="000000"
BLACKLIST_PATTERN="000000"
MIN_FILE_SIZE=$((1*2*3*4))

sid=$(curl -s -i -d "username=$USERNAME&password=$PASSWORD" "$WEBUI_URL/api/v2/auth/login" | grep -i '^set-cookie:' | sed 's/.*\(SID=[^;]*\).*/\1/')

curl -s -b "$sid" "$WEBUI_URL/api/v2/torrents/info?hashes=$1" | jq -e --arg tag "$TARGET_TAG" '.[0].tags // "" | contains($tag)' >/dev/null || exit 0

excl=$(curl -s -b "$sid" "$WEBUI_URL/api/v2/torrents/files?hash=$1" | jq -r --argjson min "$MIN_FILE_SIZE" --arg white "$WHITELIST_PATTERN" --arg black "$BLACKLIST_PATTERN" '
  [
    .[] | select(
      (if $white != "" then (.name | test($white; "i") | not) else true end) and
      ((.size < $min) or (if $black != "" then (.name | test($black; "i")) else false end))
    ) | .index
  ] | join("|")
')

[ -n "$excl" ] && curl -s -b "$sid" -d "hash=$1&id=$excl&priority=0" "$WEBUI_URL/api/v2/torrents/filePrio" >/dev/null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant