Last active
April 26, 2026 17:11
-
-
Save Mubelotix/9e398f7e7bc966ecd5827fd0aadfb45d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Calculate ratio per day for torrents managed by transmission-daemon | |
| # Adds a lock emoji for private tracker torrents. | |
| # | |
| set -euo pipefail | |
| TR_CMD="transmission-remote" | |
| echo "Fetching torrent list..." | |
| # Get IDs, ignoring the header and footer | |
| TORRENT_IDS=$($TR_CMD --list | awk 'NR>1 && $1 ~ /^[0-9]+(\*?)$/ {gsub(/[^0-9]/,"",$1); print $1}') | |
| printf "%-5s | %-8s | %-10s | %-10s | %s\n" "ID" "Ratio" "Days" "Ratio/Day" "Name" | |
| printf "%0.s-" {1..100}; echo | |
| RESULTS=() | |
| for ID in $TORRENT_IDS; do | |
| INFO=$($TR_CMD -t "$ID" --info) | |
| # Parsing fields using awk | |
| NAME=$(echo "$INFO" | awk -F': ' '/Name:/ {print substr($0, index($0,$2))}') | |
| RATIO=$(echo "$INFO" | awk -F': ' '/Ratio:/ {print $2}') | |
| IS_PUBLIC=$(echo "$INFO" | awk -F': ' '/Public torrent:/ {print $2}') | |
| # Extract seeding days | |
| SEED_DAYS=$(echo "$INFO" | awk -F'[ ()]+' '/Seeding Time:/ { | |
| for (i=1;i<=NF;i++) { | |
| if ($i=="days") {print $(i-1); exit} | |
| } | |
| }') | |
| # Skip if seeding for less than 10 days or if SEED_DAYS is empty | |
| if [[ -z "$SEED_DAYS" || "$SEED_DAYS" -lt 10 ]]; then | |
| continue | |
| fi | |
| # Determine if private tracker (Public torrent: No) | |
| LOCK_ICON="" | |
| if [[ "$IS_PUBLIC" == "No" ]]; then | |
| LOCK_ICON="🔒 " | |
| fi | |
| # Calculate Ratio/Day | |
| RATIO_PER_DAY=$(awk "BEGIN {printf \"%.3f\", $RATIO / $SEED_DAYS}") | |
| # Store result (using a tab or unique delimiter for the name to handle spaces) | |
| RESULTS+=("$ID|$RATIO|$SEED_DAYS|$RATIO_PER_DAY|$LOCK_ICON$NAME") | |
| done | |
| # Sort by ratio per day descending | |
| # We use -t'|' to tell sort that the delimiter is the pipe character | |
| IFS=$'\n' SORTED=($(sort -t'|' -k4 -nr <<<"${RESULTS[*]}")) | |
| unset IFS | |
| for ENTRY in "${SORTED[@]}"; do | |
| IFS='|' read -r ID RATIO SEED_DAYS RATIO_PER_DAY NAME <<<"$ENTRY" | |
| printf "%-5s | %-8s | %-10s | %-10s | %s\n" "$ID" "$RATIO" "$SEED_DAYS" "$RATIO_PER_DAY" "$NAME" | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output and usage: