aboutsummaryrefslogtreecommitdiff
path: root/ext/js/media
diff options
context:
space:
mode:
authorStefan Vuković <stefanvukovic44@gmail.com>2024-07-01 11:51:10 +0200
committerGitHub <noreply@github.com>2024-07-01 09:51:10 +0000
commit9261a70a564034badf2c2b8c6859c46b295adb3d (patch)
tree1517f37d5d368db2104fa0b5d38677cb65705803 /ext/js/media
parentf243608010746b8268f8658b40bd38bc4e337a98 (diff)
make non-ja audio work without configuration (#1152)
* add audio source for wiktionary format filenames on commons * allow region codes * fix files being saved in anki as mp3 * wip * refactor _getAvailableAudioSourceTypes * update docs * wording * single line list * fix no anki audio
Diffstat (limited to 'ext/js/media')
-rw-r--r--ext/js/media/audio-downloader.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/ext/js/media/audio-downloader.js b/ext/js/media/audio-downloader.js
index 99ca1dfd..17911c3e 100644
--- a/ext/js/media/audio-downloader.js
+++ b/ext/js/media/audio-downloader.js
@@ -90,7 +90,8 @@ export class AudioDownloader {
*/
async downloadTermAudio(sources, preferredAudioIndex, term, reading, idleTimeout, languageSummary) {
const errors = [];
- for (const source of sources) {
+ const requiredAudioSources = this._getRequiredAudioSources(languageSummary.iso, sources);
+ for (const source of [...sources, ...requiredAudioSources]) {
let infoList = await this.getTermAudioInfoList(source, term, reading, languageSummary);
if (typeof preferredAudioIndex === 'number') {
infoList = (preferredAudioIndex >= 0 && preferredAudioIndex < infoList.length ? [infoList[preferredAudioIndex]] : []);
@@ -116,6 +117,31 @@ export class AudioDownloader {
// Private
/**
+ * @param {string} language
+ * @param {import('audio').AudioSourceInfo[]} sources
+ * @returns {import('audio').AudioSourceInfo[]}
+ */
+ _getRequiredAudioSources(language, sources) {
+ /** @type {Set<import('settings').AudioSourceType>} */
+ const requiredSources = language === 'ja' ?
+ new Set([
+ 'jpod101',
+ 'jpod101-alternate',
+ 'jisho',
+ ]) :
+ new Set([
+ 'lingua-libre',
+ 'wiktionary',
+ ]);
+
+ for (const {type} of sources) {
+ requiredSources.delete(type);
+ }
+
+ return [...requiredSources].map((type) => ({type, url: '', voice: ''}));
+ }
+
+ /**
* @param {string} url
* @param {string} base
* @returns {string}