Skip to content

Instantly share code, notes, and snippets.

@Sispheor
Created February 25, 2022 16:44

Revisions

  1. Sispheor created this gist Feb 25, 2022.
    38 changes: 38 additions & 0 deletions deluge_tracker_rename.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    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")