rakshasa / rtorrent

rTorrent BitTorrent client
https://github.com/rakshasa/rtorrent/wiki
GNU General Public License v2.0
4.21k stars 415 forks source link

Move torrents when completed (but with a delay)? #547

Open Gruncher opened 7 years ago

Gruncher commented 7 years ago

Is it possible to setup rtorrent to move completed torrents, but only after a certain amount of time has has passed?

What I want to do is download a torrent completely, seed for 15 minutes, then move it to another directory and continue seeding.

Can anyone suggest a way to do this? Thank you!

chros73 commented 7 years ago

Yes, you can do it:

... move completed torrents, but only after a certain amount of time ... seed for 15 minutes, then move it ...

Why do you even need this delay? What's the purpose of it?

Gruncher commented 7 years ago

I need the delay because I have a server with a lot of RAM, but a slow HDD.

My plan was to set up a ramdisk to autodl torrents to, get the upload credit during the initial rush, then move them to HDD for more long-term seeding.

My HDD is slow and I believe is holding me back from the other ultra-fast SSD seedboxes in the swarm at first. I was hoping initially downloading to a ramdisk would alleviate this.

chros73 commented 7 years ago

Hm, interesting. You can do delayed moving with scripting in rtorrent config too. You'll need:

rakshasa commented 7 years ago

I would be willing to merge a patch that adds a 'event.download.finished_delayed' event if properly implemented.

It would have to be triggered from within libtorrent, and deal with some edge cases like when a torrent is paused after finish and if rtorrent is restarted (saving the not-triggered stated to the session file).

pyroscope commented 7 years ago

This does not need to be in the core, a proper solution based on a persistent view solves all the restart etc. problems, and allows more flexibility. A command-based solution could be added to the core setup, though.

rakshasa commented 7 years ago

I'd actually rather have it done as triggers, they use less resources and are easier to make work correctly in all circumstances.

pyroscope commented 7 years ago

https://github.com/rakshasa/rtorrent/wiki/Common-Tasks-in-rTorrent#delayed-completion-handling

Can be closed.

pyroscope commented 7 years ago

Since that view is pretty much always empty or small, performance impact is practically zero – especially compared to long lists of 5sec interval watch schedules people have, that hit the disk every time.

chros73 commented 7 years ago

@pyroscope, it's a pretty good idea, thanks. Also good as a tutorial how to use these objects.

Symbiot78 commented 6 years ago

@chros73 & others - question regarding this. I've more or less copy pasted the example and changed a few bits.. I'm unsure if it works and I also have a request for help.. Is it possible to exclude a label?

So I am setting folder based on label. I'd like to exclude "movies" from the delayed finish part of the "script".

also.. when looking at the below delay part & the rest.. does it look right?

hoping for some insights & help :)

the part from my rtorrent.rc:

`schedule = watch_directory_1,10,8,"load_start=/downloads/torrents/movies/.torrent,d.set_custom1=movies" schedule = watch_directory_2,15,12,"load_start=/downloads/torrents/tv/.torrent,d.set_custom1=tv" schedule = watch_directory_3,20,14,"load_start=/downloads/torrents/animation/*.torrent,d.set_custom1=animation"

method.insert = d.get_finished_dir,simple,"cat=/downloads/,$d.get_custom1="

method.set_key = event.download.finished,move_complete,"d.set_directory=$d.get_finished_dir=;execute=mkdir,-p,$d.get_finished_dir=;execute=mv,-u,$d.get_base_path=,$d.get_finished_dir="

method.set_key = event.download.finished,move_complete,"d.directory.set=$d.custom1= ;execute=mkdir,-p,$d.get_finished_dir=;execute=mv,-u,$d.get_base_path=,$d.get_finished_dir="

#############################################################################

Add a "finished_delayed" event

#

See https://github.com/rakshasa/rtorrent/issues/547

#############################################################################

Delay in seconds

method.insert.value = event.download.finished_delayed.interval, 86400

Add persistent view (queue holding delayed items)

view.add = finished_delayed view.persistent = finished_delayed

Add new event for delayed completion handling

method.insert = event.download.finished_delayed, multi|rlookup|static method.set_key = event.download.finished, !add_to_finished_delayed, \ "d.views.push_back_unique = finished_delayed ; \ view.filter_download = finished_delayed" method.set_key = event.download.finished_delayed, !remove_from_finished_delayed, \ "d.views.remove = finished_delayed ; \ view.filter_download = finished_delayed"

Call new event for items that passed the delay interval

schedule2 = event.download.finished_delayed, 60, 60, \ ((d.multicall2, finished_delayed, \ "branch=\"elapsed.greater=(d.timestamp.finished),(event.download.finished_delayed.interval)\", \ event.download.finished_delayed="))

For debugging…

method.set_key = event.download.finished_delayed, !debug, \ "print = \"DELAYED FINISH after \", (convert.elapsed_time, (d.timestamp.finished)), \ \" of \", (d.name)"

method.set_key = event.download.finished_delayed,"d.set_directory=$d.get_finished_dir=;execute=mkdir,-p,$d.get_finished_dir=;execute=mv,-u,$d.get_base_path=,$d.get_finished_dir=" `

pyroscope commented 6 years ago

Post a "diff -U" of yours against the original, and use a ```diff …``` multi-line section, not garbled markdown.

Symbiot78 commented 6 years ago

thank you for your reply @pyroscope this is my first post with diff so bear with me..

green = my rtorrent.rc file - red = original.


 # See https://github.com/rakshasa/rtorrent/issues/547
 #############################################################################
-
 # Delay in seconds
-method.insert.value = event.download.finished_delayed.interval, 600
-
+method.insert.value = event.download.finished_delayed.interval, 60
 # Add persistent view (queue holding delayed items)
-view.add = finished_delayed
-view.persistent = finished_delayed
-
+view.add = finished_delayed 
+view.persistent = finished_delayed
 # Add new event for delayed completion handling
-method.insert = event.download.finished_delayed, multi|rlookup|static
+method.insert = event.download.finished_delayed, multi|rlookup|static
 method.set_key = event.download.finished, !add_to_finished_delayed, \
     "d.views.push_back_unique = finished_delayed ; \
-     view.filter_download = finished_delayed"
-method.set_key = event.download.finished_delayed, !remove_from_finished_delayed, \
+     view.filter_download = finished_delayed" method.set_key =
+event.download.finished_delayed, !remove_from_finished_delayed, \
     "d.views.remove = finished_delayed ; \
      view.filter_download = finished_delayed"
-
 # Call new event for items that passed the delay interval
 schedule2 = event.download.finished_delayed, 60, 60, \
     ((d.multicall2, finished_delayed, \
-        "branch=\"elapsed.greater=(d.timestamp.finished),(event.download.finished_delayed.interval)\", \
+        "branch=\"elapsed.greater=(d.timestamp.finished),(event.download.finished_delayed.interval)\",
+\
             event.download.finished_delayed="))
-
 # For debugging…
 method.set_key = event.download.finished_delayed, !debug, \
-    "print = \"DELAYED FINISH after \", (convert.elapsed_time, (d.timestamp.finished)), \
+   "print = \"DELAYED FINISH after \", (convert.elapsed_time, (d.timestamp.finished)), \
              \" of \", (d.name)"
-
+
+method.set_key = event.download.finished_delayed,move_complete"d.set_directory=$d.get_finished_dir=;execute=mkdir,-p,$d.get_finished_dir=;execute=mv,-u,$d.get_base_path=,$d.get_finished_dir="

trying if this works..

pyroscope commented 6 years ago

it won't with sloppy syntax like removed/added line breaks and missing commas. why did you even change anything in the snippet? the proper way to change the interval is event.download.finished_delayed.interval.set = 60 and anything else needs no change.

Symbiot78 commented 6 years ago

Hi

I only changed the interval.

I think what I am missing is how to actually fire off the event so it will start moving my files.

pyroscope commented 6 years ago

I only changed the interval.

If that were true, the diff would be way shorter.

Symbiot78 commented 6 years ago

sure... probably when I did the diff -U.

would you rather discuss my poor abilities to post proper 'up to par' markdown or can I hope for a guiding answer as to how I get the delay to fire off? I'd prefer the 2nd.

Symbiot78 commented 6 years ago

Previously before trying to add the delay I used this line to do my moviing: method.set_key = event.download.finished,move_complete,"d.set_directory=$d.get_finished_dir=;execute=mkdir,-p,$d.get_finished_dir=;execute=mv,-u,$d.get_base_path=,$d.get_finished_dir=" After adding the snippet for the delay and changing the interval I commented out my previosly move-line and added this instead: method.set_key = event.download.finished_delayed,move_complete,"d.set_directory=$d.get_finished_dir=;execute=mkdir,-p,$d.get_finished_dir=;execute=mv,-u,$d.get_base_path=,$d.get_finished_dir="

but it doesn't seem to pick it up.

Symbiot78 commented 6 years ago

So I think I actually got it working. I set up the whole dropin folder thing with .rc files. Then added the import to the main rtorrent.rc file. I had some trouble getting it to load because it kept complaining about junk at the end of the file. I removed the debug part which seems to fix it.

I discovered that the actual line to trigger the delay and actually move stuff had to be at the bottom of the main file (at least it started working after I did that.) Og and I also had to "initiate" the cfg.basedir folder and created the config.d folder.

at start of rtorrent.rc method.insert = cfg.basedir, private|const|string, (cat,"/config/rtorrent/")

Then create config.d folder under rtorrent folder.

perhaps this is because I am not using standard basefolder.. I dunno.

So to get the delay to run I added this at the bottom of my rtorrent.rc file:

#import .rc files from config.d folder
method.insert = cfg.drop_in, private|const|string, (cat, (cfg.basedir), "config.d")
execute.nothrow = bash, -c, (cat,\
    "find ", (cfg.drop_in), " -name '*.rc' ",\
    "| sort | sed -re 's/^/import=/' >", (cfg.drop_in), "/.import")
try_import = (cat, (cfg.drop_in), "/.import")

#Fire off event and move files when delay has been reached. 
method.set_key = event.download.finished_delayed,move_complete,"d.set_directory=$d.get_finished_dir=;execute=mkdir,-p,$d.get_finished_dir=;execute=mv,-u,$d.get_base_path=,$d.get_finished_dir=" 

in config.d folder I created a file called delay.rc with the following:

#############################################################################
# Add a "finished_delayed" event
#
# See https://github.com/rakshasa/rtorrent/issues/547
#############################################################################

# Delay in seconds
method.insert.value = event.download.finished_delayed.interval, 259200

# Add persistent view (queue holding delayed items)
view.add = finished_delayed
view.persistent = finished_delayed

# Add new event for delayed completion handling
method.insert = event.download.finished_delayed, multi|rlookup|static
method.set_key = event.download.finished, !add_to_finished_delayed, \
    "d.views.push_back_unique = finished_delayed ; \
     view.filter_download = finished_delayed"
method.set_key = event.download.finished_delayed, !remove_from_finished_delayed, \
    "d.views.remove = finished_delayed ; \
     view.filter_download = finished_delayed"

# Call new event for items that passed the delay interval
schedule2 = event.download.finished_delayed, 60, 60, \
    ((d.multicall2, finished_delayed, \
        "branch=\"elapsed.greater=(d.timestamp.finished),(event.download.finished_delayed.interval)\", \
            event.download.finished_delayed="))

All I wish for now is that after it moves the file it doesn't mark the torrent as fininshed but picks of the new folder with the copied content and continues to seed. As it is now it stops seeding after the delay has fired and moved the file. can someone help me achieve this?

Symbiot78 commented 6 years ago

oh yeah.. my delay is set to 3 days in the above delay.rd file. method.insert.value = event.download.finished_delayed.interval, 259200

chros73 commented 6 years ago

I think this is the problem in your main config: d.set_directory=$d.get_finished_dir= from this:

#Fire off event and move files when delay has been reached. 
method.set_key = event.download.finished_delayed,move_complete,"d.set_directory=$d.get_finished_dir=;execute=mkdir,-p,$d.get_finished_dir=;execute=mv,-u,$d.get_base_path=,$d.get_finished_dir=" 

The problem is the you move downloads INTO d.get_finished_dir and set the d.set_directory to this dir and NOT to the actual final full path to the download:

You can print out values with CTRL+X and e.g. print=$d.directory= to see their actual values in rtorrent.

Symbiot78 commented 6 years ago

I did get it working but it was way way way too slow. I wanted to move via VPN connection.

Today I download on 1 box and seed it there for 3 days. Every night I push any files in /tv to box2 via rsync and del anything that’s not in box 1 /tv. Via channels in rutorrent I seed for 3 days and “remove (all)” though it seems the remove all doesn’t quite work 😐

From: gl0biz notifications@github.com Sent: Tuesday, 15 May 2018 21.19 To: rakshasa/rtorrent rtorrent@noreply.github.com Cc: Symbiot78 razkyou@hotmail.com; Mention mention@noreply.github.com Subject: Re: [rakshasa/rtorrent] Move torrents when completed (but with a delay)? (#547)

@Symbiot78https://github.com/Symbiot78 did you get rtorrent to continue seedig after the move? i did not understand how to implement what @chros73https://github.com/chros73 said.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/rakshasa/rtorrent/issues/547#issuecomment-389282450, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADKSSejC4unX3j0PLajqWNyd5fEfaQ2-ks5tyyopgaJpZM4LiAEU.