Update audio downloader (#1499)

* Update _getInfoJpod101's empty reading check

* Use URLSearchParams instead of a string
This commit is contained in:
toasted-nutbread 2021-03-06 18:26:16 -05:00 committed by GitHub
parent 16217728af
commit 49bf562690
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,29 +78,31 @@ class AudioDownloader {
} }
async _getInfoJpod101(expression, reading) { async _getInfoJpod101(expression, reading) {
let kana = reading; if (reading === expression && this._japaneseUtil.isStringEntirelyKana(expression)) {
let kanji = expression; reading = expression;
expression = null;
if (!kana && this._japaneseUtil.isStringEntirelyKana(kanji)) {
kana = kanji;
kanji = null;
} }
const params = []; const params = new URLSearchParams();
if (kanji) { if (expression) {
params.push(`kanji=${encodeURIComponent(kanji)}`); params.set('kanji', expression);
} }
if (kana) { if (reading) {
params.push(`kana=${encodeURIComponent(kana)}`); params.set('kana', reading);
} }
const url = `https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?${params.join('&')}`; const url = `https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?${params.toString()}`;
return [{type: 'url', url}]; return [{type: 'url', url}];
} }
async _getInfoJpod101Alternate(expression, reading) { async _getInfoJpod101Alternate(expression, reading) {
const fetchUrl = 'https://www.japanesepod101.com/learningcenter/reference/dictionary_post'; const fetchUrl = 'https://www.japanesepod101.com/learningcenter/reference/dictionary_post';
const data = `post=dictionary_reference&match_type=exact&search_query=${encodeURIComponent(expression)}&vulgar=true`; const data = new URLSearchParams({
post: 'dictionary_reference',
match_type: 'exact',
search_query: expression,
vulgar: 'true'
});
const response = await this._requestBuilder.fetchAnonymous(fetchUrl, { const response = await this._requestBuilder.fetchAnonymous(fetchUrl, {
method: 'POST', method: 'POST',
mode: 'cors', mode: 'cors',