Skip to content

Commit

Permalink
fix(pt/otakuanimes): Fixed images on search for pt/otakuanimes (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
WebDitto committed Aug 17, 2024
1 parent 7e7aa7d commit f72391c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/pt/otakuanimes/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'OtakuAnimes'
extClass = '.OtakuAnimes'
extVersionCode = 1
extVersionCode = 2
isNsfw = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class OtakuAnimes : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override fun popularAnimeFromElement(element: Element) = SAnime.create().apply {
setUrlWithoutDomain(element.attr("href"))
title = element.selectFirst("div.aniNome")!!.text().trim()
thumbnail_url = element.selectFirst("img")?.attr("data-lazy-src")
thumbnail_url = element.selectFirst("img")?.getImageUrl()
}

override fun popularAnimeNextPageSelector() = null
Expand Down Expand Up @@ -111,7 +111,7 @@ class OtakuAnimes : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
return SAnime.create().apply {
setUrlWithoutDomain(doc.location())
title = doc.selectFirst("div.animeFirstContainer h1")!!.text()
thumbnail_url = doc.selectFirst("div.animeCapa img")?.attr("data-lazy-src")
thumbnail_url = doc.selectFirst("div.animeCapa img")?.getImageUrl()
description = doc.selectFirst("div.animeSecondContainer > p")?.text()
genre = doc.select("ul.animeGen li").eachText()?.joinToString(", ")
}
Expand Down Expand Up @@ -222,6 +222,19 @@ class OtakuAnimes : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
return document
}

/**
* Tries to get the image url via various possible attributes.
* Taken from Tachiyomi's Madara multisrc.
*/
protected open fun Element.getImageUrl(): String? {
return when {
hasAttr("data-src") -> attr("abs:data-src")
hasAttr("data-lazy-src") -> attr("abs:data-lazy-src")
hasAttr("srcset") -> attr("abs:srcset").substringBefore(" ")
else -> attr("abs:src")
}.substringBefore("?resize")
}

companion object {
const val PREFIX_SEARCH = "path:"
private val REGEX_QUALITY by lazy { Regex("""(\d+)p""") }
Expand Down

0 comments on commit f72391c

Please sign in to comment.