diff --git a/py_aax_decode/native.py b/py_aax_decode/native.py index d688d05..8410441 100644 --- a/py_aax_decode/native.py +++ b/py_aax_decode/native.py @@ -34,6 +34,12 @@ def main(in_file, out_file, dll_path=None): authenticate(*a) print('c', channels, 's', sample_rate) + + n_chapters = get_chapter_count(*a) + chapter_times = [get_chapter_start_time(*a, i) for i in range(n_chapters)] + + with open(out_file + '.txt', 'w') as f: + [f.write(str(ti) + '\n') for ti in chapter_times] enc_buf = ctypes.create_string_buffer(0x400) dec_buf = ctypes.create_string_buffer(0x400 * 200) @@ -116,7 +122,8 @@ def get_encoded_audio(dll, handle, buf=None): data_len = ctypes.c_uint() res = dll.AAXGetEncodedAudio(handle, buf, len(buf), byref(data_len)) - if res != 0: + if res not in (0, -24): + #-24 is "read past end of data" raise Exception('AAXGetEncodedAudio: {}'.format(res)) return buf, data_len.value @@ -136,16 +143,22 @@ def decode_pcm_frame(dll, handle, in_buf, in_len, out_buf=None): def get_chapter_text(dll, handle, chapter_num, buf=None): + ''' + Possibly doesn't exist? + ''' if buf is None: - buf = ctypes.create_string_buffer(0x400) + buf = ctypes.create_string_buffer(0x800) data_len = ctypes.c_uint() - res = dll.AAXGetChapterText(handle, chapter_num, buf, len(buf), byref(data_len)) + res = dll.AAXGetChapterText(handle, ctypes.c_uint(chapter_num), buf, len(buf), byref(data_len)) + if data_len.value == 0: + return '' + if res != 0: raise Exception('AAXGetChapterText: {}'.format(res)) - return buf, data_len.value + return bytearray(buf[:data_len.value]).decode('utf-8') def get_metadata(dll, handle, mdn): @@ -213,7 +226,7 @@ def get_playback_position(dll, handle): def get_chapter_start_time(dll, handle, chapter): position = ctypes.c_uint() - res = dll.AAXGetChapterStartTime(handle, byref(position), chapter) + res = dll.AAXGetChapterStartTime(handle, ctypes.c_uint(chapter), byref(position)) if res != 0: raise Exception('AAXGetChapterStartTime: {}'.format(res))