aboutsummaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-15 20:47:35 -0500
committerGitHub <noreply@github.com>2021-02-15 20:47:35 -0500
commitf2a387237bac02d93d1664ed7acb6a10108915b6 (patch)
tree17db44dea4a4d14ceafd73e608fd53367b0189fe /ext/js
parent7027d537a914cbd5a2f8aa6accf221efeed4af0d (diff)
Update audio downloading to support specifying an exact array index (#1405)
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/background/backend.js9
-rw-r--r--ext/js/display/display.js2
-rw-r--r--ext/js/media/audio-downloader.js7
3 files changed, 9 insertions, 9 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index d88c5853..2a3ccbc2 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -1636,10 +1636,6 @@ class Backend {
}
}
- async _downloadDefinitionAudio(sources, expression, reading, details) {
- return await this._audioDownloader.downloadExpressionAudio(sources, expression, reading, details);
- }
-
async _injectAnkNoteMedia(ankiConnect, timestamp, definitionDetails, audioDetails, screenshotDetails, clipboardDetails) {
let screenshotFileName = null;
let clipboardImageFileName = null;
@@ -1701,12 +1697,13 @@ class Backend {
return null;
}
- const {sources, customSourceUrl, customSourceType} = details;
+ const {sources, preferredAudioIndex, customSourceUrl, customSourceType} = details;
let data;
let contentType;
try {
- ({data, contentType} = await this._downloadDefinitionAudio(
+ ({data, contentType} = await this._audioDownloader.downloadExpressionAudio(
sources,
+ preferredAudioIndex,
expression,
reading,
{
diff --git a/ext/js/display/display.js b/ext/js/display/display.js
index a7c45f19..6a2a3766 100644
--- a/ext/js/display/display.js
+++ b/ext/js/display/display.js
@@ -1487,7 +1487,7 @@ class Display extends EventDispatcher {
const timestamp = Date.now();
const definitionDetails = this._getDefinitionDetailsForNote(definition);
- const audioDetails = (mode !== 'kanji' && this._ankiNoteBuilder.containsMarker(fields, 'audio') ? {sources, customSourceUrl, customSourceType} : null);
+ const audioDetails = (mode !== 'kanji' && this._ankiNoteBuilder.containsMarker(fields, 'audio') ? {sources, preferredAudioIndex: null, customSourceUrl, customSourceType} : null);
const screenshotDetails = (this._ankiNoteBuilder.containsMarker(fields, 'screenshot') ? {tabId: this._contentOriginTabId, frameId: this._contentOriginFrameId, format, quality} : null);
const clipboardDetails = {
image: this._ankiNoteBuilder.containsMarker(fields, 'clipboard-image'),
diff --git a/ext/js/media/audio-downloader.js b/ext/js/media/audio-downloader.js
index 4e77419b..bb8d40a8 100644
--- a/ext/js/media/audio-downloader.js
+++ b/ext/js/media/audio-downloader.js
@@ -49,9 +49,12 @@ class AudioDownloader {
return [];
}
- async downloadExpressionAudio(sources, expression, reading, details) {
+ async downloadExpressionAudio(sources, preferredAudioIndex, expression, reading, details) {
for (const source of sources) {
- const infoList = await this.getExpressionAudioInfoList(source, expression, reading, details);
+ let infoList = await this.getExpressionAudioInfoList(source, expression, reading, details);
+ if (typeof preferredAudioIndex === 'number') {
+ infoList = (preferredAudioIndex >= 0 && preferredAudioIndex < infoList.length ? [infoList[preferredAudioIndex]] : []);
+ }
for (const info of infoList) {
switch (info.type) {
case 'url':