Last active
December 3, 2023 03:57
-
-
Save mylylyl/34db565ffc85493ea49670dabd97cbb8 to your computer and use it in GitHub Desktop.
qbittorrent script to apply tag and upload rate automatically based on tracker url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import qbittorrentapi | |
sites = { | |
"zhuque.in": { | |
"up": 6500000, # 6.5 MBps | |
"tag": "ZhuQue" | |
}, | |
} | |
def get_site(tracker_url): | |
for site, properties in sites.items(): | |
if site in tracker_url: | |
return properties | |
return None | |
def main(hash): | |
# instantiate a Client using the appropriate WebUI configuration | |
conn_info = dict( | |
host="localhost", | |
port=30024, | |
username="admin", | |
password="adminadmin", | |
) | |
with qbittorrentapi.Client(**conn_info) as qbt_client: | |
tags = qbt_client.torrents_tags() | |
trackers = qbt_client.torrents_trackers(torrent_hash=hash) | |
if len(trackers) == 4: | |
site = get_site(trackers[3]['url']) | |
if site is not None: | |
if site['tag'] not in tags: | |
qbt_client.torrents_create_tags([site['tag']]) | |
qbt_client.torrents_add_tags(tags=[site['tag']], torrent_hashes=[hash]) | |
qbt_client.torrents_set_upload_limit(limit=site['up'], torrent_hashes=[hash]) | |
if __name__ == "__main__": | |
if len(sys.argv) > 1: | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment