Update audio downloader (#1499)
* Update _getInfoJpod101's empty reading check * Use URLSearchParams instead of a string
This commit is contained in:
parent
16217728af
commit
49bf562690
@ -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',
|
||||||
|
Loading…
Reference in New Issue
Block a user