Last active
June 19, 2026 15:24
-
-
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 and a sprout emoji for new ones. | |
| # | |
| set -euo pipefail | |
| TR_CMD="transmission-remote" | |
| echo "Fetching torrent list..." | |
| # Get IDs, safely stripping out error asterisks without dropping the line | |
| TORRENT_IDS=$($TR_CMD --list | awk 'NR>1 {print $1}' | grep -E '^[0-9]+\*?$' | tr -d '*') | |
| 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))}') | |
| RAW_RATIO=$(echo "$INFO" | awk -F': ' '/Ratio:/ {print $2}') | |
| IS_PUBLIC=$(echo "$INFO" | awk -F': ' '/Public torrent:/ {print $2}') | |
| # Strip commas out of ratios (e.g. "1,129" -> "1129") so awk doesn't break | |
| CLEAN_RATIO=$(echo "$RAW_RATIO" | tr -d ',') | |
| RATIO=$(awk "BEGIN {printf \"%.2f\", $CLEAN_RATIO}") | |
| # Extract seeding days | |
| SEED_DAYS=$(echo "$INFO" | awk -F'[ ()]+' '/Seeding Time:/ { | |
| for (i=1;i<=NF;i++) { | |
| if ($i=="days") {print $(i-1); exit} | |
| } | |
| }') | |
| # Track if it's a new torrent (< 10 days or empty) for the emoji tag | |
| NEW_ICON="" | |
| DISPLAY_DAYS="$SEED_DAYS" | |
| if [[ -z "$SEED_DAYS" || "$SEED_DAYS" -lt 10 ]]; then | |
| NEW_ICON="🌱 " | |
| if [[ -z "$SEED_DAYS" ]]; then | |
| DISPLAY_DAYS=0 | |
| fi | |
| fi | |
| # Determine if private tracker (Public torrent: No) | |
| LOCK_ICON="" | |
| if [[ "$IS_PUBLIC" == "No" ]]; then | |
| LOCK_ICON="🔒 " | |
| fi | |
| # Calculate Ratio/Day safely using your real values | |
| # If SEED_DAYS is 0 (less than a day old), we divide by 1 to show the real ratio accumulation | |
| MATH_DAYS="$SEED_DAYS" | |
| if [[ -z "$MATH_DAYS" || "$MATH_DAYS" -eq 0 ]]; then | |
| MATH_DAYS=1 | |
| fi | |
| RATIO_PER_DAY=$(awk "BEGIN {printf \"%.3f\", $RATIO / $MATH_DAYS}") | |
| # Store result (using a pipe delimiter for the name to handle spaces) | |
| RESULTS+=("$ID|$RATIO|$DISPLAY_DAYS|$RATIO_PER_DAY|$NEW_ICON$LOCK_ICON$NAME") | |
| done | |
| # Sort by ratio per day descending | |
| 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: