Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Konyaco committed Feb 22, 2022
2 parents 658881f + 551d238 commit af82567
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,18 @@ private class WordFormParser {

private class PronunciationParser {
fun parse(dictionaryElement: Element): Pronunciation {
val pronElement = dictionaryElement.getElementsByClass("pron type-").firstOrNull()
val pronElement = dictionaryElement.getElementsByClass("mini_h2").firstOrNull()
?: error("Cannot find word pronunciation")
val pronStr = pronElement.text()
val pronItem = dictionaryElement.getElementsByClass("pron type-").firstOrNull()
val pronStr = pronItem?.text()
val soundElement = pronElement.getElementsByAttribute("data-src-mp3").firstOrNull()
?: error("Cannot find sound element")
val sound = soundElement.attributes()["data-src-mp3"] ?: error("Cannot find sound url")
return Pronunciation(pronStr, sound)
val sound = soundElement?.let {
it.attributes()["data-src-mp3"] ?: error("Cannot find sound url")
}
if (pronStr == null && soundElement == null) {
error("Cannot find word pronunciation")
}
return Pronunciation(pronStr ?: "", sound)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,18 @@ private class WordFormParser {

private class PronunciationParser {
fun parse(dictionaryElement: Element): Pronunciation {
val pronElement = dictionaryElement.getElementsByClass("pron type-").firstOrNull()
val pronElement = dictionaryElement.getElementsByClass("mini_h2").firstOrNull()
?: error("Cannot find word pronunciation")
val pronStr = pronElement.text()
val pronItem = dictionaryElement.getElementsByClass("pron type-").firstOrNull()
val pronStr = pronItem?.text()
val soundElement = pronElement.getElementsByAttribute("data-src-mp3").firstOrNull()
?: error("Cannot find sound element")
val sound = soundElement.attributes()["data-src-mp3"] ?: error("Cannot find sound url")
return Pronunciation(pronStr, sound)
val sound = soundElement?.let {
it.attributes()["data-src-mp3"] ?: error("Cannot find sound url")
}
if (pronStr == null && soundElement == null) {
error("Cannot find word pronunciation")
}
return Pronunciation(pronStr ?: "", sound)
}
}

Expand Down

0 comments on commit af82567

Please sign in to comment.