Package: tofipa
tofipafinds files from a torrent beneath a bunch of download locations and
the relevant download location is printed. Optionally, the torrent is added to a
BitTorrent client with the relevant download location.Matching files are found by name first and, if that fails, by comparing the file
size and then a few piece hashes.Renamed files are linked to the paths expected by the torrent beneath the
download location of the renamed files.Hard links are created if possible, symbolic links are used as a fallback.A default download location is used if not even a single file from the torrent
can be found.The only output onstdoutis the download location. If the torrent is added
to a BitTorrent client, there is no output. Errors and warnings are printed tostderr.ContentsAlgorithmInstallationConfiguration~/.config/tofipa/locationsExamplelocations~/.config/tofipa/clients.iniOptionsClient URLsExampleclients.ini~/.config/tofipa/config.cfgOptionscopy_torrent_toOptionEnvironment VariablesAlgorithmTORRENTrefers to the provided torrent file.LOCATIONis a download directory (the download path without the torrent’s
name) provided via--locationand~/.config/tofipa/locations.Find files fromTORRENTin the file system. For each file inTORRENT:Find a file beneath eachLOCATIONwith the same size.Sort multiple size matching files by file name similarity. The file name
most similar to the one inTORRENTis processed first.Hash some pieces to confirm the file content is whatTORRENTexpects.If at least one matching file is found, set the download location to theLOCATIONof the first matching file.If there are no matching files, set the download location to the location
specified via--defaultor the firstLOCATION.Make sure every matching file exists beneath the download location with the
same relative path as inTORRENT. Try to create a hard link and default
to a symbolic link if source and target are on different file systems.If a client is configured and--noclientis not given, addTORRENTto
the client specified via--clientor the first client in~/.config/tofipa/clients.ini.If no client is configured or--noclientis given, print the download
location to stdout. This is the only output on stdout.Installationtofipais onPyPI. The recommended
installation method is withpipx:$pipxinstalltofipaConfigurationBesides command line options, there are configuration files in$XDG_CONFIG_HOME/tofipa/. If$XDG_CONFIG_HOMEis not set, it defaults to~/.config/.~/.config/tofipa/locations~/.config/tofipa/locationsis a simple list of download directories. These
are searched for torrent files. There is some support for globbing and
environment variables.Any directories provided via the--locationargument are searched first in
addition to the directories from~/.config/locations.Examplelocations# Lines that start with "#" and empty lines are ignored.

# The first download location is the default that is used if no matches are
# found and --default is not given.
/downloads/

# More directories can be listed individually.
/stuff/various/
/stuff/more/
/stuff/other/

# ... or you can use "*" to include all subdirectories.
/stuff/*

# Environment variables can be used as usual. There is no support for fancy
# expansion stuff like "${FOO:-bar}".
# NOTE: To keep you sane, unset and empty environment variables are an
# error case.
$HOME/downloads~/.config/tofipa/clients.ini~/.config/tofipa/clients.inicontains all the information that is needed to
add a torrent to a BitTorrent client. Section names are arbitrary strings that
can be passed to--client. If--clientis not given, the first client in~/.config/tofipa/clients.iniis used.Comments start with#.OptionsOptionDescriptionValid ValuesDefaultclientName of the BitTorrent clientdeluge,qbittorrent,rtorrent,transmissionMust be provided for every sectionurlHow to connect toclientSee belowSee belowusernameUsername for authentication againstclientAny stringEmptypasswordPassword for authentication againstclientAny stringEmptyverifyWhether a torrent should be hash checked by the client after it is addedtrue/false, yes/no, on/off, 1/0truefortransmission,falsefor other clientsstoppedWhether a torrent should be active right awaytrue/false, yes/no, on/off, 1/0falseClient URLsClientFormatDefaultdeluge[USERNAME:PASSWORD@]HOST[:PORT]localhost:58846qBittorrent[http[s]://][USERNAME:PASSWORD@]HOST[:PORT]http://localhost:8080rTorrent[scgi://]HOST[:PORT]or[file://]SOCKET_PATHorhttp[s]://[USERNAME:PASSWORD@]HOST[:PORT][/PATH]scgi://127.0.0.1:5000Transmission[http[s]://][USERNAME:PASSWORD@]HOST[:PORT][/PATH]http://localhost:9091/transmission/rpcExampleclients.ini[foo]
client = qbittorrent
url = localhost:5000
username = hunter1
password = hunter2

[bar]
client = rtorrent
url = http://localhost:12345
verify = true

[baz]
client = transmission
stopped = yes~/.config/tofipa/config.cfg~/.config/tofipa/config.cfgcontains generic configuration options. It’s an
INI file without sections, justoption = valuepairs.List values are separated by newline characters with one or more spaces after
it:after_location_found_commands = echo "$TOFIPA_TORRENT_NAME: $TOFIPA_TORRENT_LOCATION"
    chmod u+r "$TOFIPA_TORRENT_PATH"
    ls -l "$TOFIPA_TORRENT_PATH"OptionsOptionDescriptionumaskFile mode creation mask for created directories, e.g.022or002(seeman 1 chmodorhttps://en.wikipedia.org/wiki/umask)copy_torrent_toCopyTORRENTto this path template (seecopy_torrent_to Optionbelow)before_location_search_commandsList of shell commands to run before searching for files inTORRENTafter_location_found_commandsList of shell commands to run after the download location ofTORRENTis foundafter_torrent_handled_commandsList of shell commands to run after the determinedLOCATIONofTORRENTwas printed orTORRENTwas added to a clientcopy_torrent_toOptionEveryTORRENTis copied tocopy_torrent_tofrom~/.config/tofipa/config.cfg. Ifcopy_torrent_tois not set,TORRENTis not copied.copy_torrent_tocan be a directory or a torrent file. It can
contain placeholders from the table below. Any string enclosed by braces
(e.g.{infohash}) is a placeholder. If you need actual braces in the path, you
need to double them:{{infohash}}If the path doesn’t end with.torrent, it is assumed to be a directory and
the original file name fromTORRENTis appended as the file name.Example:/tmp/tofipa/{current_date}/{tracker}/{infohash}.{name}.{torrent_datetime}.torrentPlaceholderDescriptionfilenameFile name part ofTORRENTnameTorrent name ofTORRENT(read from metadata)infohashInfohash ofTORRENTtrackerName of the first tracker inTORRENTornotrackerif it doesn’t
have any trackerscurrent_dateCurrent date in YYYY-MM-DD formatcurrent_timeCurrent time in HH:MM:SS formatcurrent_datetimeCurrent date and time in YYYY-MM-DDTHH:MM:SS formattorrent_dateTORRENTcreation date in YYYY-MM-DD format ornodatetorrent_timeTORRENTcreation time in HH:MM:SS format ornotimetorrent_datetimeTORRENTcreation date and time in YYYY-MM-DDTHH:MM:SS format ornodatetimeEnvironment VariablesThe environments of the*_commandsare populated with these variables:VariableDescriptionTOFIPA_TORRENT_FILETorrent file path as provided (i.e.TORRENT)TOFIPA_TORRENT_NAMEName of the torrentTOFIPA_TORRENT_LOCATIONDownload location ofTORRENT(always empty forbefore_location_search_commands)TOFIPA_TORRENT_PATHSame as$TOFIPA_TORRENT_LOCATION/$TOFIPA_TORRENT_NAME, but always
empty forbefore_location_search_commands