Fix torrent processing issues in transmission_handler.sh
- Fix quote handling in transmission-remote commands - Add robust handling for empty torrent IDs - Improve path handling for empty directories - Update version to 9.1 with shared directory handling - Fix empty array subscript errors On branch main Your branch is up to date with 'origin/main'. Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: README.md modified: etc/torrent/mover.conf modified: install.sh new file: usr/local/bin/smart-processor modified: usr/local/bin/torrent-mover new file: usr/local/bin/torrent-processor modified: usr/local/lib/torrent-mover/common.sh modified: usr/local/lib/torrent-mover/transmission_handler.sh
This commit is contained in:
@@ -115,7 +115,19 @@ main() {
|
||||
declare -A warned_dirs=()
|
||||
|
||||
# Get list of torrents from Transmission
|
||||
get_torrents | while read -r id; do
|
||||
log_debug "Getting list of torrents..."
|
||||
local torrent_ids
|
||||
torrent_ids=$(get_torrents)
|
||||
log_debug "Found $(echo "$torrent_ids" | wc -l) torrents"
|
||||
|
||||
echo "$torrent_ids" | while read -r id; do
|
||||
# Skip empty IDs
|
||||
if [[ -z "$id" ]]; then
|
||||
log_debug "Skipping empty torrent ID"
|
||||
continue
|
||||
fi
|
||||
|
||||
log_debug "Processing torrent ID: $id"
|
||||
local info
|
||||
info=$(get_torrent_info "${id}")
|
||||
|
||||
@@ -134,19 +146,62 @@ main() {
|
||||
# Extract Transmission-reported directory and translate to local path.
|
||||
local reported_dir
|
||||
reported_dir=$(grep -i "Location:" <<< "${info}" | awk -F": " '{print $2}' | xargs)
|
||||
log_debug "Raw reported directory: '${reported_dir}'"
|
||||
|
||||
# If the reported directory is empty, try to derive it from the name
|
||||
if [[ -z "${reported_dir}" ]]; then
|
||||
local name
|
||||
name=$(grep -i "Name:" <<< "${info}" | awk -F": " '{print $2}' | xargs)
|
||||
log_debug "Torrent name: '${name}'"
|
||||
|
||||
# Check if there are labels we can use
|
||||
local labels
|
||||
labels=$(grep -i "Labels:" <<< "${info}" | awk -F": " '{print $2}' | xargs)
|
||||
log_debug "Torrent labels: '${labels}'"
|
||||
|
||||
if [[ "${labels}" == *"Books"* ]]; then
|
||||
reported_dir="/downloads/Books"
|
||||
elif [[ "${labels}" == *"Movies"* ]]; then
|
||||
reported_dir="/downloads/Movies"
|
||||
elif [[ "${labels}" == *"TV"* ]]; then
|
||||
reported_dir="/downloads/TV"
|
||||
elif [[ "${labels}" == *"Games"* ]]; then
|
||||
reported_dir="/downloads/Games"
|
||||
elif [[ "${labels}" == *"Apps"* ]]; then
|
||||
reported_dir="/downloads/Apps"
|
||||
elif [[ "${labels}" == *"Music"* ]]; then
|
||||
reported_dir="/downloads/Music"
|
||||
else
|
||||
# Default to Other if we can't determine
|
||||
reported_dir="/downloads/Other"
|
||||
fi
|
||||
log_debug "Derived directory from labels: '${reported_dir}'"
|
||||
fi
|
||||
|
||||
local dir
|
||||
dir=$(translate_source "${reported_dir}")
|
||||
log_info "Torrent source directory reported: '${reported_dir}' translated to '${dir}'"
|
||||
log_info "Torrent source directory: '${reported_dir}' translated to '${dir}'"
|
||||
|
||||
# Initialize empty directory mapping if needed
|
||||
if [[ -z "$dir" ]]; then
|
||||
log_warn "Empty directory path detected, using default"
|
||||
dir="${LOCAL_PATH_PREFIX}/Other"
|
||||
fi
|
||||
|
||||
local dst
|
||||
dst=$(get_destination "${dir}")
|
||||
[[ -z "${warned_dirs["${dir}"]+x}" ]] && warned_dirs["${dir}"]=0
|
||||
|
||||
# Initialize warned_dirs for this directory if needed
|
||||
if [[ -n "${dir}" ]]; then
|
||||
[[ -z "${warned_dirs["${dir}"]+x}" ]] && warned_dirs["${dir}"]=0
|
||||
fi
|
||||
|
||||
# Avoid processing the same directory more than once.
|
||||
if [[ -n "${processed_source_dirs["${dir}"]+x}" ]]; then
|
||||
log_info "Directory ${dir} has already been processed; skipping copy for torrent ${id}"
|
||||
elif (( $(bc <<< "${percent_done} >= 100") )) && ! is_processed "${hash}"; then
|
||||
log_info "Processing completed torrent ${id} (${percent_done}% done)"
|
||||
if [[ "${dst}" == "${DEFAULT_DST}" ]] && (( warned_dirs["${dir}"] == 0 )); then
|
||||
if [[ "${dst}" == "${DEFAULT_DST}" ]] && [[ -n "${dir}" ]] && (( warned_dirs["${dir}"] == 0 )); then
|
||||
log_warn "Using default destination for: ${dir}"
|
||||
warned_dirs["${dir}"]=1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user