如何在 rTorrent 中从 Firefox 打开磁力种子链接?

如何在 rTorrent 中从 Firefox 打开磁力种子链接?

我正在使用命令行 torrent 客户端rTorrent在 Xenial Xerus 的领导下,我希望:

  1. 查找并点击磁铁使用 Firefox 进行种子链接
  2. 让 rTorrent 自动打开磁力链接并开始下载

我相信需要从 Firefox 内部调用一个脚本,但是编写这样的脚本迄今为止让我感到很困惑...

答案1

问题通常在于 MIME 类型和默认处理程序。

首先,您是否更改了 Firefox 的about:config设置?例如:

network.protocol-handler.expose.magnet -> false

并重置其他选项 按照 Firefox deluge Q&A。

您是否已设置 rTorrent 来监视任何特定目录?

文件: ~/.rtorrent.rc

# Maximum and minimum number of peers to connect to per torrent.
min_peers = 50
max_peers = 80

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

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

# Default directory to save the downloaded torrents.
directory = $HOME/torrents/downloads

# Watch a directory for new torrents
# SET your watch directory here --v 
schedule = watch_directory,5,5,$HOME/torrents/watch/*.torrent

port_range = 60125-64125
port_random = yes
dht = auto

# UDP port to use for DHT.
dht_port = 63425

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

# Check hash for finished torrents.
check_hash = yes

encryption = allow_incoming,try_outgoing ,enable_retry

然后只需简单地“另存为”即可$HOME/torrents/watch

更改$HOME/torrents/watch为您使用的任何 torrents 子文件夹,或者至少将 $HOME 更改为 /home/username

创建一个文件并添加以下脚本:

文件:maglink-rtorrent.sh

#!/bin/bash

cd $HOME/torrents/watch    # set your watch directory here
[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"

不要忘记使其可执行

chmod +x maglink-rtorrent.sh

这也提供了通过以下方式从终端下载的功能:

cd $HOME/torrents/watch
./maglink-rtorrent.sh "MAGNET-LINK-HERE"

更加棒服务提示和 rTorrent 设置选项在这里

更多致谢:

更新 2:

如果不使用 rTorrent,而是使用 kTorrent 或 qBittorent,则以下是运行它的方法:

# check defaults
xdg-mime query default x-scheme-handler/magnet
gvfs-mime --query x-scheme-handler/magnet

# set defaults
xdg-mime default qBittorent.desktop x-scheme-handler/magnet
gvfs-mime --set x-scheme-handler/magnet qBittorrent.desktop

还有一个进一步的设置(来自内存)来确定您是否需要命令行。

但对于 rTorrent 来说,这个链接是FlexGet rTorrent 磁力链接 URI 处理器

完整信息在此。

希望这可以帮助。

答案2

以下脚本是马克斯·冈齐的代码它适用于常规 .torrent 文件和磁力链接:

#!/bin/bash

torrent_file_or_magnet_link="$1"

# Edit rtorrent.rc to automatically start downloads when a .torrent file
# appears in this directory.
cd "$HOME/.rtorrent/watch/start/"

# XT stands for "exact topic".
# BTIH is the BitTorrent info hash:
# https://en.wikipedia.org/wiki/Magnet_URI_scheme#BitTorrent_info_hash_(BTIH)
# This is the hex-encoded SHA-1 hash of the torrent file info section
magnet_regex="xt=urn:btih:([^&/]+)"
if [[ "$torrent_file_or_magnet_link" =~ $magnet_regex ]]; then
  torrent_hash=${BASH_REMATCH[1]};
  magnet_link_length=${#torrent_file_or_magnet_link}
  # To conform with the bencode encoding, the magnet link's number of characters
  # must be part of the torrent file, otherwise rTorrent can't read it.
  # Same for the "e" at the end.
  # See https://en.wikipedia.org/wiki/Bencode
  torrent_file_content="d10:magnet-uri${magnet_link_length}:${torrent_file_or_magnet_link}e"

  # Note that rTorrent will read this torrent file, start downloading
  # the file and then remove the torrent file
  echo "$torrent_file_content" > "$torrent_hash.torrent"
else
  cp "$torrent_file_or_magnet_link" .
fi

您可以在脚本中使用它(我们称之为pass_to_rtorrent.sh),并让 Firefox 将 torrent 文件或磁力链接传递给脚本:

Firefox rTorrent 截图

确保脚本是可执行的:chmod +x pass_to_rtorrent.sh

相关内容