Created
October 19, 2024 13:07
-
-
Save samicrusader/7160887d69ba73c2ad0a87de16ebe22e to your computer and use it in GitHub Desktop.
quick and shit bencode editor for rtorrent session files
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 | |
| def read_value(lol, header): | |
| readfrom = len(lol.split(header)[0]+':') + len(header) + len(lol.split(header)[1].split(':')[0]) | |
| path_size = int(lol.split(header)[1].split(':')[0]) | |
| readto = readfrom + path_size | |
| path = lol[readfrom:readto] | |
| return path, path_size | |
| def replace_value(lol, header, find, replace): | |
| oldpath, oldsize = read_value(lol, header) | |
| newpath = oldpath.replace(find, replace) | |
| return lol.replace(header + str(oldsize) + ':' + oldpath, header + str(len(newpath)) + ':' + newpath) | |
| #data = open('session/6969696969696969696969696969696969696969.torrent.rtorrent', 'r').read() | |
| #replace_value(data, '11:loaded_file', '/mnt/rtorrent/.session', '/var/lib/rtorrent/.session') | |
| for _sf in os.scandir('session/'): | |
| if _sf.name.endswith('.torrent.rtorrent'): | |
| fh = open('session/'+_sf.name, 'r') | |
| data = fh.read() | |
| fh.close() | |
| data = replace_value(data, '11:loaded_file', '/var/lib/rtorrent/.session', '/var/lib/rtorrent/session') | |
| fh = open('session/'+_sf.name, 'w') | |
| fh.write(data) | |
| fh.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment