Audio now works

This commit is contained in:
Alex Yatskov 2016-07-17 10:34:07 -07:00
parent c403c32766
commit 80dee40300

View File

@ -66,10 +66,10 @@ def audioIsPlaceholder(data):
return m.hexdigest() == '7e2c2f954ef6051373ba916f000168dc' return m.hexdigest() == '7e2c2f954ef6051373ba916f000168dc'
def audioInject(note, kana, kanji, fields): def audioInject(note, fields, filename):
for field in fields: for field in fields:
if field in note: if field in note:
note[field] += u'[sound:{}]'.format(audioBuildFilename(kana, kanji)) note[field] += u'[sound:{}]'.format(filename)
# #
@ -243,10 +243,11 @@ class AnkiBridge:
return return
if audio is not None and len(audio['fields']) > 0: if audio is not None and len(audio['fields']) > 0:
data = audioDownload(**audio) data = audioDownload(audio['kana'], audio['kanji'])
if data is not None and not audioIsPlaceholder(data): if data is not None and not audioIsPlaceholder(data):
audioInject(note, **audio) filename = audioBuildFilename(audio['kana'], audio['kanji'])
self.media().writeData(audioBuildFilename(**audio), data) audioInject(note, audio['fields'], filename)
self.media().writeData(filename, data)
self.startEditing() self.startEditing()
collection.addNote(note) collection.addNote(note)