/ #torrent #passkey 

Bulk Updating Torrent File Passkeys

You can find the hunnyb library on pastebin

This was originally for torrents in Transmission but should work on any folder of torrents to update the passkey.

import hunnyb
import os
 
passkey = raw_input("Enter passkey:").strip()
path = raw_input("Enter path of torrent files, hit enter for defualt path -> '~/Library/Application Support/Transmission/Torrents'\n:").strip()
if len(path) == 0:
    path = "~/Library/Application Support/Transmission/Torrents"
path = os.path.expanduser(path)
dirList=os.listdir(path)
print "Starting."
for f_name in dirList:
    if f_name == ".DS_Store":
        continue
 
    try:    
        print "Working on file %s\n" % f_name
 
        f=open("%s/%s" % (path,f_name))
        data=f.read()
        see = data.decode('bencode')
        see = eval(see)
 
        if 'trackername' in see['announce']:
            new_passkey = "http://trackername.me:42532/%s/announce" % passkey
            see['announce'] = new_passkey
            see = hunnyb.encode(see)
            new_file = open("%s/%s" % (path,f_name), 'wb')
            new_file.write(see)
            new_file.close()
            print "Finished updating passkey."
        else:
            print "Not a trackername torrent"
        f.close()
 
    except Exception as e:
        print "Failed: %s" % e