Created
March 2, 2022 21:47
-
-
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
This file contains 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
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