首先我不得不说我不知道python是什么。我刚刚从一个网站下载这个文件来修复游戏但它没有用。我所能做的就是检查模块和继续找出我不知道如何修复的语法错误。
import glob, struct, os, time
#(frames, offset)
CORRECT_OFFSETS = {
'z000_1.win32.wmp': [],
'z000_1_us.win32.wmp': [],
'z000_us.win32.wmp': [(5160, 16)],
'z002_1_us.win32.wmp': [],
'z002_1.win32.wmp': [],
'z002_us.win32.wmp': [(3503, 16),
(300, 192218060),
(3209, 206170072),
(2487, 380544968),
(4935, 515381728),
(2614, 783495996),
(3771, 926055480)],
'z003_1.win32.wmp': [],
'z003_1_us.win32.wmp': [],
'z003_us.win32.wmp': [(890, 16),
(1260, 48459248),
(1655, 117355932),
(3948, 187336488),
(3519, 403805692),
(1277, 586686420),
(1425, 655754428),
(4524, 732863232),
(6129, 979373904),
(3864, 1312563632)],
'z004_1.win32.wmp': [],
'z004_1_us.win32.wmp': [],
'z004_us.win32.wmp': [(2226, 16),
(1832, 121399364),
(5319, 222033424),
(3705, 506525476),
(1983, 707701264),
(4549, 815726584),
(3659, 1061123128),
(4544, 1243716124),
(6364, 1490772192)],
'z006_1.win32.wmp': [],
'z006_1_us.win32.wmp': [],
'z006_us.win32.wmp': [(5575, 16),
(2100, 293834120),
(550, 387084972),
(6079, 416998404),
(2799, 743454316),
(6280, 894567360),
(2669, 1235777764)],
'z008_1.win32.wmp': [],
'z008_1_us.win32.wmp': [],
'z008_us.win32.wmp': [(4745, 16),
(1636, 259311488),
(4017, 348757556),
(5056, 561896404),
(1792, 836029048),
(1338, 932748940),
(1498, 1004929368),
(2224, 1085833772),
(2234, 1206194300),
(3768, 1328116396),
(5446, 1533012980),
(3014, 1828393288),
(6379, 1991109064),
(7774, 2336102408),
(2770, 2757514936)],
'z010_1.win32.wmp': [],
'z010_1_us.win32.wmp': [],
'z010_us.win32.wmp': [(2184, 16), (3194, 118867312), (5734, 290475520)],
'z015_1.win32.wmp': [],
'z015_1_us.win32.wmp': [],
'z015_us.win32.wmp': [(4103, 16),
(4379, 220586552),
(280, 456968932),
(979, 472130776),
(981, 525418388)],
'z016_1.win32.wmp': [],
'z016_1_us.win32.wmp': [],
'z016_us.win32.wmp': [(3782, 16),
(6480, 183886044),
(1859, 535752572),
(2834, 637377540),
(5100, 792524584),
(5179, 1069841780),
(4408, 1352921468),
(2744, 1592998080)],
'z017_1.win32.wmp': [],
'z017_1_us.win32.wmp': [],
'z017_us.win32.wmp': [(1597, 16),
(5193, 87344904),
(4263, 363545928),
(2440, 573049548),
(4033, 705570740),
(6760, 924508440),
(4760, 1291548892)],
'z018_1.win32.wmp': [],
'z018_1_us.win32.wmp': [],
'z018_us.win32.wmp': [(1709, 16),
(1499, 84767520),
(4778, 165357228),
(6974, 424118704)],
'z019_1.win32.wmp': [],
'z019_1_us.win32.wmp': [],
'z019_us.win32.wmp': [(28887, 16),
(5995, 1320322644),
(1410, 1638422156),
(1670, 1714374168),
(2425, 1806044880),
(1574, 1937609736),
(1650, 2023546760),
(1528, 2113553256),
(4546, 2197337816),
(2218, 2445721012),
(7167, 2566140476)],
'z020_1.win32.wmp': [],
'z020_1_us.win32.wmp': [],
'z020_us.win32.wmp': [(848, 16)],
'z021_1.win32.wmp': [],
'z021_1_us.win32.wmp': [],
'z021_us.win32.wmp': [(3720, 16), (3962, 203966320), (6172, 418886756)],
'z022_1.win32.wmp': [],
'z022_1_us.win32.wmp': [],
'z022_us.win32.wmp': [(2747, 16)],
'z024_1.win32.wmp': [],
'z024_1_us.win32.wmp': [],
'z024_us.win32.wmp': [(3777, 16), (6448, 203939416)],
'z027_1.win32.wmp': [],
'z027_1_us.win32.wmp': [],
'z027_us.win32.wmp': [(814, 16),
(7481, 42085708),
(1439, 447896256),
(1160, 526298144)],
'z029_1.win32.wmp': [],
'z029_1_us.win32.wmp': [],
'z029_us.win32.wmp': [(6648, 16),
(3403, 362326952),
(6980, 549208352),
(3994, 930114820),
(1470, 1148494148),
(6794, 1225595976),
(1009, 1596274408),
(6009, 1650800068)]}
class BikHeader(object):
def __init__(self, header):
self._raw_header = header
self.sig, self.rev, self.size, self.frames, self.largest_frame, \
self.frames_again, self.width, self.height, self.frame_dividend, \
self.frame_divider, self.flags, self.audio = \
struct.unpack('<3s1sIIIIIIIIII', header)
self.size += 8
def get_offsets(file):
data = []
with open(file, 'rb') as infile:
infile.seek(16) #WMP header
while True:
offset = infile.tell()
header = infile.read(44)
if not header: break
header = BikHeader(header)
if header.sig not in ('BIK', 'KB2'):
raise ValueError, "Bad BIK header " + header.sig
infile.seek(header.size-44, 1)
header.offset = offset
data.append(header)
return data
def realign_this_file(infilename, outfilename, dry=True):
filebasename = os.path.basename(infilename)
target_offsets = CORRECT_OFFSETS[filebasename]
current_offsets = get_offsets(infilename)
if len(target_offsets) != len(current_offsets):
raise ValueError, "Unexpected Video Count %s %d != %d" % ( \
infilename, len(target_offsets), len(current_offsets) )
if os.path.abspath(infilename) == os.path.abspath(outfilename):
raise ValueError, "The input and output file can not be the same"
#The videos in c are not in the same order as r. Using frame count to pair
#up the videos correctly.
offset_lookup = dict(target_offsets)
if len(offset_lookup) != len(target_offsets):
raise ValueError, "Multiple videos with the same number of frames"
MB = 1024**2
read_size = 16*MB
head_size = 16 #WMP Header
if dry:
for current in current_offsets: #match up videos
if current.frames not in offset_lookup:
raise ValueError, "Unable to find matching video"
print (infilename, outfilename)
return
with open(infilename, 'rb') as infile:
with open(outfilename, 'wb') as outfile:
#write the header
data = infile.read(head_size)
outfile.write(data)
for current in current_offsets:
#write the video file
target = offset_lookup[current.frames]
outfile.seek(target)
to_write = current.size
while to_write > 0:
to_read = min(to_write, read_size)
data = infile.read(to_read)
outfile.write(data)
to_write -= len(data)
print '\r', (infile.tell()/MB), ' Megabytes',
if not data:
raise ValueError, "End of File at %d with %d bytes left" % (infile.tell(), to_write)
if target_offsets: print
def realign_all_files(infolder, outfolder, dry=True):
filelist = glob.glob(os.path.join(infolder, '*.wmp'))
for file in filelist:
outfile = os.path.join(outfolder, os.path.basename(file))
if not dry: print "Processing ", outfile
realign_this_file(file, outfile, dry)
def main():
start_time = time.time()
if not os.path.isdir('orig_movie'):
raise ValueError, "Missing orig_movie folder"
if not os.path.isdir('movie'):
if os.path.exists('movie'):
raise ValueError, "Unable to create the movie directory due to an existing file call movie. Please remove that file"
os.mkdir('movie')
print "Checking files"
realign_all_files('orig_movie', 'movie', True)
print
print "Fixing files"
realign_all_files('orig_movie', 'movie', False)
print "Finish. Run time %.2f seconds" % (time.time() - start_time)
if __name__ == '__main__':
main()
同样在Dropbox上:https://www.dropbox.com/s/hof1qxk6uf8cqw3/z.py?dl=0
P.S:拜托,请老友好,正如我上面所说,我完全不知道python.Thanks。
编辑:错误发生在线上&#34; 162&#34; (提出错误,bla,bla,bla ......)
编辑2:现在我收到了这个错误:
>>>
Checking files
('orig_movie\\z000_1.win32.wmp', 'movie\\z000_1.win32.wmp')
('orig_movie\\z000_1_us.win32.wmp', 'movie\\z000_1_us.win32.wmp')
Traceback (most recent call last):
File "E:\Program Files (x86)\Mitiden\Final Fantasy XIII\Final Fantasy XIII\white_data\z.py", line 242, in <module>
main()
File "E:\Program Files (x86)\Mitiden\Final Fantasy XIII\Final Fantasy XIII\white_data\z.py", line 233, in main
realign_all_files('orig_movie', 'movie', True)
File "E:\Program Files (x86)\Mitiden\Final Fantasy XIII\Final Fantasy XIII\white_data\z.py", line 221, in realign_all_files
realign_this_file(file, outfile, dry)
File "E:\Program Files (x86)\Mitiden\Final Fantasy XIII\Final Fantasy XIII\white_data\z.py", line 172, in realign_this_file
current_offsets = get_offsets(infilename)
File "E:\Program Files (x86)\Mitiden\Final Fantasy XIII\Final Fantasy XIII\white_data\z.py", line 162, in get_offsets
raise ValueError("Bad BIK header " + header.sig)
TypeError: Can't convert 'bytes' object to str implicitly
>>>
答案 0 :(得分:0)
代码在python2中。所以你得到了错误。使用此代码:
import glob, struct, os, time
#(frames, offset)
CORRECT_OFFSETS = {
'z000_1.win32.wmp': [],
'z000_1_us.win32.wmp': [],
'z000_us.win32.wmp': [(5160, 16)],
'z002_1_us.win32.wmp': [],
'z002_1.win32.wmp': [],
'z002_us.win32.wmp': [(3503, 16),
(300, 192218060),
(3209, 206170072),
(2487, 380544968),
(4935, 515381728),
(2614, 783495996),
(3771, 926055480)],
'z003_1.win32.wmp': [],
'z003_1_us.win32.wmp': [],
'z003_us.win32.wmp': [(890, 16),
(1260, 48459248),
(1655, 117355932),
(3948, 187336488),
(3519, 403805692),
(1277, 586686420),
(1425, 655754428),
(4524, 732863232),
(6129, 979373904),
(3864, 1312563632)],
'z004_1.win32.wmp': [],
'z004_1_us.win32.wmp': [],
'z004_us.win32.wmp': [(2226, 16),
(1832, 121399364),
(5319, 222033424),
(3705, 506525476),
(1983, 707701264),
(4549, 815726584),
(3659, 1061123128),
(4544, 1243716124),
(6364, 1490772192)],
'z006_1.win32.wmp': [],
'z006_1_us.win32.wmp': [],
'z006_us.win32.wmp': [(5575, 16),
(2100, 293834120),
(550, 387084972),
(6079, 416998404),
(2799, 743454316),
(6280, 894567360),
(2669, 1235777764)],
'z008_1.win32.wmp': [],
'z008_1_us.win32.wmp': [],
'z008_us.win32.wmp': [(4745, 16),
(1636, 259311488),
(4017, 348757556),
(5056, 561896404),
(1792, 836029048),
(1338, 932748940),
(1498, 1004929368),
(2224, 1085833772),
(2234, 1206194300),
(3768, 1328116396),
(5446, 1533012980),
(3014, 1828393288),
(6379, 1991109064),
(7774, 2336102408),
(2770, 2757514936)],
'z010_1.win32.wmp': [],
'z010_1_us.win32.wmp': [],
'z010_us.win32.wmp': [(2184, 16), (3194, 118867312), (5734, 290475520)],
'z015_1.win32.wmp': [],
'z015_1_us.win32.wmp': [],
'z015_us.win32.wmp': [(4103, 16),
(4379, 220586552),
(280, 456968932),
(979, 472130776),
(981, 525418388)],
'z016_1.win32.wmp': [],
'z016_1_us.win32.wmp': [],
'z016_us.win32.wmp': [(3782, 16),
(6480, 183886044),
(1859, 535752572),
(2834, 637377540),
(5100, 792524584),
(5179, 1069841780),
(4408, 1352921468),
(2744, 1592998080)],
'z017_1.win32.wmp': [],
'z017_1_us.win32.wmp': [],
'z017_us.win32.wmp': [(1597, 16),
(5193, 87344904),
(4263, 363545928),
(2440, 573049548),
(4033, 705570740),
(6760, 924508440),
(4760, 1291548892)],
'z018_1.win32.wmp': [],
'z018_1_us.win32.wmp': [],
'z018_us.win32.wmp': [(1709, 16),
(1499, 84767520),
(4778, 165357228),
(6974, 424118704)],
'z019_1.win32.wmp': [],
'z019_1_us.win32.wmp': [],
'z019_us.win32.wmp': [(28887, 16),
(5995, 1320322644),
(1410, 1638422156),
(1670, 1714374168),
(2425, 1806044880),
(1574, 1937609736),
(1650, 2023546760),
(1528, 2113553256),
(4546, 2197337816),
(2218, 2445721012),
(7167, 2566140476)],
'z020_1.win32.wmp': [],
'z020_1_us.win32.wmp': [],
'z020_us.win32.wmp': [(848, 16)],
'z021_1.win32.wmp': [],
'z021_1_us.win32.wmp': [],
'z021_us.win32.wmp': [(3720, 16), (3962, 203966320), (6172, 418886756)],
'z022_1.win32.wmp': [],
'z022_1_us.win32.wmp': [],
'z022_us.win32.wmp': [(2747, 16)],
'z024_1.win32.wmp': [],
'z024_1_us.win32.wmp': [],
'z024_us.win32.wmp': [(3777, 16), (6448, 203939416)],
'z027_1.win32.wmp': [],
'z027_1_us.win32.wmp': [],
'z027_us.win32.wmp': [(814, 16),
(7481, 42085708),
(1439, 447896256),
(1160, 526298144)],
'z029_1.win32.wmp': [],
'z029_1_us.win32.wmp': [],
'z029_us.win32.wmp': [(6648, 16),
(3403, 362326952),
(6980, 549208352),
(3994, 930114820),
(1470, 1148494148),
(6794, 1225595976),
(1009, 1596274408),
(6009, 1650800068)]}
class BikHeader(object):
def __init__(self, header):
self._raw_header = header
self.sig, self.rev, self.size, self.frames, self.largest_frame, \
self.frames_again, self.width, self.height, self.frame_dividend, \
self.frame_divider, self.flags, self.audio = \
struct.unpack('<3s1sIIIIIIIIII', header)
self.size += 8
def get_offsets(file):
data = []
with open(file, 'rb') as infile:
infile.seek(16) #WMP header
while True:
offset = infile.tell()
header = infile.read(44)
if not header: break
header = BikHeader(header)
if header.sig not in ('BIK', 'KB2'):
raise ValueError("Bad BIK header " + header.sig)
infile.seek(header.size-44, 1)
header.offset = offset
data.append(header)
return data
def realign_this_file(infilename, outfilename, dry=True):
filebasename = os.path.basename(infilename)
target_offsets = CORRECT_OFFSETS[filebasename]
current_offsets = get_offsets(infilename)
if len(target_offsets) != len(current_offsets):
raise ValueError("Unexpected Video Count %s %d != %d" % ( \
infilename, len(target_offsets), len(current_offsets) ))
if os.path.abspath(infilename) == os.path.abspath(outfilename):
raise ValueError("The input and output file can not be the same")
#The videos in c are not in the same order as r. Using frame count to pair
#up the videos correctly.
offset_lookup = dict(target_offsets)
if len(offset_lookup) != len(target_offsets):
raise ValueError("Multiple videos with the same number of frames")
MB = 1024**2
read_size = 16*MB
head_size = 16 #WMP Header
if dry:
for current in current_offsets: #match up videos
if current.frames not in offset_lookup:
raise ValueError("Unable to find matching video")
print((infilename, outfilename))
return
with open(infilename, 'rb') as infile:
with open(outfilename, 'wb') as outfile:
#write the header
data = infile.read(head_size)
outfile.write(data)
for current in current_offsets:
#write the video file
target = offset_lookup[current.frames]
outfile.seek(target)
to_write = current.size
while to_write > 0:
to_read = min(to_write, read_size)
data = infile.read(to_read)
outfile.write(data)
to_write -= len(data)
print('\r', (infile.tell()/MB), ' Megabytes', end=' ')
if not data:
raise ValueError("End of File at %d with %d bytes left" % (infile.tell(), to_write))
if target_offsets: print()
def realign_all_files(infolder, outfolder, dry=True):
filelist = glob.glob(os.path.join(infolder, '*.wmp'))
for file in filelist:
outfile = os.path.join(outfolder, os.path.basename(file))
if not dry: print("Processing ", outfile)
realign_this_file(file, outfile, dry)
def main():
start_time = time.time()
if not os.path.isdir('orig_movie'):
raise ValueError("Missing orig_movie folder")
if not os.path.isdir('movie'):
if os.path.exists('movie'):
raise ValueError("Unable to create the movie directory due to an existing file call movie. Please remove that file")
os.mkdir('movie')
print("Checking files")
realign_all_files('orig_movie', 'movie', True)
print()
print("Fixing files")
realign_all_files('orig_movie', 'movie', False)
print("Finish. Run time %.2f seconds" % (time.time() - start_time))
if __name__ == '__main__':
main()