Browse Source

fix media data wrong offset #18

pull/19/head
Nzix 6 years ago
parent
commit
7a669e4d22
  1. 12
      ncmdump.py

12
ncmdump.py

@ -28,8 +28,9 @@ def dump(input_path, output_path = None, skip = True):
header = f.read(8) header = f.read(8)
assert binascii.b2a_hex(header) == b'4354454e4644414d' assert binascii.b2a_hex(header) == b'4354454e4644414d'
# key data
f.seek(2, 1) f.seek(2, 1)
# key data
key_length = f.read(4) key_length = f.read(4)
key_length = struct.unpack('<I', bytes(key_length))[0] key_length = struct.unpack('<I', bytes(key_length))[0]
@ -65,16 +66,17 @@ def dump(input_path, output_path = None, skip = True):
else: else:
meta_data = {'format': 'flac' if os.fstat(f.fileno()).st_size > 1024 ** 2 * 16 else 'mp3'} meta_data = {'format': 'flac' if os.fstat(f.fileno()).st_size > 1024 ** 2 * 16 else 'mp3'}
# crc32 f.seek(5, 1)
crc32 = f.read(4)
crc32 = struct.unpack('<I', bytes(crc32))[0]
# album cover # album cover
f.seek(5, 1) image_space = f.read(4)
image_space = struct.unpack('<I', bytes(image_space))[0]
image_size = f.read(4) image_size = f.read(4)
image_size = struct.unpack('<I', bytes(image_size))[0] image_size = struct.unpack('<I', bytes(image_size))[0]
image_data = f.read(image_size) if image_size else None image_data = f.read(image_size) if image_size else None
f.seek(image_space - image_size, 1)
# media data # media data
output_path = output_path(input_path, meta_data) output_path = output_path(input_path, meta_data)
if skip and os.path.exists(output_path): return if skip and os.path.exists(output_path): return

Loading…
Cancel
Save