aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-10 19:18:28 -0500
committerGitHub <noreply@github.com>2021-02-10 19:18:28 -0500
commit07cd006127c23c17e5c750122a4ac6916994bc76 (patch)
treede4ab1f7005181790f598d9e12d7ffffc1e09a38 /ext/bg/js/backend.js
parent673952e82576b0bc4b6b02c2105fbb1850e55950 (diff)
Add support for multiple types of audio (#1366)
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js9
1 files changed, 6 insertions, 3 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 465c8137..e5f8466e 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -1604,8 +1604,9 @@ class Backend {
const {sources, customSourceUrl, customSourceType} = details;
let data;
+ let contentType;
try {
- data = await this._downloadDefinitionAudio(
+ ({data, contentType} = await this._downloadDefinitionAudio(
sources,
expression,
reading,
@@ -1616,13 +1617,15 @@ class Backend {
binary: true,
disableCache: true
}
- );
+ ));
} catch (e) {
// No audio
return null;
}
- let fileName = this._generateAnkiNoteMediaFileName('yomichan_audio', '.mp3', timestamp, definitionDetails);
+ let extension = this._mediaUtility.getFileExtensionFromAudioMediaType(contentType);
+ if (extension === null) { extension = '.mp3'; }
+ let fileName = this._generateAnkiNoteMediaFileName('yomichan_audio', extension, timestamp, definitionDetails);
fileName = fileName.replace(/\]/g, '');
await ankiConnect.storeMediaFile(fileName, data);