You are not logged in.

#1 2010-02-21 06:18:55

HackBug
Member
From: Portland, OR
Registered: 2009-02-06
Posts: 23

Rtorrent move finished files

Okay, I've been looking around and I can't really seem to get a completely clear answer that applies to me, though I may just be misunderstanding things, either way...

So what I am trying to do is, in rtorrent, move a file from the default download directory, to a new directory when it is finished. I know how to do this with files that were started in rtorrent to begin with, but if I move a file that i torrented elsewhere (or specifically in my case, a torrent I created and wanted to seed), into the download directory, the hash will start when rtorrent starts, but the file will remain in the default download directory and not be moved into the finished directory.

As I understand it, this is because the on_finished event isn't called when rtorrent hash checks a already finished file, it is only called when rtorrent itself finishes a file. Does anyone know how to get this working so that when rtorrent sees any file at 100% it automatically moves it to my finished directory?

I hope that was clear enough: here is my .rtorrent.rc:

# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
max_peers_seed = 10

# Maximum number of simultanious uploads per torrent.
#max_uploads = 15

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 1500
upload_rate = 300

# Default directory to save the downloaded torrents.
directory = /home/shared/downloads

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
#session = ./session

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=/home/shared/watch/*.torrent
schedule = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=100M

# Stop torrents when reaching upload ratio in percent,
# when also reaching total upload in bytes, or when
# reaching final upload ratio in percent.
# example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
schedule = ratio,60,60,"stop_on_ratio=200,200M,2000"

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
port_range = 49900-49900

# Start opening ports at a random position within the port range.
#port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
check_hash = yes

# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
encryption = allow_incoming,try_outgoing,enable_retry

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
# 
dht = auto

# UDP port to use for DHT. 
# 
# dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10

#set finished path
system.method.set_key = event.download.finished,move_complete,"execute=mv,-u,$d.get_base_path=,/home/shared/downloads/finished;d.set_directory=/home/shared/downloads/finished"

schedule = throttle_1,00:00:00,24:00:00,download_rate=1500
schedule = throttle_2,10:00:00,24:00:00,download_rate=300

# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
max_peers_seed = 10

# Maximum number of simultanious uploads per torrent.
#max_uploads = 15

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 1500
upload_rate = 300

# Default directory to save the downloaded torrents.
directory = /home/shared/downloads

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
#session = ./session

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=/home/shared/watch/*.torrent
schedule = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=100M

# Stop torrents when reaching upload ratio in percent,
# when also reaching total upload in bytes, or when
# reaching final upload ratio in percent.
# example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
schedule = ratio,60,60,"stop_on_ratio=200,200M,2000"

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
port_range = 49900-49900

# Start opening ports at a random position within the port range.
#port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
check_hash = yes

# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
encryption = allow_incoming,try_outgoing,enable_retry

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
# 
dht = auto

# UDP port to use for DHT. 
# 
# dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10

#set finished path
system.method.set_key = event.download.finished,move_complete,"execute=mv,-u,$d.get_base_path=,/home/shared/downloads/finished;d.set_directory=/home/shared/downloads/finished"

schedule = throttle_1,00:00:00,24:00:00,download_rate=1500
schedule = throttle_2,10:00:00,24:00:00,download_rate=300

Offline

#2 2010-02-21 07:37:15

jwwolf
Member
Registered: 2009-06-29
Posts: 74

Re: Rtorrent move finished files

A workaround
http://www.mail-archive.com/libtorrent- … 01414.html

Last edited by jwwolf (2010-02-21 08:13:04)

Offline

#3 2010-02-21 09:35:21

HackBug
Member
From: Portland, OR
Registered: 2009-02-06
Posts: 23

Re: Rtorrent move finished files

Well, that's good as a temporary solution, but it would be nice to have a more "real" solution to this if one exists.

Offline

#4 2010-06-03 02:41:46

print
Member
Registered: 2007-02-27
Posts: 174

Re: Rtorrent move finished files

It seems like it would be a good idea to include a toggle for move after hash check.  In the mean time, you can update the session hash itself to trick rtorrent.  Here's some very glitchy python code.  Use at your own risk, YMMV, but it worked for me.

Note that this moves files around so use it carefully.

http://gist.github.com/423529

Noah

Last edited by print (2010-06-03 05:52:28)


% whereis whatis whence which whoami whois who

Offline

#5 2010-06-03 05:51:52

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Rtorrent move finished files

It would also be a good idea to post your feature request where the rtorrent dev(s) might actually see it. And it would be an even better idea to include a patch that implements your request.

Offline

#6 2010-06-03 05:54:43

print
Member
Registered: 2007-02-27
Posts: 174

Re: Rtorrent move finished files

Thanks for the additional ideas, tomk.  You just missed my edit; I implemented my fix in python because my c/c++ skills are a little rusty.


% whereis whatis whence which whoami whois who

Offline

#7 2010-07-06 17:39:24

Splex
Member
Registered: 2009-03-09
Posts: 33

Re: Rtorrent move finished files

A solution im using at the moment to move all completed torrents to the correct custom dirs:
1.)Use either the svn version of rtorrent/libtorrent or apply the patch to 0.8.6 that adds 'equal'
2.)Add the following to your ~/.rtorrent.rc :

directory = /path/to/incomplete
schedule = watch_directory_1,10,10,"load=/path/to/.torrents/*.torrent,d.set_custom1=/path/to/complete"
system.method.insert=checkdirs,simple,"not=\"$equal={d.get_custom1=,d.get_base_path=}\""
system.method.insert=movecheck,simple,"and={checkdirs=,d.get_complete=,d.get_custom1=}"
system.method.insert=movedir,simple,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.get_custom1=;d.set_custom1=;d.stop=;d.start="
system.method.set_key=event.download.hash_done,move_hashed,"branch={$movecheck=,movedir=}"

Tha above will process torrents after they are hashed.  If the torrent is 100% done and it has a custom1 variable set and the data is not in the custom1 folder, then a move command will be issued and the custom1 variable will be cleared from the torrent entry.

Offline

#8 2010-07-06 19:05:23

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: Rtorrent move finished files

Can you tell how the variable is set Splex? Is it like adding a label to a torrent? Or is it functionality that gets added with the equal patch only? Do you happen to have a link to the patch?

Edit: checked the rtorrent trac, is this it?

http://libtorrent.rakshasa.no/changeset/1146


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#9 2010-07-06 20:51:05

Splex
Member
Registered: 2009-03-09
Posts: 33

Re: Rtorrent move finished files

.:B:. wrote:

Can you tell how the variable is set Splex? Is it like adding a label to a torrent? Or is it functionality that gets added with the equal patch only? Do you happen to have a link to the patch?

Edit: checked the rtorrent trac, is this it?

http://libtorrent.rakshasa.no/changeset/1146

That looks like the svn change where they added the equal operator, yes.

here is the patch for 0.8.6:
http://ovh.ttdpatch.net/~jdrexler/rt/ol … rator.diff

The custom1 variable is set to the torrent if you drop it into the dir that you specify on the watch_directory_1 event.

I added some comments to help explain what is going on in the scripting

# location where new torrent data is placed, and where you should place your 'complete' data before you place your *.torrent file into the watch folder
directory = /home/user/torrents/incomplete

# a timer event named 'watch_directory_1' that is triggered 10 seconds after rtorrent starts, and every 10 seconds thereafter.  Each time it is triggered, it will attempt to load (and start) new *.torrent files found in /home/user/torrents/watch/
# If a new *.torrent is loaded from this directory, a variable named 'custom1' is added with the value being "/home/user/torrents/complete"
# if you don't want it to automatically start the torrent, change 'load_start' to 'load'
schedule = watch_directory_1,10,10,"load_start=/home/user/torrents/watch/*.torrent,d.set_custom1=/home/user/torrents/complete"

# alias 'checkdirs' = ('current path of torrent data' != 'value of custom1')
# returns true if the values are not equal, false if they are equal
system.method.insert=checkdirs,simple,"not=\"$equal={d.get_custom1=,d.get_base_path=}\""

# alias 'movecheck'  = ('result of checkdirs' && 'torrent is 100% done', 'custom1 variable is set')
# returns true if all 3 commands return true
system.method.insert=movecheck,simple,"and={checkdirs=,d.get_complete=,d.get_custom1=}"

# alias 'movedir'  = (series of commands): "set path of torrent to equal the value of custom1"; "mv -u <current data path> <custom1 path>"; "clear custom1", "stop the torrent","resume the torrent"
# The last 2 commands are used to get the torrent to reset the 'base path' to custom1
system.method.insert=movedir,simple,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.get_custom1=;d.set_custom1=;d.stop=;d.start="

# a key with a name of 'move_hashed' that is attached to the hash_done event.
# When hashing of a torrent completes, a custom key called 'move_hashed' will be called that checks if the movecheck command is true and if so runs the movedir command
# 'branch' is like an 'if' statement
# if(movecheck){movedir}
system.method.set_key=event.download.hash_done,move_hashed,"branch={$movecheck=,movedir=}"

Last edited by Splex (2010-07-06 20:54:50)

Offline

#10 2010-07-06 21:05:24

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: Rtorrent move finished files

Thanks a lot smile.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#11 2011-01-07 20:22:21

maxim9
Member
Registered: 2011-01-07
Posts: 1

Re: Rtorrent move finished files

Wow. This was EXACTLY what I needed to make my setup perfect. I used your commands exactly as you typed them and everything works exactly as I expect it. This really made my day. Thank you Splex!

Offline

#12 2011-04-28 19:11:01

claes
Member
Registered: 2011-04-28
Posts: 1

Re: Rtorrent move finished files

EDIT: Just realized that I had a nonexistent "complete" directory : / All is well now!
Thanks for the code! I'd delete this but the forum won't let me.



Hi! Just installed rtorrent 0.8.6 and patched with bad_peer_handling.diff and equal-operator.diff. All was a success, and so I deleted my .rtsession folder and made a new one and then copied my completed torrents to the directory "/media/joan/torrents/incomplete". I then added your posted code to my .rtorrent.rc but I keep getting "download event action failed: bad return code." What could I be doing wrong/how can I diagnose this?

# location where new torrent data is placed, and where you should place your
# 'complete' data before you place your *.torrent file into the watch folder
directory = /media/joan/torrents/incomplete
 
# schedule a timer event named 'watch_directory_1':
# 1) triggers 10 seconds after rtorrent starts
# 2) triggers at 10 second intervals thereafter
# 3) Upon trigger, attempt to load (and start) new *.torrent files found in /home/user/torrents/watch/
# 4) set a variable named 'custom1' with the value "/home/user/torrents/complete"
# NOTE: if you don't want it to automatically start the torrent, change 'load_start' to 'load'
schedule = watch_directory_1,10,10,"load_start=/home/peggy/Torrents/*.torrent,d.set_custom1=/home/media/joan/torrents/done"
  
# insert a method with the alias 'checkdirs1'
# 1) returns true if the current path of the torrent data is not equal to the value of custom1
# 2) otherwise, returns false
system.method.insert=checkdirs,simple,"not=\"$equal={d.get_custom1=,d.get_base_path=}\""

# insert a method with the alias 'movecheck1'
# 1) returns true if all 3 commands return true ('result of checkdirs1' && 'torrent is 100% done', 'custom1 variable is set')
# 2) otherwise, returns false
system.method.insert=movecheck,simple,"and={checkdirs=,d.get_complete=,d.get_custom1=}"

# insert a method with the alias 'movedir1'
# (a series of commands, separated by ';')
# 1) "set path of torrent to equal the value of custom1";
# 2) "mv -u <current data path> <custom1 path>";
# 3) "clear custom1", "stop the torrent","resume the torrent"
# 4) stop the torrent
# 5) start the torrent (to get the torrent to update the 'base path')
system.method.insert=movedir,simple,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.get_custom1=;d.set_custom1=;d.stop=;d.start="

# set a key with the name 'move_hashed1' that is triggered by the hash_done event.
# 1) When hashing of a torrent completes, this custom key will be triggered.
# 2) when triggered, execute the 'movecheck1' method and check the return value.
# 3) if the 'movecheck' method returns 'true', execute the 'movedir1' method we inserted above.
# NOTE: 'branch' is an 'if' conditional statement: if(movecheck1){movedir1}
system.method.set_key=event.download.hash_done,move_hashed,"branch={$movecheck=,movedir=}"

Note: I originally got the code from the archwiki but on failure rewrote it based on what's in this thread. The completed torrents are never moved so I assume my first problem is in step 3 of the system.method processes. Also, I'm using Xubuntu 10.10, but that shouldn't make a difference?

Last edited by claes (2011-04-28 19:20:31)

Offline

#13 2012-02-02 22:39:20

C5OK5Y
Member
Registered: 2010-07-04
Posts: 48

Re: Rtorrent move finished files

This solution works great but it has one problem. A newly downloaded file stays in 'directory' (the one with unfinished files) and is moved to the path in custom1 only after rehash (which occurs on start of rtorrent so I have to restart rtorrent to get the files moved). Here is suggested to add:

system.method.set_key=event.download.finished,move_complete,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.get_custom1="

After I do so the file gets moved immediately after download completes but then the torrent gets paused (and it don't resume with ^S) and I get:

Download event action failed: Bad return code.

I can either only use http://libtorrent.rakshasa.no/wiki/RTor … hdirectory or only use https://wiki.archlinux.org/index.php/Rt … eted_files (that's the same thing as in this thread) but I can't use them at once. Does anyone know how to combine these two things?
I use rtorrent 0.8.9-2 from community repo and here's my config:

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = ~/Stažené/.torrenty/rtorrent/session/

# Add new views. You may find out what downloads they contain through
# 'ui.current_view.set=group_1' command or XMLRPC calls.
view_add = view_group_1

# Make the views persist across sessions.
view.persistent = view_group_1

# Create new groups, 'group.insert = <name>, <view>'.
group.insert = group_1, view_group_1

group.group_1.ratio.enable=
group.group_1.ratio.min.set=200
group.group_1.ratio.max.set=300
group.group_1.ratio.upload.set=20M

# Watch a directory for new torrents, restart torrents that have been
# copied back and stop those that have been deleted.
schedule = watch_directory_1,5,5,"load_start=~/Stažené/.torrenty/rtorrent/watch/*.torrent,d.set_custom1=~/Stažené/.torrenty"
schedule = watch_dierctory_2,5,5,"load_start=~/Stažené/.torrenty/rtorrent/watch_buffer/*.torrent,d.set_custom1=~/Stažené/.torrenty/buffer"

# Downloads need to be inserted into the view with the 'view.set_visible'
# command. Note that extra parameters to 'load' are commands called
# with the newly created download as the target.
schedule = watch_directory_3,5,5,"load_start=~/Stažené/.torrenty/rtorrent/watch_ratio/*.torrent,d.set_custom1=~/Stažené/.torrenty/ratio,   view.set_visible=view_group_1"
#schedule = tied_directory,5,5,start_tied= # Causes unpausable torrents
schedule = untied_directory,5,5,stop_untied=

system.method.set_key=event.download.finished,move_complete,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.           get_custom1="

# insert a method with the alias 'checkdirs1'
# 1) returns true if the current path of the torrent data is not equal to the value of custom1
# 2) otherwise, returns false
system.method.insert=checkdirs1,simple,"not=\"$equal={d.get_custom1=,d.get_base_path=}\""

# insert a method with the alias 'movecheck1'
# 1) returns true if all 3 commands return true ('result of checkdirs1' && 'torrent is 100% done', 'custom1 variable is set')
# 2) otherwise, returns false
system.method.insert=movecheck1,simple,"and={checkdirs1=,d.get_complete=,d.get_custom1=}"

# insert a method with the alias 'movedir1'
# (a series of commands, separated by ';')
# 1) "set path of torrent to equal the value of custom1";
# 2) "mv -u <current data path> <custom1 path>";
# 3) "clear custom1", "stop the torrent","resume the torrent"
# 4) stop the torrent
# 5) start the torrent (to get the torrent to update the 'base path')
system.method.insert=movedir1,simple,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.get_custom1=;d.set_custom1=;d.    stop=;d.start="

# set a key with the name 'move_hashed1' that is triggered by the hash_done event.
# 1) When hashing of a torrent completes, this custom key will be triggered.
# 2) when triggered, execute the 'movecheck1' method and check the return value.
# 3) if the 'movecheck' method returns 'true', execute the 'movedir1' method we inserted above.
# NOTE: 'branch' is an 'if' conditional statement: if(movecheck1){movedir1}
system.method.set_key=event.download.hash_done,move_hashed1,"branch={$movecheck1=,movedir1=}"

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=100M

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
port_range = 55555-55555

# Start opening ports at a random position within the port range.
#port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
#check_hash = no

# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext
encryption = allow_incoming,try_outgoing,enable_retry

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
#
 dht = auto

# UDP port to use for DHT.
#
 dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
 peer_exchange = yes

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10

# Omezení rychlosti
throttle_up=zpomal,10
throttle_down=zpomal,50

# Správné zobrazování aktivních torrentů
schedule = filter_active,30,30,"view_filter = active,\"or={d.get_up_rate=,d.get_down_rate=}\""

Offline

#14 2012-02-02 23:09:53

Splex
Member
Registered: 2009-03-09
Posts: 33

Re: Rtorrent move finished files

Did you try the following in your rtorrentrc?
check_hash = yes

Offline

#15 2012-02-03 11:52:47

C5OK5Y
Member
Registered: 2010-07-04
Posts: 48

Re: Rtorrent move finished files

Yes I have and it doesn't have any effect.

Offline

#16 2012-04-01 19:22:06

iggy1
Member
Registered: 2012-04-01
Posts: 2

Re: Rtorrent move finished files

This will only work when torrents are hashed (when they are added AND when they are finished if the 'check_hash = yes' is set).

You could do a multicall to hash check every torrent, but that would kill you hard drives if like me you have thousands of active torrents.

You could also empty your session directory to have every file readded and hash checked. Again a bad idea if you have tons of active files.

These settings are good for one purpose only: when you make them before adding any files to rtorrent. In my case I already had the files working on rtorrent and bash and/or python scripts taking care of file operations. When I moved to rtorrent 8.9 I realized that using the builtins would make the process less memory and cpu consuming, thus allowing me to use the same rtorrent.rc I'm using on an amd64 machine on my arm processor torrentbox.

So the solution in my case was to empty the sessions and start adding the torrents to the watch folders all over again, but in a way that the hash batch lists did not get so extensive. I had to do it all in bash, using find and mv, and I had to use an external machine (my amd64 processor in this case) because the torrentbox had not sufficient heat control. If you don't have many torrents you can add them all at once.

Now it even works if I have to reinstall rtorrent or anything because my settings also watch for torrent files in the finished torrents directory, so it adds already finished downloads (my first settings made me move every completed download to the "new downloads" folder so rtorrent moves them all back to the finished directory in the other hard drives).

I will show the way i did my settings in the next post.

Offline

#17 2012-04-01 20:11:25

iggy1
Member
Registered: 2012-04-01
Posts: 2

Re: Rtorrent move finished files

This is EXTENSIVE. I am sorry about that. But it was the best I could do. I removed about 2000 lines of explaining the complexity of my network settings that were useless to the subject but I had to leave things like fake directories to clarify better what I did AND to help people trying to make torrentboxes or even leaving their computer on 24/7 to upload stuff.

In this case I have 100% of my torrents uploading with no ratio limit. If one wants to limit the number of torrents being uploaded or cutting it when it achieve a given share ratio it should be easy to do but that is not my case.

These settings do not address active torrents. That would require much more methods and even external scripts for somethings that aren't still covered by rtorrent. So to use this one would have to empty the sessions and re-add every file again. The good part is that this won't download the files all over again. If they are already complete then they will start seeding right away.

In my case the settings slighty different than the ones shown here and in other forums. Basically what they do is to organize files this way:
-TORRENT files 'watch' directory or new torrents folder. I can have none or many of these.
-Finished TORRENT files directory. Of course each watch folder has the same name for the finished torrent folder.
-DIRECTORY for files being downloaded. It stores files for torrents that are not finished.
-DIRECTORY for finished files. It stores files for torrents that are finished. This is on the fastest hard drive because the upload speeds are way slower than download speeds in my country, so these files have to be in priority because I am a critical and dedicated seeder.

I will show some folder structures as an example to clarify:

/home/rtorrent/watch - torrent files downloaded or generated by magnet links land here and are automatically grabbed by rtorrent. Actually mine looks more like this:
/home/rtorrent/watch/development/bash
/home/rtorrent/watch/development/java
/home/rtorrent/watch/development/perl
/home/rtorrent/watch/development/php
/home/rtorrent/watch/development/python
/home/rtorrent/watch/development/ruby
/home/rtorrent/watch/development/sql
/home/rtorrent/watch/movies/larsvontrier
/home/rtorrent/watch/movies/montypython
/home/rtorrent/watch/movies/vodo
/home/rtorrent/watch/music/blacksabbath
/home/rtorrent/watch/music/brainsync
/home/rtorrent/watch/music/meditation
/home/rtorrent/watch/music/nativas
/home/rtorrent/watch/music/raulseixas
/home/rtorrent/watch/music/own
...and so on. You get the idea. Actually the folder names are all 3 letters wide and there is a description.txt inside of every folder for compatibility with special file systems that I use.

Then there are the folders for finished torrents, which are also watch folders:
/mnt/external/hd3-160gb/home/finished - but mine looks more like:
/mnt/external/hd3-160gb/home/finished/development/bash
/mnt/external/hd3-160gb/home/finished/development/perl
/mnt/external/hd3-160gb/home/finished/movies/montypython
/mnt/external/hd3-160gb/home/finished/music/brainsync
...etc. There are two schedule triggers, when torrent files are loaded from these folders they will have the directory set to the finished folder instead of the folder where files being downloaded for unfinished files.

So I had to have two different folders for the files unfinished and for the files that have already been finished and are only in seeding mode:
/mnt/external/hd4-500gb/home/incomplete - this is for files being downloaded, but I have like:
/mnt/external/hd4-500gb/home/incomplete/development/bash
/mnt/external/hd4-500gb/home/incomplete/development/perl
/mnt/external/hd4-500gb/home/incomplete/movies/montypython
/mnt/external/hd4-500gb/home/incomplete/music/brainsync
...and:
/mnt/external/virtual1-8tb/home/complete - this is an array of hard drives with symbolic links that stores all finished files. But since I have a lot of directories mine is more like:
/mnt/external/virtual1-8tb/home/complete/development/bash
/mnt/external/virtual1-8tb/home/complete/development/perl
/mnt/external/virtual1-8tb/home/complete/movies/montypython
/mnt/external/virtual1-8tb/home/complete/music/brainsync



So now here is my rtorrent.rc, using the settings that were provided here:

************************************************************************************************************************
************************************************** START OF .rtorrent.rc **************************************************
************************************************************************************************************************

# This is to check hash of finished torrents, so the command that moves torrents will be triggered. It only triggers after a torrent is hashed, so this has to be on.
check_hash=yes

# This I have to force to be able to use the UDP trackers.
use_udp_trackers=yes

# Also this was necessary to login in the DHT network
dht=auto

# I don't remember why i had to set this
peer_exchange=yes

# This is where torrents being processed by rtorrent are stored, this is a MUST because it enables session locking and it organize every torrent files being used so I don't need external scripts to organize the mess.
session="/home/rtorrent/session"

# This folder is never used, but it is set here in the case that something goes wrong. This does not have enough space to store anything larger than about 1GB so if rtorrent starts buffering things here the process will be killed and error messsages will be sent to the logs.
directory="/home/rtorrent/temp"

# The schedule for low diskspace (yes, mine is 10Mb because the storage where rtorrent runs is very small in size)
schedule=low_diskspace,5,60,close_low_diskspace=10M

# This is to assure that if files "disappear" of the watch folders they will be loaded again if they manage to come back.
schedule=reload_torrent,0,60,"start_tied="

### First of all an explanaton about the custom variables I use:
### the d.custom1 is the finished FILES directory.
### the d.custom2 is the unfinished FILES directory.
### the d.custom3 is the finished TORRENTs watch folder.
### the d.custom4 is the new TORRENTs watch folder.
### These are all shown down there but I am explaining before here to avoid you reading twice the whole file.

### I used the prefix "user_" to show where I put methods that are not native to rtorrent.
### Also you will notice that instead of UNIX's 'mv' command i used rtorrent-mv which is a bash script that I made. It is provided here in this post as well.

## These two are global commands that will be called whenever torrents are added. They will be called depending on the torrent file original location (the new torrents folder or the finished torrents folder). I didn't called the new torrents folder "watch" folder because actually both folders are watch folders. Notice that the only difference here is that it will either set the directory of the torrent to custom1 or custom2 variables. They are set when the torrents is added.
# This is for the finished folder
system.method.insert=user_load_finished_torrents,simple,"d.set_directory=$d.custom1="
# This is for the new folder
system.method.insert=user_load_new_torrents,simple,"d.set_directory=$d.custom2="

## This is the command that moves finished torrents. It is called after the tests below. Notice that I don't use the 'mv' command, instead I use a custom bash script that I provide below. There is a critical difference here: I dont use the 'd.get_base_path', I use 'd.get_base_filename' to make sure that torrents which have only files (like a rar plus a txt or nfo file) and no folders to be treated properly. The torrent file is also moved. Then the directory of the torrent is set to the finished folder. The torrent is stopped and started just to make sure that it will keep seeding after this operation.
system.method.insert=user_move_finished_torrents,simple,"execute=rtorrent-mv,$d.base_filename=,$d.custom1= ;execute=rtorrent-mv,$d.loaded_file=,$d.custom3= ;d.set_directory=$d.custom1= ;d.stop= ;d.start="

## And this is the tests that are performed when a torrent finish hashing. the test_2 is just there to prevent torrents that are already in the finished folder to be moved again.
system.method.insert=user_finished_test_2,simple,"not={\"$equal=\{d.directory=,d.custom1=}\"}"
system.method.insert=user_finished_test_1,simple,"and={d.complete=,user_finished_test_2=}"
system.method.set_key=event.download.hash_done,user_hash_check_done,"branch={$user_finished_test_1=,user_move_finished_torrents=}"

## The rules of folders is in a separate rc file so I can have control of which folders are being processed (to reduce hard disk usage and to prevent low diskspace) but this is not very useful for most users.
import="/home/rtorrent/include.rc"

************************************************************************************************************************
************************************************** END OF .rtorrent.rc  **************************************************
************************************************************************************************************************



This is part of the include.rc file which has the specific torrent add and customs set for each folder as an example. As you can see this file merely include other files that are on the include.d dir and it is generated automatically whenever rtorrent has to be restarted for some reason (energy bills coming too high and wife complaining so the computers have to be turn off for some hours, for instance):

************************************************************************************************************************
************************************************** START OF include.rc  **************************************************
************************************************************************************************************************

import="/home/rtorrent/include.d/development-bash.rc"
import="/home/rtorrent/include.d/development-perl.rc"
import="/home/rtorrent/include.d/movies-montypython.rc"
import="/home/rtorrent/include.d/music-brainsync.rc"

************************************************************************************************************************
**************************************************  END OF include.rc   **************************************************
************************************************************************************************************************



Now for these actual rc files. Notice that every method has an unique name. Rtorrent will import every rc file and CONCATENATE the output. So it doesn't matter if you have a thousand rc files, if any of them has a method which has the same name as other one, only one of these methods will be available. (If I'm not wrong it will be the last on the load order):

************************************************************************************************************************
********************************************   START OF development-bash.rc   ********************************************
************************************************************************************************************************

# These two schedule commands set the watch directories: one is in the new torrent folder and the other is in the finished torrents folder. Each one of them call the main method on the .rtorrent.rc file according to its location. They also call the method to set the customs variables for each file:

schedule=user_load_finished_torrents_development_bash,0,60,"load_start_verbose=/mnt/external/hd3-160gb/home/finished/development/bash/*.torrent,user_set_customs_development_bash=,user_load_finished_torrents="

schedule=user_load_new_torrents_development_bash,0,60,"load_start_verbose=/home/rtorrent/watch/development/bash/*.torrent,user_set_customs_development_bash=,user_load_new_torrents="


# These methods set the customs variables for each file. They are separated to make sure that the directory exists by running mkdir BEFORE it sets the custom variable. The last one simply calls the other four. NOTICE THERE IS A '/' IN THE END OF EVERY DIRECTORY BEING SET. THIS IS CRUCIAL FOR THE 'mv' COMMAND!

system.method.insert=user_set_customs_development_bash_finished_files,simple,"execute=mkdir,-p,/mnt/external/virtual1-8tb/home/complete/development/bash/ ;d.set_custom1=/mnt/external/virtual1-8tb/home/complete/development/bash/"

system.method.insert=user_set_customs_development_bash_unfinished_files,simple,"execute=mkdir,-p,/mnt/external/hd4-500gb/home/incomplete/development/bash/ ;d.set_custom2=/mnt/external/hd4-500gb/home/incomplete/development/bash/"

system.method.insert=user_set_customs_development_bash_finished_torrents,simple,"execute=mkdir,-p,/mnt/external/hd3-160gb/home/finished/development/bash/ ;d.set_custom3=/mnt/external/hd3-160gb/home/finished/development/bash/"

system.method.insert=user_set_customs_development_bash_new_torrents,simple,"execute=mkdir,-p,/home/rtorrent/watch/development/bash/ ;d.set_custom4=/home/rtorrent/watch/development/bash/"

system.method.insert=user_set_customs_development_bash,simple,"user_set_customs_development_bash_finished_files= ;user_set_customs_development_bash_unfinished_files= ;user_set_customs_development_bash_finished_torrents= ;user_set_customs_development_bash_new_torrents="

************************************************************************************************************************
********************************************    END OF development-bash.rc     ********************************************
************************************************************************************************************************

************************************************************************************************************************
********************************************   START OF development-perl.rc    ********************************************
************************************************************************************************************************

# These two schedule commands set the watch directories: one is in the new torrent folder and the other is in the finished torrents folder. Each one of them call the main method on the .rtorrent.rc file according to its location. They also call the method to set the customs variables for each file:

schedule=user_load_finished_torrents_development_perl,0,60,"load_start_verbose=/mnt/external/hd3-160gb/home/finished/development/perl/*.torrent,user_set_customs_development_perl=,user_load_finished_torrents="

schedule=user_load_new_torrents_development_perl,0,60,"load_start_verbose=/home/rtorrent/watch/development/perl/*.torrent,user_set_customs_development_perl=,user_load_new_torrents="


# These methods set the customs variables for each file. They are separated to make sure that the directory exists by running mkdir BEFORE it sets the custom variable. The last one simply calls the other four. NOTICE THERE IS A '/' IN THE END OF EVERY DIRECTORY BEING SET. THIS IS CRUCIAL FOR THE 'mv' COMMAND!

system.method.insert=user_set_customs_development_perl_finished_files,simple,"execute=mkdir,-p,/mnt/external/virtual1-8tb/home/complete/development/perl/ ;d.set_custom1=/mnt/external/virtual1-8tb/home/complete/development/perl/"

system.method.insert=user_set_customs_development_perl_unfinished_files,simple,"execute=mkdir,-p,/mnt/external/hd4-500gb/home/incomplete/development/perl/ ;d.set_custom2=/mnt/external/hd4-500gb/home/incomplete/development/perl/"

system.method.insert=user_set_customs_development_perl_finished_torrents,simple,"execute=mkdir,-p,/mnt/external/hd3-160gb/home/finished/development/perl/ ;d.set_custom3=/mnt/external/hd3-160gb/home/finished/development/perl/"

system.method.insert=user_set_customs_development_perl_new_torrents,simple,"execute=mkdir,-p,/home/rtorrent/watch/development/perl/ ;d.set_custom4=/home/rtorrent/watch/development/perl/"

system.method.insert=user_set_customs_development_perl,simple,"user_set_customs_development_perl_finished_files= ;user_set_customs_development_perl_unfinished_files= ;user_set_customs_development_perl_finished_torrents= ;user_set_customs_development_perl_new_torrents="

************************************************************************************************************************
********************************************    END OF development-perl.rc     ********************************************
************************************************************************************************************************

************************************************************************************************************************
********************************************  START OF movies-montypython.rc   ********************************************
************************************************************************************************************************

# These two schedule commands set the watch directories: one is in the new torrent folder and the other is in the finished torrents folder. Each one of them call the main method on the .rtorrent.rc file according to its location. They also call the method to set the customs variables for each file:

schedule=user_load_finished_torrents_movies_montypython,0,60,"load_start_verbose=/mnt/external/hd3-160gb/home/finished/movies/montypython/*.torrent,user_set_customs_movies_montypython=,user_load_finished_torrents="

schedule=user_load_new_torrents_movies_montypython,0,60,"load_start_verbose=/home/rtorrent/watch/movies/montypython/*.torrent,user_set_customs_movies_montypython=,user_load_new_torrents="


# These methods set the customs variables for each file. They are separated to make sure that the directory exists by running mkdir BEFORE it sets the custom variable. The last one simply calls the other four. NOTICE THERE IS A '/' IN THE END OF EVERY DIRECTORY BEING SET. THIS IS CRUCIAL FOR THE 'mv' COMMAND!

system.method.insert=user_set_customs_movies_montypython_finished_files,simple,"execute=mkdir,-p,/mnt/external/virtual1-8tb/home/complete/movies/montypython/ ;d.set_custom1=/mnt/external/virtual1-8tb/home/complete/movies/montypython/"

system.method.insert=user_set_customs_movies_montypython_unfinished_files,simple,"execute=mkdir,-p,/mnt/external/hd4-500gb/home/incomplete/movies/montypython/ ;d.set_custom2=/mnt/external/hd4-500gb/home/incomplete/movies/montypython/"

system.method.insert=user_set_customs_movies_montypython_finished_torrents,simple,"execute=mkdir,-p,/mnt/external/hd3-160gb/home/finished/movies/montypython/ ;d.set_custom3=/mnt/external/hd3-160gb/home/finished/movies/montypython/"

system.method.insert=user_set_customs_movies_montypython_new_torrents,simple,"execute=mkdir,-p,/home/rtorrent/watch/movies/montypython/ ;d.set_custom4=/home/rtorrent/watch/movies/montypython/"

system.method.insert=user_set_customs_movies_montypython,simple,"user_set_customs_movies_montypython_finished_files= ;user_set_customs_movies_montypython_unfinished_files= ;user_set_customs_movies_montypython_finished_torrents= ;user_set_customs_movies_montypython_new_torrents="

************************************************************************************************************************
********************************************   END OF movies-montypython.rc    ********************************************
************************************************************************************************************************

************************************************************************************************************************
********************************************    START OF music-brainsync.rc    ********************************************
************************************************************************************************************************

# These two schedule commands set the watch directories: one is in the new torrent folder and the other is in the finished torrents folder. Each one of them call the main method on the .rtorrent.rc file according to its location. They also call the method to set the customs variables for each file:

schedule=user_load_finished_torrents_music_brainsync,0,60,"load_start_verbose=/mnt/external/hd3-160gb/home/finished/music/brainsync/*.torrent,user_set_customs_music_brainsync=,user_load_finished_torrents="

schedule=user_load_new_torrents_music_brainsync,0,60,"load_start_verbose=/home/rtorrent/watch/music/brainsync/*.torrent,user_set_customs_music_brainsync=,user_load_new_torrents="


# These methods set the customs variables for each file. They are separated to make sure that the directory exists by running mkdir BEFORE it sets the custom variable. The last one simply calls the other four. NOTICE THERE IS A '/' IN THE END OF EVERY DIRECTORY BEING SET. THIS IS CRUCIAL FOR THE 'mv' COMMAND!

system.method.insert=user_set_customs_music_brainsync_finished_files,simple,"execute=mkdir,-p,/mnt/external/virtual1-8tb/home/complete/music/brainsync/ ;d.set_custom1=/mnt/external/virtual1-8tb/home/complete/music/brainsync/"

system.method.insert=user_set_customs_music_brainsync_unfinished_files,simple,"execute=mkdir,-p,/mnt/external/hd4-500gb/home/incomplete/music/brainsync/ ;d.set_custom2=/mnt/external/hd4-500gb/home/incomplete/music/brainsync/"

system.method.insert=user_set_customs_music_brainsync_finished_torrents,simple,"execute=mkdir,-p,/mnt/external/hd3-160gb/home/finished/music/brainsync/ ;d.set_custom3=/mnt/external/hd3-160gb/home/finished/music/brainsync/"

system.method.insert=user_set_customs_music_brainsync_new_torrents,simple,"execute=mkdir,-p,/home/rtorrent/watch/music/brainsync/ ;d.set_custom4=/home/rtorrent/watch/music/brainsync/"

system.method.insert=user_set_customs_music_brainsync,simple,"user_set_customs_music_brainsync_finished_files= ;user_set_customs_music_brainsync_unfinished_files= ;user_set_customs_music_brainsync_finished_torrents= ;user_set_customs_music_brainsync_new_torrents="

************************************************************************************************************************
********************************************     END OF music-brainsync.rc     ********************************************
************************************************************************************************************************



You probably noticed that these files are similar, and they can be produced by a bash script. And they actually are. Here is a part of the script I used to produce this (the actual script is far more complex but I am doing my best to simplify the process here):

************************************************************************************************************************
********************************************     START OF make-rc-file.sh      ********************************************
************************************************************************************************************************

#!/bin/bash
RC_BASE_FILES_DIR=( "development" "development" "movies" "music" )
RC_BASE_FILES_SUBDIR=( "bash" "perl" "montypython" "brainsync" )
for ((INDEX=0;INDEX<${#RC_BASE_FILES_DIR[@]};INDEX++))
do

    RC_FILE="/home/rtorrent/include.d/${RC_BASE_FILES_DIR[$INDEX]}-${RC_BASE_FILES_SUBDIR[$INDEX]}.rc"

    echo > $RC_FILE

    echo -e "schedule=user_load_finished_torrents_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]},0,60,\"load_start_verbose=/mnt/external/hd3-160gb/home/finished/${RC_BASE_FILES_DIR[$INDEX]}/${RC_BASE_FILES_DIR[$INDEX]}/*.torrent,user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]}=,user_load_finished_torrents=\"" >> $RC_FILE

    echo -e "schedule=user_load_new_torrents_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]},0,60,\"load_start_verbose=/home/rtorrent/watch/${RC_BASE_FILES_DIR[$INDEX]}/${RC_BASE_FILES_DIR[$INDEX]}/*.torrent,user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]}=,user_load_new_torrents=\"" >> $RC_FILE

    echo -e "system.method.insert=user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]}_finished_files,simple,\"execute=mkdir,-p,/mnt/external/virtual1-8tb/home/complete/${RC_BASE_FILES_DIR[$INDEX]}/${RC_BASE_FILES_DIR[$INDEX]}/ ;d.set_custom1=/mnt/external/virtual1-8tb/home/complete/${RC_BASE_FILES_DIR[$INDEX]}/${RC_BASE_FILES_DIR[$INDEX]}/\"" >> $RC_FILE

    echo -e "system.method.insert=user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]}_unfinished_files,simple,\"execute=mkdir,-p,/mnt/external/hd4-500gb/home/incomplete/${RC_BASE_FILES_DIR[$INDEX]}/${RC_BASE_FILES_DIR[$INDEX]}/ ;d.set_custom2=/mnt/external/hd4-500gb/home/incomplete/${RC_BASE_FILES_DIR[$INDEX]}/${RC_BASE_FILES_DIR[$INDEX]}/\"" >> $RC_FILE

    echo -e "system.method.insert=user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]}_finished_torrents,simple,\"execute=mkdir,-p,/mnt/external/hd3-160gb/home/finished/${RC_BASE_FILES_DIR[$INDEX]}/${RC_BASE_FILES_DIR[$INDEX]}/ ;d.set_custom3=/mnt/external/hd3-160gb/home/finished/${RC_BASE_FILES_DIR[$INDEX]}/${RC_BASE_FILES_DIR[$INDEX]}/\"" >> $RC_FILE

echo -e "system.method.insert=user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]}_new_torrents,simple,\"execute=mkdir,-p,/home/rtorrent/watch/${RC_BASE_FILES_DIR[$INDEX]}/${RC_BASE_FILES_DIR[$INDEX]}/ ;d.set_custom4=/home/rtorrent/watch/${RC_BASE_FILES_DIR[$INDEX]}/${RC_BASE_FILES_DIR[$INDEX]}/\"" >> $RC_FILE

    echo -e "system.method.insert=user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]},simple,\"user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]}_finished_files= ;user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]}_unfinished_files= ;user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]}_finished_torrents= ;user_set_customs_${RC_BASE_FILES_DIR[$INDEX]}_${RC_BASE_FILES_DIR[$INDEX]}_new_torrents=\"" >> $RC_FILE

done

************************************************************************************************************************
********************************************      END OF make-rc-file.sh       ********************************************
************************************************************************************************************************



And now the bash script that moves torrents 'rtorrent-mv' I made (this does not end in .sh because it is located on the PATH - for example /home/rtorrent/bin/rtorrent-mv). The reason for this script in the first place was to concatenate multiple arguments which could not be done in the rtorrent builtin "execute" command, but now it is only there because of the "export" command that I have to use to make sure that old files will not be overwritten. This happens because some torrent makers do not take into consideration that if they use a directory name that is similar to another torrent this mv command may cause to unfinished torrents to be moved along with the finished one. For example: if you download a NINE_INCH_NAILS_DISCOGRAPHY.torrent and that torrent has a Nine Inch Nails/ main directory with the albums in subfolders, and then you download another torrent named Nine_Inch_Nails_Full_Discography_320kbps.torrent which also has the Nine Inch Nails/ main directory but different subfolders, when one of these torrents finishes it will move the files of the other along, which is not good because it will either crash the download or make it download all files again.

This scripts do not test if the directory given ends with an '/'. If the arguments are not passed correctly this coud cause the mv command to concatenate every file into a single one instead of moving it to a directory. This is frsutating for torrents over 20GB.

************************************************************************************************************************
********************************************       START OF rtorrent-mv        ********************************************
************************************************************************************************************************

#!/bin/bash
if [[ ! -z $1 && ! -z $2 ]]
then
    SOURCE_DIRECTORY="$1"
    DESTINATION_DIRECTORY="$2"
    export VERSION_CONTROL=numbered
    mv --backup "$1" "$2"
fi

************************************************************************************************************************
********************************************        END OF rtorrent-mv         ********************************************
************************************************************************************************************************

Probably a lot of things went unexplained or are not clarified enough because I stripped off a lot of details, you can ask for clarification if it is not so clear.

Edit1: Do not copy and paste those things, it probably have syntax errors and it is not complete. There are other bash scripts that I had to use that I will only show if one is willing to do what I did, and that is not the intention. This is only meant to give some ideas of what can be done to others. If someone find it useful then I can think of porting things and make a more wide solution/pseudo-tutorial/software or something.

Edit2: Also note that some old versions of rtorrent may require you to use for instance $d.get_base_filename instead of just $d.base_filename or in new versions you will even have to use d.directory.set instead of d.set_directory. This also applies for example to the d.complete command which in old versions should be $d.get_complete or something

Last edited by iggy1 (2012-04-01 20:19:29)

Offline

#18 2012-07-09 19:36:06

C5OK5Y
Member
Registered: 2010-07-04
Posts: 48

Re: Rtorrent move finished files

@iggy1: Thanks for your awesome contribution. I only now had enough time to completely look into it. I have encountered a problem though (possibly because you wrote: "...it probably have syntax errors and it is not complete. There are other bash scripts that I had to use that I will only show if one is willing to do what I did..."). I configured everything like you posted. Then I put a .torrent in the "TORRENT files 'watch' directory or new torrents folder". The torrent got downloaded into the DIRECTORY for files being downloaded but didn't get moved into the "DIRECTORY for finished files". After restarting rtorrent I get "Event 'event.download.hash_done' failed: Bad return code.". After rechecking the config files you provided, it seams that the error is coming form the third last line of the .rtorrent.rc file you shared:

# This is to check hash of finished torrents, so the command that moves torrents will be triggered. It only triggers after a torrent is hashed, so this has to be on.
check_hash=yes
# This I have to force to be able to use the UDP trackers.
use_udp_trackers=yes
# Also this was necessary to login in the DHT network
dht=auto
# I don't remember why i had to set this
peer_exchange=yes
# This is where torrents being processed by rtorrent are stored, this is a MUST because it enables session locking and it organize every torrent files being used so I don't need external scripts to organize the mess.
session="/home/rtorrent/session"
# This folder is never used, but it is set here in the case that something goes wrong. This does not have enough space to store anything larger than about 1GB so if rtorrent starts buffering things here the process will be killed and error messsages will be sent to the logs.
directory="/home/rtorrent/temp"
# The schedule for low diskspace (yes, mine is 10Mb because the storage where rtorrent runs is very small in size)
schedule=low_diskspace,5,60,close_low_diskspace=10M
# This is to assure that if files "disappear" of the watch folders they will be loaded again if they manage to come back.
schedule=reload_torrent,0,60,"start_tied="
### First of all an explanaton about the custom variables I use:
### the d.custom1 is the finished FILES directory.
### the d.custom2 is the unfinished FILES directory.
### the d.custom3 is the finished TORRENTs watch folder.
### the d.custom4 is the new TORRENTs watch folder.
### These are all shown down there but I am explaining before here to avoid you reading twice the whole file.
### I used the prefix "user_" to show where I put methods that are not native to rtorrent.
### Also you will notice that instead of UNIX's 'mv' command i used rtorrent-mv which is a bash script that I made. It is provided here in this post as well.
## These two are global commands that will be called whenever torrents are added. They will be called depending on the torrent file original location (the new torrents folder or the finished torrents folder). I didn't called the new torrents folder "watch" folder because actually both folders are watch folders. Notice that the only difference here is that it will either set the directory of the torrent to custom1 or custom2 variables. They are set when the torrents is added.
# This is for the finished folder
system.method.insert=user_load_finished_torrents,simple,"d.set_directory=$d.custom1="
# This is for the new folder
system.method.insert=user_load_new_torrents,simple,"d.set_directory=$d.custom2="
## This is the command that moves finished torrents. It is called after the tests below. Notice that I don't use the 'mv' command, instead I use a custom bash script that I provide below. There is a critical difference here: I dont use the 'd.get_base_path', I use 'd.get_base_filename' to make sure that torrents which have only files (like a rar plus a txt or nfo file) and no folders to be treated properly. The torrent file is also moved. Then the directory of the torrent is set to the finished folder. The torrent is stopped and started just to make sure that it will keep seeding after this operation.
system.method.insert=user_move_finished_torrents,simple,"execute=rtorrent-mv,$d.base_filename=,$d.custom1= ;execute=rtorrent-mv,$d.loaded_file=,$d.custom3= ;d.set_directory=$d.custom1= ;d.stop= ;d.start="
## And this is the tests that are performed when a torrent finish hashing. the test_2 is just there to prevent torrents that are already in the finished folder to be moved again.
system.method.insert=user_finished_test_2,simple,"not={\"$equal=\{d.directory=,d.custom1=}\"}"
system.method.insert=user_finished_test_1,simple,"and={d.complete=,user_finished_test_2=}"
system.method.set_key=event.download.hash_done,user_hash_check_done,"branch={$user_finished_test_1=,user_move_finished_torrents=}"
## The rules of folders is in a separate rc file so I can have control of which folders are being processed (to reduce hard disk usage and to prevent low diskspace) but this is not very useful for most users.
import="/home/rtorrent/include.rc"

Is there really a problem in the files you shared or should I rather post my config to check if I haven't made an error there? Also don't hesitate to share the other bash scripts you used.

Offline

#19 2012-07-10 02:31:28

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Rtorrent move finished files

@iggy1: Please edit your post and wrap that stuff in code tags

https://wiki.archlinux.org/index.php/Fo … s_and_Code


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB