-
-
Save mattatcha/2d4bdd6f0c2079b7c7521e5a2b7b0417 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 os | |
| import platform | |
| import shutil | |
| import cPickle | |
| orig_tracker_url = 'udp://xxx' | |
| new_tracker_url = 'udp://xxx' | |
| if platform.system() in ('Windows', 'Microsoft'): | |
| state_file_path = os.path.join(os.environ.get('APPDATA'), 'deluge', 'torrents.state') | |
| else: | |
| state_file_path = os.path.expanduser('~/.config/deluge/state/torrents.state') | |
| print "State file: %s" % state_file_path | |
| print "Replace '%s' with '%s'" % (orig_tracker_url, new_tracker_url) | |
| state_file = open(state_file_path, 'rb') | |
| state = cPickle.load(state_file) | |
| state_file.close() | |
| state_modified = False | |
| for torrent in state.torrents: | |
| for tracker in torrent.trackers: | |
| if tracker['url'] == orig_tracker_url: | |
| tracker['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