Update audio downloading to support specifying an exact array index (#1405)

This commit is contained in:
toasted-nutbread 2021-02-15 20:47:35 -05:00 committed by GitHub
parent 7027d537a9
commit f2a387237b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -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,
{

View File

@ -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'),

View File

@ -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':