Update audio downloading to support specifying an exact array index (#1405)
This commit is contained in:
parent
7027d537a9
commit
f2a387237b
@ -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) {
|
async _injectAnkNoteMedia(ankiConnect, timestamp, definitionDetails, audioDetails, screenshotDetails, clipboardDetails) {
|
||||||
let screenshotFileName = null;
|
let screenshotFileName = null;
|
||||||
let clipboardImageFileName = null;
|
let clipboardImageFileName = null;
|
||||||
@ -1701,12 +1697,13 @@ class Backend {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {sources, customSourceUrl, customSourceType} = details;
|
const {sources, preferredAudioIndex, customSourceUrl, customSourceType} = details;
|
||||||
let data;
|
let data;
|
||||||
let contentType;
|
let contentType;
|
||||||
try {
|
try {
|
||||||
({data, contentType} = await this._downloadDefinitionAudio(
|
({data, contentType} = await this._audioDownloader.downloadExpressionAudio(
|
||||||
sources,
|
sources,
|
||||||
|
preferredAudioIndex,
|
||||||
expression,
|
expression,
|
||||||
reading,
|
reading,
|
||||||
{
|
{
|
||||||
|
@ -1487,7 +1487,7 @@ class Display extends EventDispatcher {
|
|||||||
|
|
||||||
const timestamp = Date.now();
|
const timestamp = Date.now();
|
||||||
const definitionDetails = this._getDefinitionDetailsForNote(definition);
|
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 screenshotDetails = (this._ankiNoteBuilder.containsMarker(fields, 'screenshot') ? {tabId: this._contentOriginTabId, frameId: this._contentOriginFrameId, format, quality} : null);
|
||||||
const clipboardDetails = {
|
const clipboardDetails = {
|
||||||
image: this._ankiNoteBuilder.containsMarker(fields, 'clipboard-image'),
|
image: this._ankiNoteBuilder.containsMarker(fields, 'clipboard-image'),
|
||||||
|
@ -49,9 +49,12 @@ class AudioDownloader {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadExpressionAudio(sources, expression, reading, details) {
|
async downloadExpressionAudio(sources, preferredAudioIndex, expression, reading, details) {
|
||||||
for (const source of sources) {
|
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) {
|
for (const info of infoList) {
|
||||||
switch (info.type) {
|
switch (info.type) {
|
||||||
case 'url':
|
case 'url':
|
||||||
|
Loading…
Reference in New Issue
Block a user