Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbsds/21df8f83d48e7e355d8af6b6862cef05 to your computer and use it in GitHub Desktop.
Save pbsds/21df8f83d48e7e355d8af6b6862cef05 to your computer and use it in GitHub Desktop.
Use this to convert transmissions .resume files from an old installation with different file hierarchy
from pathlib import Path
OLD = b"/old/downloads/dir/"
NEW = b"/new/downloads/dir/"
for fname in Path(".").glob("*.resume"):
print(fname)
with fname.open("rb") as f:
data = f.read()
count = 0
while b':/mnt/downloads/' in data:
count += 1
offset_sep = data.find(b':' + OLD)
offset_num = offset_sep - 1
while data[offset_num-1:offset_num].isdigit():
offset_num -= 1
length = int(data[offset_num:offset_sep])
path = data[offset_sep+1:offset_sep+1+length]
assert path.startswith(OLD)
head = data[:offset_num]
tail = data[offset_sep+1+length:]
path = path.replace(OLD, NEW)
data = head + str(len(path)).encode() + b':' + path + tail
print(count, "entries changed.")
with fname.open("wb") as f:
f.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment