Skip to content

Instantly share code, notes, and snippets.

@oglops
Created January 9, 2023 01:58
Show Gist options
  • Save oglops/65fcae79d18c544a93ea24c9180a577a to your computer and use it in GitHub Desktop.
Save oglops/65fcae79d18c544a93ea24c9180a577a to your computer and use it in GitHub Desktop.
remove unwanted tags
import qbittorrentapi
# instantiate a Client using the appropriate WebUI configuration
client = qbittorrentapi.Client(
host='http://192.168.0.x',
port=xxxx,
username='admin',
password='xxxx',
)
# the Client will automatically acquire/maintain a logged-in state
# in line with any request. therefore, this is not strictly necessary;
# however, you may want to test the provided login credentials.
try:
client.auth_log_in()
except qbittorrentapi.LoginFailed as e:
print(e)
bad_tags = set()
torrent_tags = set()
for torrent in list(client.torrents_info()):
tags = [ x.strip() for x in torrent.tags.split(',')]
torrent_tags.update(tags)
if 'private' not in torrent.trackers[0]['msg']:
# public torrent
# print(f'{torrent.hash[-6:]}: {torrent.name} ({torrent.state})')
bad_tags.update(tags)
# break
if bad_tags:
print(f'bad: {bad_tags}')
client.torrent_tags.delete_tags(tags=bad_tags)
all_tags = set(client.torrent_tags.tags)
empty_tags = all_tags - torrent_tags
if empty_tags:
print(f'empty: {empty_tags}')
client.torrent_tags.delete_tags(tags=empty_tags)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment