I use rtorrent. When using magnetic-links, it creates a "meta"-file (.meta). This gets the form of a long hexadecimal-number (0-9, A-F). For example:


To "use" an existing meta-file to start rtorrent, you can first "isolate" the file-name without the suffix (without ".meta").


This hexadecimal-number part is actually (always?) 41 characters long.

Then you must add the protocol before it and a list of trackers after.


It would be great if it was possible to change the list of trackers. Ideally, the URLs for trackers should be read from a file with one tracker per line - adding &tr= where needed. Trackers uses either http:// or udp:// as protocols, and often port-number must be specified (with :port at the end).

An example of an actual "tracker-tail" (the part after the hexadecimal-number) could be:


It must however be possible to change these, and ideally they should be listed in a separate file.

Such a file could for example contain:



(Note: Trackers also uses http:// as protocol)

The result, after removing .meta"= and adding magnet:... and &tr=... - in quotes to be sure & doesn't confuse bash - can then be passed to rtorrent as argument.

What I'd like is a script that can automate this conversion-process, and pass the result to rtorrent. Preferably one that could take multiple meta-files as argument (e.g. expanded by bash from *.meta), and pass them all - converted - as arguments to one rtorrent instance (which the script starts).

rtorrent "magnet:...12345..." "magnet:...6789..." "magnet:...ABCD..."

Unfortunately, I'm really horrid at writing bash-scripts, so does anybody here know how something like this could be done?

  • What is desired output? Mar 16, 2016 at 11:07
  • @don_crissti No, the protocol of trackers is either http:// or udp://. The "prefix/protocol" of the magnet (before the hexadecimal) is always "magnet:?xt=urn:btih:" Typical tracker "tail": &tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A80&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969 Mar 16, 2016 at 11:41
  • 1
    Could you please edit your question to put that info in (properly formatted) rather than leaving it in the comments?
    – Wildcard
    Mar 16, 2016 at 11:45
  • @user1700494 I thought the script may start/spawn rtorrent "internally". But what rtorrent need would be one - or preferably several - argument(s) in the form I mentioned, where the hexadecimal parts were parsed from the file-names of the meta-files passed to the script as arguments (only the name - not the actual content of the file - would be used). After the "converted" arguments were passed to rtorrent, rtorrent would "take over" the script, showing rtorrent's interface. Mar 16, 2016 at 11:50

1 Answer 1


Here is a snippet do do the conversion in bash.


# The array of results passed to rtorrent in the end

# The file listing the trackers is the first argument
# create the tracker list url part.
# sed reads the file and puts '&tr=' before each line,
# then it replaces all : and / with the percent escaped version for urls.
# tr deletes all newlines (turning the text into one long line)
tracker_list_for_url="$(sed 's/^/&tr=/;s/:/%3A/g;s#/#%2F#g' < "$trackers" \
                        | tr -d '\n')"

# loop over arguments and add them to $results
for arg in "$@"; do
  # remove the extension
  # append to results array
exec rtorrent "${results[@]}"

I don't yet understand which program in your scenario calls which program and when and how arguments are created and passed to other programs. So I made these assumptions:

  1. you call your script with the tracker list file as 1st argument and the meta files as the rest of the arguments
  2. your script should start rtorrent

If these assumptions are wrong please clarify or use the above script and adopt it to your need.

  • don_crissti is right, I'd like (if possible) to pass one or more meta-files - for example the result of bash expanding *.meta. I guess the tracker-file could be passed as the first argument, but it would also be acceptable to "hardcode" it into the script (would perhaps be best) - or maybe as a shell-variable. I can certainly use your script as it is, but it would be even better if it could take several meta-files as argument and pass them all as arguments to the same rtorrent. Anyway, you gave me a great place to start... Thanks! Mar 16, 2016 at 12:43
  • I should add that the content of the meta-files aren't actually used by the script - only the file-names of the meta-files. (rtorrent itself uses the content however) Mar 16, 2016 at 12:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .