diff --git a/app/src/main/java/org/koitharu/kotatsu/core/parser/site/AnibelRepository.kt b/app/src/main/java/org/koitharu/kotatsu/core/parser/site/AnibelRepository.kt index 318fcad02..35c5e6187 100644 --- a/app/src/main/java/org/koitharu/kotatsu/core/parser/site/AnibelRepository.kt +++ b/app/src/main/java/org/koitharu/kotatsu/core/parser/site/AnibelRepository.kt @@ -37,11 +37,14 @@ class AnibelRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor return items.mapNotNull { card -> val href = card.selectFirst("a").attr("href") val status = card.select("tr")[2].text() + val fullTitle = card.selectFirst("h1.anime-card-title").text() + .substringBeforeLast('[') + val titleParts = fullTitle.splitTwoParts('/') Manga( id = generateUid(href), - title = card.selectFirst("h1.anime-card-title").text(), + title = titleParts?.first?.trim() ?: fullTitle, coverUrl = card.selectFirst("img").attr("data-src").withDomain(), - altTitle = null, + altTitle = titleParts?.second?.trim(), author = null, rating = Manga.NO_RATING, url = href, @@ -49,7 +52,7 @@ class AnibelRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor tags = card.select("p.tupe.tag")?.select("a")?.mapNotNullToSet tags@{ x -> MangaTag( title = x.text(), - key = x.attr("href") ?: return@tags null, + key = x.attr("href")?.substringAfterLast("=") ?: return@tags null, source = source ) }.orEmpty(), @@ -132,11 +135,14 @@ class AnibelRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor return items.mapNotNull { card -> val href = card.select("a").attr("href") val status = card.select("tr")[2].text() + val fullTitle = card.selectFirst("h1.anime-card-title").text() + .substringBeforeLast('[') + val titleParts = fullTitle.splitTwoParts('/') Manga( id = generateUid(href), - title = card.selectFirst("h1.anime-card-title").text(), + title = titleParts?.first?.trim() ?: fullTitle, coverUrl = card.selectFirst("img").attr("src").withDomain(), - altTitle = null, + altTitle = titleParts?.second?.trim(), author = null, rating = Manga.NO_RATING, url = href, @@ -144,7 +150,7 @@ class AnibelRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor tags = card.select("p.tupe.tag")?.select("a")?.mapNotNullToSet tags@{ x -> MangaTag( title = x.text(), - key = x.attr("href") ?: return@tags null, + key = x.attr("href")?.substringAfterLast("=") ?: return@tags null, source = source ) }.orEmpty(), diff --git a/app/src/main/java/org/koitharu/kotatsu/utils/ext/StringExt.kt b/app/src/main/java/org/koitharu/kotatsu/utils/ext/StringExt.kt index 4cfa1c808..834a4158f 100644 --- a/app/src/main/java/org/koitharu/kotatsu/utils/ext/StringExt.kt +++ b/app/src/main/java/org/koitharu/kotatsu/utils/ext/StringExt.kt @@ -77,6 +77,20 @@ fun String.ellipsize(maxLength: Int) = if (this.length > maxLength) { this.take(maxLength - 1) + Typography.ellipsis } else this +fun String.splitTwoParts(delimiter: Char): Pair? { + val indices = ArrayList(4) + for ((i, c) in this.withIndex()) { + if (c == delimiter) { + indices += i + } + } + if (indices.isEmpty() || indices.size and 1 == 0) { + return null + } + val index = indices[indices.size / 2] + return substring(0, index) to substring(index + 1) +} + fun String.urlEncoded(): String = URLEncoder.encode(this, Charsets.UTF_8.name()) fun String.toUriOrNull(): Uri? = if (isEmpty()) {