python - 在 Ubuntu 上使用 python 打开磁力链接

标签 python hyperlink transmission utorrent

我有一个来自 torrent 站点的磁力链接,可以打开这个名为 Transmission 的程序。我如何使用 Python 打开它?

顺便说一句,我在 ubuntu 上。 我听说这个名为 xdg-open 的东西可以解决这个问题,但是我如何使用它来打开磁力链接?

如果这不是我正在寻找的代码,我应该使用什么来运行磁力链接?

最佳答案

查看 transmission-gtk 的命令行参数会有所帮助:

$ transmission-gtk --help

Usage: transmission-gtk [OPTION...] [torrent files or urls]

Python 解决方案的一种快速但肮脏的方法是使用 os模块:

import os
os.system("transmission-gtk urlhere")

对外部程序进行此类调用的更好、更复杂的方法是使用 subprocess模块。更多示例可以在python - how to create a subprocess?下找到。 .

xdg-open 的工作方式几乎相同。但它不是直接调用传输客户端,而是选择首选的 Torrent 应用程序(本例中的首选表示默认应用程序,可以使用 Ubuntu 系统设置中的默认应用程序菜单进行设置)。反复向您指出通过从命令行调用程序给出的帮助文本,检查 xdg-open 的退出代码可能会很有趣:

$ xdg-open --manual

...

1 Error in command line syntax.

2 One of the files passed on the command line did not exist.

3 A required tool could not be found.

4 The action failed.

关于python - 在 Ubuntu 上使用 python 打开磁力链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9630569/

相关文章:

Python-多线程套接字

c - Transmission-daemon 只是停止通量

linux - 下载完成后,传输守护程序启动程序

python - 修改类中多个方法的调用参数

Python - 多个if语句被忽略

python - 均方位移作为 Python 中的时间函数

c# - 使用 htmlagilitypack 选择具有特定文本值的节点

html - 图片超链接不可点击

Android ACTION_SEND 超链接在 GMail 中不起作用

linux数据包传输时间戳