-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_torrent.py
29 lines (22 loc) · 960 Bytes
/
add_torrent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys
import qbittorrentapi
def add_torrent(magnet_link):
# Replace the following variables with your qBittorrent Web UI credentials and address
qb_username = '<USERNAME>'
qb_password = '<PASSWORD>'
qb_address = 'http://IP:PORT'
# Connect to the qBittorrent Web API
qbt_client = qbittorrentapi.Client(host=qb_address, username=qb_username, password=qb_password)
try:
# Log in to the qBittorrent Web API
qbt_client.auth_log_in()
# Add the magnet link as a new torrent
qbt_client.torrents_add(urls=magnet_link)
print(f"Torrent added successfully: {magnet_link}")
except qbittorrentapi.exceptions.LoginFailed as e:
print(f"Failed to log in to qBittorrent Web API: {e}")
if __name__ == "__main__":
if len(sys.argv) > 1:
add_torrent(sys.argv[1])
else:
print("Usage: python add_torrent.py <magnet_link>")