Created
March 12, 2016 10:12
-
-
Save Johni0702/8c0ec958aff47a30a6ca to your computer and use it in GitHub Desktop.
tmcpr recovery script
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
#!/bin/python | |
from zipfile import ZipFile | |
import struct | |
import sys | |
import time | |
def recover(broken): | |
duration = 0 | |
with open(broken) as bf: | |
while True: | |
bDuration = bf.read(4) | |
if len(bDuration) < 4: break | |
duration = struct.unpack('>i', bDuration)[0] | |
bLength = bf.read(4) | |
if len(bLength) < 4: break | |
length = struct.unpack('>i', bLength)[0] | |
if len(bf.read(length)) < length: break | |
with ZipFile(broken[:-5]+'mcpr', 'w') as rf: | |
rf.write(broken, 'recording.tmcpr') | |
rf.writestr('metaData.json', '{"singleplayer":true,"serverName":"Python tmcpr recovery","duration":'+str(duration)+',"date":'+str(int(time.time()*1000))+',"mcversion":"1.8","fileFormat":"MCPR","fileFormatVersion":1,"generator":"Python tmcpr recovery","selfId":-1,"players":[]}') | |
if __name__ == '__main__': | |
for f in sys.argv[1:]: recover(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment