Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Vyacheslav Levit <dev@vlevit.org>
Jure Vengušt <jure.vengust@gmail.com>
Artem Mygaiev <joculator@gmail.com>
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ Usage
transmission-batch-move [OPTIONS] PATTERN REPLACEMENT

The script will search PATTERN (regex) and replace it with REPLACEMENT
in all destination properties of Transmission resume files in
`~/.config/transmission/resume` directory. It will recalculate lengths
of new destination paths, so resume files should not break. All
original resume files are backed up. To be on the safe side make a
backup before running the script yourself.
in all destination or incomplete-dir properties of Transmission resume
files in `~/.config/transmission/resume` directory. It will recalculate
lengths of new paths, so resume files should not break. All original
resume files are backed up. To be on the safe side make a backup before
running the script yourself.

Options
=======

-h, --help Displays this help.
-y, --yes Ignore safety prompt.
--path=PATH Specify configuration directory where resume folder
is located. Default is "~/.config/transmission"
-h, --help Displays this help.
-y, --yes Ignore safety prompt.
-d, --destination Change destination location.
-i, --incomplete-dir Change incomplete directory location.
--path=PATH Specify configuration folder where resume directory
is located. Default is "~/.config/transmission"

Transmission daemon on Debian / Ubuntu
======================================
Expand All @@ -31,4 +33,4 @@ For Debian and derivative distributions Transmission daemon
configuration directory is set to `/var/lib/transmission-daemon/info`
by default. So pass `--path` as follows:

transmission-batch-move --path=/var/lib/transmission-daemon/info PATTERN REPLACEMENT
transmission-batch-move --path=/var/lib/transmission-daemon/info -i PATTERN REPLACEMENT
35 changes: 28 additions & 7 deletions transmission-batch-move
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ Usage: ${0##*/} [OPTIONS] PATTERN REPLACEMENT
Change all torrents location. Do NOT move actual downloaded files,
just change their location in *.resume files.

It is mandatory to specify which location must be changed - either
'destination' or 'incomplete-dir'.

Options:
-h, --help Displays this help.
-y, --yes Ignore safety prompt.
--path=PATH Specify configuration folder where resume directory
is located. Default is "$CONFIG"
-h, --help Displays this help.
-y, --yes Ignore safety prompt.
-d, --destination Change destination location.
-i, --incomplete-dir Change incomplete directory location.
--path=PATH Specify configuration folder where resume directory
is located. Default is "$CONFIG"
EOF
}

Expand All @@ -39,6 +44,16 @@ case $i in
REPLY=y
shift
;;
-d|--download-dir)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-d|--download-dir)
-d|--destination)

right?

OFFSET=14
TOKEN="11:destination"
shift
;;
-i|--incomplete-dir)
OFFSET=17
TOKEN="14:incomplete-dir"
shift
;;
*)
# ignore positional arguments
;;
Expand All @@ -53,6 +68,11 @@ if (( $# != 2 )); then
exit 2
fi

if [ -z $OFFSET ]; then
help
exit 2
fi

if test ! -d "${RESUME}"; then
echo "error: $RESUME doesn't exist or is not a directory"
exit 1
Expand All @@ -66,6 +86,7 @@ fi
echo "Transimission configuration folder: $CONFIG"
echo "Resume files folder: $RESUME"
echo "Backup folder: $ORIG"
echo "Changing: $TOKEN"
echo "PATTERN: $1"
echo "REPLACEMENT: $2"

Expand Down Expand Up @@ -95,10 +116,10 @@ do
echo "processing $(basename "$file")"

# calculate destination position
dest=$(grep -aob "11:destination[0-9]\+" "$file")
dest=$(grep -aob "$TOKEN[0-9]\+" "$file")
old_len=$(grep -o "[0-9]\+$" <<< "$dest")
pos=$(grep -o "^[0-9]\+" <<< "$dest")
end=$(($pos+14+${#old_len}+1+$old_len))
end=$(($pos+$OFFSET+${#old_len}+1+$old_len))

# fetch the destination path, make the substitution
old_path="$(head -c $end "$file"| tail -c $old_len)"
Expand All @@ -111,7 +132,7 @@ do

# new path length in bytes, not characters
new_len=$(echo -n "$new_path" | wc -c)
new_dest="11:destination${new_len}:${new_path}"
new_dest="$TOKEN${new_len}:${new_path}"

# write temporary file and replace the original one
tmpfile="${file}.tmp.$$"
Expand Down