Fix error from reading past end of file
Save chapter start times to file Note that get_chapter_text doesn't work
This commit is contained in:
parent
20eea6848a
commit
f04c214e63
@ -35,6 +35,12 @@ def main(in_file, out_file, dll_path=None):
|
|||||||
|
|
||||||
print('c', channels, 's', sample_rate)
|
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)
|
enc_buf = ctypes.create_string_buffer(0x400)
|
||||||
dec_buf = ctypes.create_string_buffer(0x400 * 200)
|
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()
|
data_len = ctypes.c_uint()
|
||||||
res = dll.AAXGetEncodedAudio(handle, buf, len(buf), byref(data_len))
|
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))
|
raise Exception('AAXGetEncodedAudio: {}'.format(res))
|
||||||
|
|
||||||
return buf, data_len.value
|
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):
|
def get_chapter_text(dll, handle, chapter_num, buf=None):
|
||||||
|
'''
|
||||||
|
Possibly doesn't exist?
|
||||||
|
'''
|
||||||
if buf is None:
|
if buf is None:
|
||||||
buf = ctypes.create_string_buffer(0x400)
|
buf = ctypes.create_string_buffer(0x800)
|
||||||
|
|
||||||
data_len = ctypes.c_uint()
|
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:
|
if res != 0:
|
||||||
raise Exception('AAXGetChapterText: {}'.format(res))
|
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):
|
def get_metadata(dll, handle, mdn):
|
||||||
@ -213,7 +226,7 @@ def get_playback_position(dll, handle):
|
|||||||
|
|
||||||
def get_chapter_start_time(dll, handle, chapter):
|
def get_chapter_start_time(dll, handle, chapter):
|
||||||
position = ctypes.c_uint()
|
position = ctypes.c_uint()
|
||||||
res = dll.AAXGetChapterStartTime(handle, byref(position), chapter)
|
res = dll.AAXGetChapterStartTime(handle, ctypes.c_uint(chapter), byref(position))
|
||||||
|
|
||||||
if res != 0:
|
if res != 0:
|
||||||
raise Exception('AAXGetChapterStartTime: {}'.format(res))
|
raise Exception('AAXGetChapterStartTime: {}'.format(res))
|
||||||
|
Loading…
Reference in New Issue
Block a user