Skip to content

Instantly share code, notes, and snippets.

@mylylyl
Last active December 3, 2023 03:57
Show Gist options
  • Save mylylyl/34db565ffc85493ea49670dabd97cbb8 to your computer and use it in GitHub Desktop.
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
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