### rTorrent Startup Script Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html A basic bash script to start rTorrent, including setting umask, changing directory, and handling the socket file. ```bash #! /bin/bash # # rTorrent startup script # umask 0027 cd $(dirname "$0") # Check for running process export RT_SOCKET=$PWD/.scgi_local test -S $RT_SOCKET && lsof $RT_SOCKET >/dev/null \ && { echo "rTorrent already running"; exit 1; } test ! -e $RT_SOCKET || rm $RT_SOCKET # Clean up after rTorrent ends _at_exit() { stty sane test ! -e $RT_SOCKET || rm $RT_SOCKET } trap _at_exit INT TERM EXIT # Start rTorrent (optionally with configuration loaded # from the directory this script is stored in) rtorrent -D -I # -n -o import=$PWD/rtorrent.rc ``` -------------------------------- ### string.lpad and string.rpad example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Illustrates how to pad strings at the start or end using string.lpad and string.rpad. ```bash # Example usage for string.lpad/string.rpad would go here, but is not provided in the source. ``` -------------------------------- ### Example of Indented Commands and Multicall Source: https://rtorrent-docs.readthedocs.io/en/latest/scripting.html Demonstrates how to use method.insert for complex command sequences and d.multicall2 for polling download items with specific conditions. ```shell method.insert = indent_sequence_of_cmds_and_their_args, private|simple,\n (cat, (cfg.watch), (argument.0), /*.torrent),\n (cat, d.category.set=, (argument.0)) ;\n category.view.update = (argument.0) schedule2 = polling, 10, 120,\n ((d.multicall2, main,\n "branch=\"or={d.up.rate=,d.down.rate=,}",\n poll=$interval.active=,\n poll=$interval.idle=")) ``` -------------------------------- ### Quick toggle example for import.return Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of using import.return for quick toggling of experimental configuration. ```shell #import.return= «here be dragons» ``` -------------------------------- ### system.has Example 2 Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example demonstrating the usage of system.has to check for method existence. ```bash $ rtxmlrpc system.has '' system.has= 1 $ rtxmlrpc system.has '' cute.kittens= 0 ``` -------------------------------- ### system.client_version.as_value command example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example showing the output of system.client_version.as_value and system.client_version commands. ```bash $ rtxmlrpc --repr system.client_version.as_value 906 $ rtxmlrpc --repr system.client_version '0.9.6' ``` -------------------------------- ### system.env Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example demonstrating how to query an environment variable and use it to set the session path. ```bash session.path.set = (cat, (system.env, RTORRENT_HOME), "/.session") ``` -------------------------------- ### p.multicall Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Demonstrates how to use p.multicall to get peer IDs and ports, and how to directly call p.port with a constructed target. ```bash $ hash="145B85116626651912298F9400805254FB1192AE" # some valid info hash $ rtxmlrpc --repr p.multicall "$hash" "" p.id= p.port= [['17C14214B60B92FFDEBFB550380ED3866BF49691', 62066]] $ rtxmlrpc --repr p.port "$hash:p17C14214B60B92FFDEBFB550380ED3866BF49691" 62066 ``` -------------------------------- ### array.at example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Placeholder for an example demonstrating the array.at function. ```bash # Example usage for array.at would go here, but is not provided in the source. ``` -------------------------------- ### system.has Example 1 Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example showing how to check if a capability exists using rtxmlrpc. ```bash $ rtxmlrpc --repr system.has.list ['canvas_v2', 'colors', 'rtorrent-ps', 'system.has'] ``` -------------------------------- ### Scheduled Bandwidth Shaping Source: https://rtorrent-docs.readthedocs.io/en/latest/use-cases.html This example demonstrates using schedule2 with absolute start times to adjust download rates based on the wall clock time, enabling full speed during work hours and moderate usage at home. ```bash schedule2 = throttle_full, 10:00:00, 24:00:00, ((throttle.global_down.max_rate.set_kb, 16000)) schedule2 = throttle_slow, 16:00:00, 24:00:00, ((throttle.global_down.max_rate.set_kb, 1000)) ``` -------------------------------- ### DHT Add Node Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of how to add a hostname/port to use for bootstrapping DHT information. ```text dht.add_node = string ‹[host]:[port]› ≫ 0 ``` -------------------------------- ### import example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of using the import command with a relative path. ```shell import = (cat, (cfg.basedir), "_rtlocal.rc") ``` -------------------------------- ### Schedule2 example: Daily log entry Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of using schedule2 to add a timestamped entry to the console log at the start of each day. ```bash # Add day break to console log # → ( 0:00:00) New day: 20/03/2017 schedule2 = log_new_day, 00:00:00, 24:00:00,\ "print=\"New day: \", (convert.date, (system.time))" ``` -------------------------------- ### string.map and string.replace examples Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Examples demonstrating the usage of string.map for exact matches and string.replace for all occurrences. ```bash $ rtxmlrpc string.map '' 'foo' [foo,bar [bar,baz baz $ rtxmlrpc string.replace '' "it's like 1" [1,2ic [2,ma3 [3,g it's like magic $ rtxmlrpc -i 'print = (string.map, (cat, (value,1)), {0,off}, {1,low}, {2,""}, {3,high})' # prints 'low' as a console message, this is how you map integers ``` -------------------------------- ### method.insert and method.set_key examples Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Demonstrates how to insert and set keys for methods, including conditional logic for logging. ```plaintext method.insert = sample.action, multi|rlookup|static method.set_key = sample.action, 10, ((print, "action")) method.set_key = sample.action, 20, ((print, "action2")) method.set_key = sample.action, 99,\n ((branch, sample.verbose=,\n "print=\"Some log message\""\n )) method.const.enable = sample.action ``` -------------------------------- ### XMLRPC Command Example Source: https://rtorrent-docs.readthedocs.io/en/latest/scripting.html Demonstrates how to use rtxmlrpc to call the view.size command, showing the error when a target is missing and the correct usage with an empty string as a placeholder. ```bash $ rtxmlrpc view.size default ERROR While calling view.size('default'): $ rtxmlrpc view.size '' default 133 ``` -------------------------------- ### schedule2 example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html An example of the schedule2 command. ```shell schedule2 = watch_cleaned, 29, 10, \ ((load.normal, (cat,(cfg.watch),"cleaned/*.torrent"), "d.delete_tied=")) ``` -------------------------------- ### log.messages example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of configuring the log file for messages. ```shell log.messages = (cat, (cfg.logs), "messages.log") ``` -------------------------------- ### log.execute example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of configuring the log file for execute commands. ```shell log.execute = (cat, (cfg.logs), "execute.log") ``` -------------------------------- ### Event handler example for view changes Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Provides examples of setting up event handlers for view hide and view show events, logging the transition. ```bash method.set_key = event.view.hide, ~log,\ ((print, "× ", ((ui.current_view)), " → ", ((argument.0))))' method.set_key = event.view.show, ~log,\ ((print, "⊞ ", ((argument.0)), " → ", ((ui.current_view))))' ``` -------------------------------- ### Start torrents one by one Source: https://rtorrent-docs.readthedocs.io/en/latest/faq.html This command starts torrents that are marked as complete, one by one, with a 2-second delay between attempts. If a torrent fails to start or triggers a crash, the loop breaks. The sleep time can be increased if necessary. ```bash while true; do rtcontrol --from-view stopped is_complete=y -/1 \ --start --flush -qo name || break; sleep 2; done ``` -------------------------------- ### schedule2 example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of using the schedule2 command with new syntax. ```shell schedule2 = log_new_day, 00:00:05, 24:00:00,\n ((print, "New day: ", ((convert.date, ((system.time_seconds)) )) )) ``` -------------------------------- ### log.open_file_pid example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of opening a log file for tracker debugging. ```shell log.open_file_pid = tracker, /tmp/tracker.log, tracker_debug ``` -------------------------------- ### Tracker Domain Rule Example Source: https://rtorrent-docs.readthedocs.io/en/latest/use-cases.html Example of how to add a rule to move downloads based on the tracker domain. ```bash # Move by tracker test -n "$target" || case $(tr A-Z' ' a-z_ <<<"${tracker_domain:-NOT_SET}") in linuxtracker.org) target="Software" ;; esac ``` -------------------------------- ### method.get examples Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Illustrates retrieving method definitions, including handling 'Key not found' errors and inspecting system handlers. ```bash $ rtxmlrpc --repr method.get '' sample.verbose 1 $ rtxmlrpc --repr method.get '' sample.verbose.set ERROR While calling method.get('', 'sample.verbose.set'): $ rtxmlrpc --repr method.get '' sample.action {'10': ['print', 'action'], '20': ['print', 'action2'], '99': ['branch', 'sample.verbose=', 'print="Some log message"']} $ rtxmlrpc --repr method.get '' event.download.closed {'!view.indemand': 'view.filter_download=indemand', '!log': 'print="CLOSED ",$d.name=," [",$convert.date=$system.time=,"]"'} ``` -------------------------------- ### method.insert example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of inserting a method with conditional logic for file paths. ```shell method.insert = d.data_path, simple,\n "if=(d.is_multi_file),\n (cat, (d.directory), /),\n (cat, (d.directory), /, (d.name))" ``` -------------------------------- ### d.custom.keys example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of retrieving custom keys using rtxmlrpc. ```shell $ rtxmlrpc --repr d.custom.keys $(rtxmlrpc download_list | head -n1) | tr -d \n [… 'tm_downloaded', 'tm_last_scrape', 'tm_loaded', 'tm_started'] ``` -------------------------------- ### Logging Configuration Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Settings for configuring rTorrent's logging output. ```rtorrent.rc print = (cat, "Logging to ", (cfg.logfile)) log.open_file = "log", (cfg.logfile) log.add_output = "info", "log" ##log.add_output = "tracker_debug", "log" ``` -------------------------------- ### log.xmlrpc example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of configuring the log file for XMLRPC commands. ```shell log.xmlrpc = (cat, (cfg.logs), "xmlrpc.log") ``` -------------------------------- ### Additional Values and Commands Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Custom methods and values that can be inserted into rTorrent's configuration. ```rtorrent.rc method.insert = system.startup_time, value|const, (system.time) method.insert = d.data_path, simple, "if=(d.is_multi_file), (cat, (d.directory), /), (cat, (d.directory), /, (d.name))" method.insert = d.session_file, simple, "cat=(session.path), (d.hash), .torrent" ``` -------------------------------- ### f.* commands example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Examples demonstrating the usage of f.multicall and f.size_bytes commands with rtxmlrpc. ```bash $ rtxmlrpc --repr f.multicall "145B85116626651912298F9400805254FB1192AE" "" f.path= [['ubuntu-16.04.3-server-amd64.iso']] $ rtxmlrpc --repr f.size_bytes "145B85116626651912298F9400805254FB1192AE:f0" 865075200 ``` -------------------------------- ### Watch Directory Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of how to use the directory.watch.added command to monitor a directory for new files and trigger an action. ```bash directory.watch.added = ‹root folder path›, ‹handler command name› ≫ 0 ``` ```bash directory.watch.added = "~/Downloads/watch/", load.start_verbose ``` -------------------------------- ### d.custom.items example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of retrieving custom items using rtxmlrpc. ```shell $ rtxmlrpc --repr d.custom.items $(rtxmlrpc download_list | head -n1) {… 'tm_downloaded': '1522406424', 'tm_last_scrape': '1527931151', 'tm_loaded': '1522406432', 'tm_started': '1522406432'} ``` -------------------------------- ### Tracker Domain and Alias Examples Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Examples demonstrating the usage of d.tracker_domain and d.tracker_alias for obtaining tracker information and sorting views. ```bash # rTorrent-PS only d.tracker_domain = ‹hash› d.tracker_alias = ‹hash› ``` -------------------------------- ### d.creation_date example with lstor Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of inspecting the creation date using lstor. ```shell $ lstor -o 'creation date' file.torrent 1480229112 ``` -------------------------------- ### system.has Branch Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example showing conditional execution based on system.has. ```ini branch=(system.has, system.has), ((print, "Your build can haz system.has!")) ``` -------------------------------- ### Post-load commands example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example demonstrating the use of post-load commands with load.verbose to set custom attributes. ```shell schedule2 = watch_with_category, 27, 10, \ ((load.verbose, (cat,(cfg.watch),"foobar/*.torrent"), "d.custom1.set=foobar")) ``` -------------------------------- ### Other Operational Settings Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Configurable operational settings for rTorrent that may need adaptation. ```rtorrent.rc encoding.add = utf8 system.umask.set = 0027 system.cwd.set = (directory.default) network.http.dns_cache_timeout.set = 25 ##network.http.capath.set = "/etc/ssl/certs" ##network.http.ssl_verify_peer.set = 0 ##network.http.ssl_verify_host.set = 0 ##pieces.hash.on_completion.set = no ##keys.layout.set = qwerty ##view.sort_current = seeding, greater=d.ratio= schedule2 = monitor_diskspace, 15, 60, ((close_low_diskspace, 1000M)) ``` -------------------------------- ### Configuration Example for ui.bind_key Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of binding a key ('^') to show the last 'rtcontrol' result, demonstrating the need for scheduled execution. ```shell # Bind '^' to show the last "rtcontrol" result schedule2 = bind_view_rtcontrol, 1, 0,\ "ui.bind_key = download_list, ^, ui.current_view.set=rtcontrol" ``` -------------------------------- ### string.join example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Illustrates how to join strings with a delimiter using string.join. ```bash # Example usage for string.join would go here, but is not provided in the source. ``` -------------------------------- ### method.rlookup and method.rlookup.clear syntax and example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Shows the syntax for reverse lookups and clearing them, with an example of finding event handlers. ```bash method.rlookup = ‹key› ≫ list of strings method.rlookup.clear = ‹key› ≫ 0 $ rtxmlrpc --repr method.rlookup '' \!view.main ['event.download.finished', 'event.download.inserted_new'] ``` -------------------------------- ### Download and execute completion-path.sh Source: https://rtorrent-docs.readthedocs.io/en/latest/use-cases.html This snippet shows how to download the completion-path.sh script and run it with the -h flag to display installation instructions. ```bash gh_raw="https://raw.githubusercontent.com/rtorrent-community/rtorrent-docs" wget -O /tmp/completion-path.sh $gh_raw/master/docs/examples/completion-path.sh bash /tmp/completion-path.sh -h ``` -------------------------------- ### Set Tracker Alias Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of how to set a specific alias for a tracker domain. ```bash trackers.alias.set_key = bttracker.debian.org, Debian ``` -------------------------------- ### Basic Operational Settings Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Default settings for rTorrent that typically do not require modification. ```rtorrent.rc session.path.set = (cat, (cfg.basedir), ".session") directory.default.set = (cat, (cfg.basedir), "download/") log.execute = (cat, (cfg.logs), "execute.log") ##log.xmlrpc = (cat, (cfg.logs), "xmlrpc.log") execute.nothrow = bash, -c, (cat, "echo >",\ (session.path), "rtorrent.pid", " ", (system.pid)) ``` -------------------------------- ### string.split example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Illustrates how to split a string by a delimiter using string.split. ```bash # Example usage for string.split would go here, but is not provided in the source. ``` -------------------------------- ### Example: Optional logging with method.insert.value Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Demonstrates how to use method.insert.value for optional logging and splitting complex commands. ```bash # Enable verbose mode by setting this to 1 method.insert.value = sample.verbose, 0 ``` -------------------------------- ### Example usage of download_list Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of using the download_list command to retrieve info hashes of tagged items. ```shell $ rtxmlrpc --repr download_list '' tagged ['91C588B9A9B5A71F0462343BC74E2A88C1E0947D', '17C14214B60B92FFDEBFB550380ED3866BF49691'] ``` -------------------------------- ### Schedule2 examples: Watching directories Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of using schedule2 to periodically watch directories for new torrent files and load them. ```bash # Watch directories schedule2 = watch_start, 11, 10, ((load.start, (cat, (cfg.watch), "start/*.torrent"))) schedule2 = watch_load, 12, 10, ((load.normal, (cat, (cfg.watch), "load/*.torrent"))) ``` -------------------------------- ### schedule2 examples for load.normal Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Examples of using load.normal and load.verbose within schedule2 configurations for watching directories. ```shell schedule2 = watch_start, 1, 10, ((load.start_verbose, (cat, (cfg.watch), "start/*.torrent"))) schedule2 = watch_load, 2, 10, ((load.verbose, (cat, (cfg.watch), "load/*.torrent"))) ``` -------------------------------- ### Watch Directories Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Configuration for watching directories for new torrent files. ```rtorrent.rc schedule2 = watch_start, 10, 10, ((load.start_verbose, (cat, (cfg.watch), "start/*.torrent"))) schedule2 = watch_load, 11, 10, ((load.verbose, (cat, (cfg.watch), "load/*.torrent"))) ``` -------------------------------- ### Conditional Branching Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example showing conditional branching based on a value comparison. ```bash $ rtxmlrpc branch '' greater=value=2,value=2 cat=YES cat=NO NO $ rtxmlrpc branch '' greater=value=4,value=2 cat=YES cat=NO YES ``` -------------------------------- ### system.has Polyfill Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Configuration snippet to polyfill system.has for older rTorrent versions. ```ini # `system.has` polyfill (the "false=" silences the `catch` command, in rTorrent-PS) catch = {"false=", "method.redirect=system.has,false"} ``` -------------------------------- ### DHT Mode Set Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of setting the DHT mode, controlling when DHT is activated. 'dht' is an alias for 'dht.mode.set'. ```text dht.mode.set = string ‹mode› ≫ 0 dht = string ‹mode› ≫ 0 ``` -------------------------------- ### cat function example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example demonstrating the usage of the cat function to print concatenated strings. ```text print=(cat, text\ or\ , {"array", " of", " text"}) ``` -------------------------------- ### t.multicall example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Demonstrates how to use t.multicall to retrieve tracker URLs and how to call t.url directly. ```bash $ rtxmlrpc --repr t.multicall DDEE5CB75C12F3165EF79A12A5CD6158BEF029AD "" t.url= [['http://torrent.ubuntu.com:6969/announce'], ['http://ipv6.torrent.ubuntu.com:6969/announce']] $ rtxmlrpc --repr t.url DDEE5CB75C12F3165EF79A12A5CD6158BEF029AD:t0 'http://torrent.ubuntu.com:6969/announce' ``` -------------------------------- ### DHT Port Set Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of controlling which port DHT will listen on. 'dht_port' is an alias for 'dht.port.set'. ```text dht.port ≫ value ‹port› dht.mode.set = value ‹port› ≫ 0 dht_port = value ‹port› ≫ 0 ``` -------------------------------- ### d.name command example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of the d.name command, showing the required hash parameter for XMLRPC calls. ```text d.name = ‹hash› ≫ string ‹name› ``` -------------------------------- ### rTorrent-PS 1.1+ Detection Example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Configuration snippet to detect and activate rTorrent-PS features using system.has. ```ini # `system.has` polyfill (the "false=" silences the `catch` command, in rTorrent-PS) catch = {"false=", "method.redirect=system.has,false"} # Set "pyro.extended" to 1 to activate rTorrent-PS features! method.insert = pyro.extended, const|value, (system.has, rtorrent-ps) ``` -------------------------------- ### Protecting imports with new features example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of protecting imports that use new features with import.return. ```shell branch=(system.has, "import.return="), ((import, using-math-stuff.rc)) ``` -------------------------------- ### Install rename script Source: https://rtorrent-docs.readthedocs.io/en/latest/use-cases.html Commands to download and make the rename script executable. ```shell gh_raw="https://raw.githubusercontent.com/rtorrent-community/rtorrent-docs" mkdir -p ~/rtorrent/scripts wget $gh_raw/master/docs/examples/rename2tied.sh -O $_/rename2tied.sh chmod a+rx $_/rename2tied.sh ``` -------------------------------- ### Example of load.raw_verbose with XMLRPC and debugging Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Demonstrates loading raw metafile data via XMLRPC and capturing debug output. ```shell $ mktor -q README.md local $ rtxmlrpc --debug load.raw_verbose '' @README.md.torrent | egrep 'xmlrpclib|stats' DEBUG load.raw_verbose('', ) took 0.000 secs DEBUG XMLRPC stats: 3 req, out 795 bytes [564 bytes max], in 445 bytes [153 bytes max], … ``` -------------------------------- ### Configuration Template - Directory Creation Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Creates the necessary directories for the rTorrent instance, including session, download, log, and watch folders, using bash and mkdir. ```rTorrent Configuration execute.throw = bash, -c, (cat,\ "builtin cd \"", (cfg.basedir), " " \ "&& mkdir -p .session download log watch/{load,start}") ``` -------------------------------- ### string.strip, string.lstrip, string.rstrip example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Illustrates how to strip characters from strings using string.strip, string.lstrip, and string.rstrip. ```bash # Example usage for string.strip/lstrip/rstrip would go here, but is not provided in the source. ``` -------------------------------- ### string.shorten example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Illustrates how to shorten a UTF-8 encoded string using string.shorten. ```bash # Example usage for string.shorten would go here, but is not provided in the source. ``` -------------------------------- ### rTorrent Command Line Usage Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Help message displayed when running `rtorrent -h`, showing available command-line options. ```bash Usage: rtorrent [OPTIONS]... [FILE]... [URL]... -h Display this very helpful text -n Don't try to load ~/.rtorrent.rc on startup -b Bind the listening socket to this IP -i Change the IP that is sent to the tracker -p - Set port range for incoming connections -d Save torrents to this directory by default -s Set the session directory -o key=opt,... Set options, see 'rtorrent.rc' file -D Disable deprecated commands -I Disable intermediate commands -K Allow intermediate commands without XMLRPC (just in config files) ``` -------------------------------- ### Escaping with Quotes Source: https://rtorrent-docs.readthedocs.io/en/latest/scripting.html Example demonstrating how to use double quotes to pass multiple arguments to a command, where one of the arguments is itself a command. ```plaintext outer = arg1, "inner=arg21,arg22", arg3 ``` -------------------------------- ### Custom Methods and Variables Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Defines custom methods for system startup time, data path, and session file path. These methods can be used within the rTorrent configuration. ```rtorrent method.insert = system.startup_time, value|const, (system.time) method.insert = d.data_path, simple,\ "if=(d.is_multi_file),\ (cat, (d.directory), /),\ (cat, (d.directory), /, (d.name))" method.insert = d.session_file, simple, "cat=(session.path), (d.hash), .torrent" ``` -------------------------------- ### network.receive_buffer.size and network.send_buffer.size Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Sets or gets the maximum socket receive / send buffer in bytes. On Linux, the default buffer size for receiving data is set by the `/proc/sys/net/core/rmem_default` file (`wmem_default` for sending). The maximum allowed value is set by the `/proc/sys/net/core/rmem_max` file (`wmem_max` for sending). See the tuning guide for tweaking these values. ```shell network.receive_buffer.size ≫ value ‹size› network.receive_buffer.size.set = ‹size› ≫ 0 network.send_buffer.size ≫ value ‹size› network.send_buffer.size.set = ‹size› ≫ 0 ``` -------------------------------- ### ui.focus commands Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Commands for navigating through the download list by pages and jumping to the start or end. ```text ui.focus.end¶ ui.focus.home¶ ui.focus.pgdn¶ ui.focus.pgup¶ ui.focus.page_size¶ ui.focus.page_size.set¶ ``` -------------------------------- ### Sorting by Multiple Criteria Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example demonstrating how to sort a view by multiple criteria (message and name) using the 'compare' command. ```rTorrent Script view.add = messages view.filter = messages, ((d.message)) view.sort_new = messages, "compare=,d.message=,d.name=" ``` -------------------------------- ### Fetch and apply modernized rTorrent wiki config template Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html This command fetches the latest rTorrent configuration template from GitHub, processes it to replace placeholder paths with the user's home directory, and saves it as the default configuration file (~/.rtorrent.rc). It also creates the necessary directory structure for rTorrent's instance. ```bash curl -Ls "https://raw.githubusercontent.com/wiki/rakshasa/rtorrent/CONFIG-Template.md" \ | grep -A9999 '^######' | grep -B9999 '^### END' \ | sed -re "s:/home/USERNAME:$HOME:" >~/.rtorrent.rc mkdir ~/rtorrent # create user's instance directory ``` -------------------------------- ### Configuration Template - Basic Definitions Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Defines instance constants like the base directory, watch directory, log directory, and log file, incorporating system time. ```rTorrent Configuration method.insert = cfg.basedir, private|const|string, (cat,"/home/USERNAME/rtorrent/") method.insert = cfg.watch, private|const|string, (cat,(cfg.basedir),"watch/") method.insert = cfg.logs, private|const|string, (cat,(cfg.basedir),"log/") method.insert = cfg.logfile, private|const|string, (cat,(cfg.logs),"rtorrent-',(system.time),".log") ``` -------------------------------- ### Launching rTorrent in tmux Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Command to launch rTorrent within a tmux session, ensuring the window remains open after rTorrent exits. ```bash tmux -2u new -n rTorrent -s rtorrent "~/rtorrent/start; exec bash" ``` -------------------------------- ### Configuration Template - Other Operational Settings Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Includes various operational settings such as encoding, umask, current working directory, and DNS cache timeout. Some settings are commented out. ```rTorrent Configuration encoding.add = utf8 system.umask.set = 0027 system.cwd.set = (directory.default) network.http.dns_cache_timeout.set = 25 ##network.http.capath.set = "/etc/ssl/certs" ##network.http.ssl_verify_peer.set = 0 ##network.http.ssl_verify_host.set = 0 ##pieces.hash.on_completion.set = no ``` -------------------------------- ### log.add_output example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of adding a specific scope (tracker_debug) to a log file named tracelog. ```shell log.add_output = tracker_debug, tracelog ``` -------------------------------- ### Configuration Template - Session and Download Paths Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Sets the session path for saving status and the default download location for data. Also configures log files and writes a PID file. ```rTorrent Configuration session.path.set = (cat, (cfg.basedir), ".session") directory.default.set = (cat, (cfg.basedir), "download/") log.execute = (cat, (cfg.logs), "execute.log") ##log.xmlrpc = (cat, (cfg.logs), "xmlrpc.log") execute.nothrow = bash, -c, (cat, "echo >", (session.path), "rtorrent.pid", " ", (system.pid)) ``` -------------------------------- ### Conditional return in imported file example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of using import.return conditionally in an imported file. ```shell branch=(not, (system.has, "math.add=")), ((import.return)) ``` -------------------------------- ### Modernized rTorrent Configuration Template Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html A minimal rTorrent configuration template that provides basic features beyond the built-in defaults. It includes settings for instance layout, listening port, tracker support, peer limits, protocol encryption, and resource limits for memory and network operations. ```rtorrent ############################################################################# # A minimal rTorrent configuration that provides the basic features # you want to have in addition to the built-in defaults. # # See https://github.com/rakshasa/rtorrent/wiki/CONFIG-Template # for an up-to-date version. ############################################################################# # Instance layout (base paths) method.insert = cfg.basedir, private|const|string, (cat,"/home/USERNAME/rtorrent/") method.insert = cfg.watch, private|const|string, (cat,(cfg.basedir),"watch/") method.insert = cfg.logs, private|const|string, (cat,(cfg.basedir),"log/") method.insert = cfg.logfile, private|const|string, (cat,(cfg.logs),"rtorrent-',(system.time),".log") # Create instance directories execute.throw = bash, -c, (cat,\ "builtin cd \"", (cfg.basedir), \" \" \ "&& mkdir -p .session download log watch/{load,start}") # Listening port for incoming peer traffic (fixed; you can also randomize it) network.port_range.set = 50000-50000 network.port_random.set = no # Tracker-less torrent and UDP tracker support # (conservative settings for 'private' trackers, change for 'public') dht.mode.set = disable protocol.pex.set = no trackers.use_udp.set = no # Peer settings throttle.max_uploads.set = 100 throttle.max_uploads.global.set = 250 throttle.min_peers.normal.set = 20 throttle.max_peers.normal.set = 60 throttle.min_peers.seed.set = 30 throttle.max_peers.seed.set = 80 trackers.numwant.set = 80 protocol.encryption.set = allow_incoming,try_outgoing,enable_retry # Limits for file handle resources, this is optimized for # an `ulimit` of 1024 (a common default). You MUST leave # a ceiling of handles reserved for rTorrent's internal needs! network.http.max_open.set = 50 network.max_open_files.set = 600 network.max_open_sockets.set = 300 # Memory resource usage (increase if you have a large number of items loaded, # and/or the available resources to spend) pieces.memory.max.set = 1800M network.xmlrpc.size_limit.set = 4M ``` -------------------------------- ### system.random command example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of using system.random to generate random numbers within a specified range. ```bash # Example use-case is adding jitter to time values that you later check with elapsed.greater, to avoid load spikes and similar effects of clustered time triggers. ``` -------------------------------- ### string.contains[_i] example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example demonstrating the usage of the string.contains_i function to find files containing 'Mate' in their name. ```bash $ rtxmlrpc d.multicall.filtered '' 'string.contains_i=(d.name),Mate' d.name= ``` -------------------------------- ### method.set_key, method.has_key, and method.list_keys syntax Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Provides the syntax for setting, checking, and listing keys within multi-methods. ```plaintext method.set_key = ‹name›, ‹key›[, ‹definition›] ≫ 0 method.has_key = ‹name›, ‹key› ≫ bool (0 or 1) method.list_keys = ‹name› ≫ list of strings ``` -------------------------------- ### Configuration Template - Tracker Settings Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Configures settings for tracker-less torrents, peer exchanges, and UDP tracker support, optimized for private trackers. ```rTorrent Configuration dht.mode.set = disable protocol.pex.set = no trackers.use_udp.set = no ``` -------------------------------- ### Configuration Template - Resource Limits Source: https://rtorrent-docs.readthedocs.io/en/latest/cookbook.html Defines limits for open HTTP connections, open files, and open sockets, optimized for a ulimit of 1024. ```rTorrent Configuration network.http.max_open.set = 50 network.max_open_files.set = 600 network.max_open_sockets.set = 300 ``` -------------------------------- ### Example usage of d.multicall2 Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of using the d.multicall2 command to retrieve hash, name, and custom category for items in a view. ```shell $ rtxmlrpc --repr d.multicall2 '' tagged d.hash= d.name= d.custom=category [['91C588B9A9B5A71F0462343BC74E2A88C1E0947D', 'sparkylinux-4.0-x86_64-lxde.iso', 'Software'], ['17C14214B60B92FFDEBFB550380ED3866BF49691', 'sparkylinux-4.0-x86_64-xfce.iso', 'Software']] ``` -------------------------------- ### Test Configuration Drop-in Source: https://rtorrent-docs.readthedocs.io/en/latest/use-cases.html Commands to test the 'drop-in' configuration feature by creating a directory and a sample configuration file, then restarting rTorrent to observe the output. ```bash mkdir -p ~/rtorrent/config.d echo 'print="Hello from config.d!"' >$_/hello.rc ``` -------------------------------- ### execute2 example Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of using execute.throw to call a shell command with features like redirection. The shell is not directly involved, so bash -c is used for shell features. ```plaintext # Write a PID file into the session directory execute.throw = sh, -c, (cat, "echo >", (session.path), "rtorrent.pid", " ", (system.pid)) ``` -------------------------------- ### pyro.view.collapsed.toggle usage Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of how to toggle a collapsed view. ```shell pyro.view.collapsed.toggle = ‹view name› ≫ 0 ``` -------------------------------- ### pyro.collapsed_view.add usage Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of how to add a collapsed view. ```shell pyro.collapsed_view.add = ‹view name› ≫ 0 ``` -------------------------------- ### pyro.view.toggle_visible usage Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of how to toggle the visibility of an item in a view. ```shell pyro.view.toggle_visible = ‹view name› ≫ 0 ``` -------------------------------- ### Default schedule for close_low_diskspace Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of the default schedule for close_low_diskspace. ```shell schedule2 = low_diskspace,5,60,((close_low_diskspace,500M)) ``` -------------------------------- ### d.creation_date usage Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Shows how to get the creation date of a .torrent file. ```shell d.creation_date = ‹hash› ≫ value ‹timestamp› ``` -------------------------------- ### Binding collapse toggle key Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Example of binding the view.collapsed.toggle command to a key. ```rc schedule = bind_collapse,0,0,"ui.bind_key=download_list,*,view.collapsed.toggle=" ``` -------------------------------- ### convert.human_size examples Source: https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html Converts a size in bytes to a compact, human readable string. ```bash convert.human_size = ‹bytes›[, ‹format›] ≫ string ``` ```bash $ rtxmlrpc --repr convert.human_size '' +970 +0 ' 0.9K' $ rtxmlrpc --repr convert.human_size '' +970 +1 ' 1K' $ rtxmlrpc --repr convert.human_size '' +970 +10 '0.9K' $ rtxmlrpc --repr convert.human_size '' +0 +2 '0.0K' $ rtxmlrpc --repr convert.human_size '' +0 +10 ' ' ```