Skip to content

Instantly share code, notes, and snippets.

@Sispheor
Created February 25, 2022 16:44
Show Gist options
  • Save Sispheor/0985151e2aacd2fc7fe5fae0780ed24e to your computer and use it in GitHub Desktop.
Save Sispheor/0985151e2aacd2fc7fe5fae0780ed24e to your computer and use it in GitHub Desktop.
Deluge bulk tracker rename
import os
import sys
import platform
import shutil
import pickle as cPickle
# Config
orig_tracker_url = [
"http://domain.net:8080/key/announce",
"http://domain2.net:8080/key/announce",
]
new_tracker_url = "http://new.domain:8080/key/announce"
state_file_path = os.path.expanduser('/data/deluge/.config/deluge/state/torrents.state')
# Run
state_file = open(state_file_path, 'rb')
state = cPickle.load(state_file)
state_file.close()
state_modified = False
for torrent in state.torrents:
for idx, tracker in enumerate(torrent.trackers[:]):
#print(tracker['url'])
if tracker['url'] in orig_tracker_url:
#print(torrent.trackers[idx]['url'])
torrent.trackers[idx]['url'] = new_tracker_url
state_modified = True
if state_modified:
shutil.copyfile(state_file_path, state_file_path + '.old')
state_file = open(state_file_path, 'wb')
cPickle.dump(state, state_file)
state_file.close()
print("State Updated")
else:
print("Nothing to do")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment