Parsers fixes
This commit is contained in:
@@ -13,11 +13,11 @@ import org.koin.android.ext.koin.androidLogger
|
||||
import org.koin.core.context.startKoin
|
||||
import org.koin.dsl.module
|
||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||
import org.koitharu.kotatsu.core.local.CbzFetcher
|
||||
import org.koitharu.kotatsu.core.local.PagesCache
|
||||
import org.koitharu.kotatsu.core.local.cookies.PersistentCookieJar
|
||||
import org.koitharu.kotatsu.core.local.cookies.cache.SetCookieCache
|
||||
import org.koitharu.kotatsu.core.local.cookies.persistence.SharedPrefsCookiePersistor
|
||||
import org.koitharu.kotatsu.core.local.CbzFetcher
|
||||
import org.koitharu.kotatsu.core.local.PagesCache
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.utils.CacheUtils
|
||||
@@ -40,27 +40,25 @@ class KotatsuApp : Application() {
|
||||
startKoin {
|
||||
androidLogger()
|
||||
androidContext(applicationContext)
|
||||
modules(listOf(
|
||||
module {
|
||||
factory {
|
||||
okHttp()
|
||||
.cache(CacheUtils.createHttpCache(applicationContext))
|
||||
.build()
|
||||
}
|
||||
single {
|
||||
mangaDb().build()
|
||||
}
|
||||
single {
|
||||
MangaLoaderContext()
|
||||
}
|
||||
factory {
|
||||
AppSettings(applicationContext)
|
||||
}
|
||||
single {
|
||||
PagesCache(applicationContext)
|
||||
}
|
||||
module {
|
||||
factory {
|
||||
okHttp()
|
||||
.cache(CacheUtils.createHttpCache(applicationContext))
|
||||
.build()
|
||||
}
|
||||
))
|
||||
single {
|
||||
mangaDb().build()
|
||||
}
|
||||
single {
|
||||
MangaLoaderContext()
|
||||
}
|
||||
factory {
|
||||
AppSettings(applicationContext)
|
||||
}
|
||||
single {
|
||||
PagesCache(applicationContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ abstract class GroupleRepository : RemoteMangaRepository() {
|
||||
val doc = when {
|
||||
!query.isNullOrEmpty() -> loaderContext.httpPost(
|
||||
"https://$domain/search",
|
||||
mapOf("q" to query)
|
||||
mapOf("q" to query, "offset" to offset.toString())
|
||||
)
|
||||
tag == null -> loaderContext.httpGet("https://$domain/list?sortType=${getSortKey(sortOrder)}&offset=$offset")
|
||||
else -> loaderContext.httpGet(
|
||||
@@ -40,7 +40,7 @@ abstract class GroupleRepository : RemoteMangaRepository() {
|
||||
return root.select("div.tile").mapNotNull { node ->
|
||||
val imgDiv = node.selectFirst("div.img") ?: return@mapNotNull null
|
||||
val descDiv = node.selectFirst("div.desc") ?: return@mapNotNull null
|
||||
if (descDiv.getElementsByAttributeValue("data-type", "author").isNotEmpty()) {
|
||||
if (descDiv.selectFirst("i.fa-user") != null) {
|
||||
return@mapNotNull null //skip author
|
||||
}
|
||||
val href = imgDiv.selectFirst("a").attr("href")?.withDomain(domain)
|
||||
@@ -87,7 +87,7 @@ abstract class GroupleRepository : RemoteMangaRepository() {
|
||||
val doc = loaderContext.httpGet(manga.url).parseHtml()
|
||||
val root = doc.body().getElementById("mangaBox") ?: throw ParseException("Cannot find root")
|
||||
return manga.copy(
|
||||
description = root.selectFirst("div.manga-description").firstChild()?.html(),
|
||||
description = root.selectFirst("div.manga-description")?.html(),
|
||||
largeCoverUrl = root.selectFirst("div.subject-cower")?.selectFirst("img")?.attr(
|
||||
"data-full"
|
||||
),
|
||||
|
||||
@@ -1,9 +1,39 @@
|
||||
package org.koitharu.kotatsu.core.parser.site
|
||||
|
||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.core.model.MangaChapter
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||
import org.koitharu.kotatsu.utils.ext.parseHtml
|
||||
import org.koitharu.kotatsu.utils.ext.withDomain
|
||||
|
||||
class HenChanRepository : ChanRepository() {
|
||||
|
||||
override val defaultDomain = "h-chan.me"
|
||||
override val source = MangaSource.HENCHAN
|
||||
|
||||
override suspend fun getDetails(manga: Manga): Manga {
|
||||
val domain = conf.getDomain(defaultDomain)
|
||||
val doc = loaderContext.httpGet(manga.url).parseHtml()
|
||||
val root =
|
||||
doc.body().getElementById("dle-content") ?: throw ParseException("Cannot find root")
|
||||
return manga.copy(
|
||||
description = root.getElementById("description")?.html()?.substringBeforeLast("<div"),
|
||||
largeCoverUrl = root.getElementById("cover")?.attr("src")?.withDomain(domain),
|
||||
chapters = root.getElementById("right").select("table.table_cha").flatMap { table ->
|
||||
table.select("div.manga2")
|
||||
}.mapNotNull { it.selectFirst("a") }.reversed().mapIndexedNotNull { i, a ->
|
||||
val href = a.attr("href")
|
||||
?.withDomain(domain) ?: return@mapIndexedNotNull null
|
||||
MangaChapter(
|
||||
id = href.longHashCode(),
|
||||
name = a.text().trim(),
|
||||
number = i + 1,
|
||||
url = href,
|
||||
source = source
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ class SourceConfig(context: Context, source: MangaSource) {
|
||||
|
||||
private val keyDomain = context.getString(R.string.key_parser_domain)
|
||||
|
||||
fun getDomain(defaultValue: String) = prefs.getString(keyDomain, defaultValue) ?: defaultValue
|
||||
fun getDomain(defaultValue: String) = prefs.getString(keyDomain, defaultValue)
|
||||
?.takeUnless(String::isBlank)
|
||||
?: defaultValue
|
||||
|
||||
}
|
||||
@@ -16,17 +16,14 @@ abstract class RepositoryTestEnvironment {
|
||||
@BeforeClass
|
||||
fun initialize(source: MangaSource) {
|
||||
startKoin {
|
||||
modules(listOf(
|
||||
module {
|
||||
factory {
|
||||
OkHttpClient()
|
||||
}
|
||||
}, module {
|
||||
single {
|
||||
MangaLoaderContext()
|
||||
}
|
||||
module {
|
||||
factory {
|
||||
OkHttpClient()
|
||||
}
|
||||
))
|
||||
single {
|
||||
MangaLoaderContext()
|
||||
}
|
||||
}
|
||||
}
|
||||
val constructor = source.cls.getConstructor(MangaLoaderContext::class.java)
|
||||
repository = constructor.newInstance(MangaLoaderContext())
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.junit.runner.RunWith
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.MangaParserTest
|
||||
import org.koitharu.kotatsu.parsers.RepositoryTestEnvironment
|
||||
import org.koitharu.kotatsu.utils.TestUtil
|
||||
import org.koitharu.kotatsu.utils.AssertX
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
@@ -21,8 +21,8 @@ class MintMangaTest : MangaParserTest {
|
||||
val item = list[40]
|
||||
Assert.assertTrue(item.title.isNotEmpty())
|
||||
Assert.assertTrue(item.rating in 0f..1f)
|
||||
TestUtil.assertValidUrl(item.url)
|
||||
TestUtil.assertValidUrl(item.coverUrl)
|
||||
AssertX.assertValidUrl(item.url)
|
||||
AssertX.assertValidUrl(item.coverUrl)
|
||||
Assert.assertEquals(item.source, MangaSource.MINTMANGA)
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ class MintMangaTest : MangaParserTest {
|
||||
override fun testMangaDetails() {
|
||||
val manga = getMangaItem()
|
||||
Assert.assertNotNull(manga.largeCoverUrl)
|
||||
TestUtil.assertValidUrl(manga.largeCoverUrl!!)
|
||||
AssertX.assertValidUrl(manga.largeCoverUrl!!)
|
||||
Assert.assertNotNull(manga.chapters)
|
||||
val chapter = manga.chapters!!.last()
|
||||
Assert.assertEquals(chapter.source, MangaSource.MINTMANGA)
|
||||
TestUtil.assertValidUrl(chapter.url)
|
||||
AssertX.assertValidUrl(chapter.url)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,8 +43,8 @@ class MintMangaTest : MangaParserTest {
|
||||
val pages = runBlocking { repository.getPages(chapter) }
|
||||
Assert.assertFalse(pages.isEmpty())
|
||||
Assert.assertEquals(pages.first().source, MangaSource.MINTMANGA)
|
||||
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
||||
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,7 +54,7 @@ class MintMangaTest : MangaParserTest {
|
||||
val tag = tags.first()
|
||||
Assert.assertFalse(tag.title.isBlank())
|
||||
Assert.assertEquals(tag.source, MangaSource.MINTMANGA)
|
||||
TestUtil.assertValidUrl("https://mintmanga.live/list/genre/${tag.key}")
|
||||
AssertX.assertValidUrl("https://mintmanga.live/list/genre/${tag.key}")
|
||||
}
|
||||
|
||||
companion object : RepositoryTestEnvironment() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.junit.runner.RunWith
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.MangaParserTest
|
||||
import org.koitharu.kotatsu.parsers.RepositoryTestEnvironment
|
||||
import org.koitharu.kotatsu.utils.TestUtil
|
||||
import org.koitharu.kotatsu.utils.AssertX
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
@@ -21,8 +21,8 @@ class ReadmangaRuTest : MangaParserTest {
|
||||
val item = list[40]
|
||||
Assert.assertTrue(item.title.isNotEmpty())
|
||||
Assert.assertTrue(item.rating in 0f..1f)
|
||||
TestUtil.assertValidUrl(item.url)
|
||||
TestUtil.assertValidUrl(item.coverUrl)
|
||||
AssertX.assertValidUrl(item.url)
|
||||
AssertX.assertValidUrl(item.coverUrl)
|
||||
Assert.assertEquals(item.source, MangaSource.READMANGA_RU)
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ class ReadmangaRuTest : MangaParserTest {
|
||||
override fun testMangaDetails() {
|
||||
val manga = getMangaItem()
|
||||
Assert.assertNotNull(manga.largeCoverUrl)
|
||||
TestUtil.assertValidUrl(manga.largeCoverUrl!!)
|
||||
AssertX.assertValidUrl(manga.largeCoverUrl!!)
|
||||
Assert.assertNotNull(manga.chapters)
|
||||
val chapter = manga.chapters!!.last()
|
||||
Assert.assertEquals(chapter.source, MangaSource.READMANGA_RU)
|
||||
TestUtil.assertValidUrl(chapter.url)
|
||||
AssertX.assertValidUrl(chapter.url)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,8 +43,8 @@ class ReadmangaRuTest : MangaParserTest {
|
||||
val pages = runBlocking { repository.getPages(chapter) }
|
||||
Assert.assertFalse(pages.isEmpty())
|
||||
Assert.assertEquals(pages.first().source, MangaSource.READMANGA_RU)
|
||||
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
||||
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,7 +54,7 @@ class ReadmangaRuTest : MangaParserTest {
|
||||
val tag = tags.first()
|
||||
Assert.assertFalse(tag.title.isBlank())
|
||||
Assert.assertEquals(tag.source, MangaSource.READMANGA_RU)
|
||||
TestUtil.assertValidUrl("https://readmanga.me/list/genre/${tag.key}")
|
||||
AssertX.assertValidUrl("https://readmanga.me/list/genre/${tag.key}")
|
||||
}
|
||||
|
||||
companion object : RepositoryTestEnvironment() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.junit.runner.RunWith
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.MangaParserTest
|
||||
import org.koitharu.kotatsu.parsers.RepositoryTestEnvironment
|
||||
import org.koitharu.kotatsu.utils.TestUtil
|
||||
import org.koitharu.kotatsu.utils.AssertX
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
@@ -21,8 +21,8 @@ class SelfMangaTest : MangaParserTest {
|
||||
val item = list[40]
|
||||
Assert.assertTrue(item.title.isNotEmpty())
|
||||
Assert.assertTrue(item.rating in 0f..1f)
|
||||
TestUtil.assertValidUrl(item.url)
|
||||
TestUtil.assertValidUrl(item.coverUrl)
|
||||
AssertX.assertValidUrl(item.url)
|
||||
AssertX.assertValidUrl(item.coverUrl)
|
||||
Assert.assertEquals(item.source, MangaSource.SELFMANGA)
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ class SelfMangaTest : MangaParserTest {
|
||||
override fun testMangaDetails() {
|
||||
val manga = getMangaItem()
|
||||
Assert.assertNotNull(manga.largeCoverUrl)
|
||||
TestUtil.assertValidUrl(manga.largeCoverUrl!!)
|
||||
AssertX.assertValidUrl(manga.largeCoverUrl!!)
|
||||
Assert.assertNotNull(manga.chapters)
|
||||
val chapter = manga.chapters!!.last()
|
||||
Assert.assertEquals(chapter.source, MangaSource.SELFMANGA)
|
||||
TestUtil.assertValidUrl(chapter.url)
|
||||
AssertX.assertValidUrl(chapter.url)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,8 +43,8 @@ class SelfMangaTest : MangaParserTest {
|
||||
val pages = runBlocking { repository.getPages(chapter) }
|
||||
Assert.assertFalse(pages.isEmpty())
|
||||
Assert.assertEquals(pages.first().source, MangaSource.SELFMANGA)
|
||||
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
||||
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
||||
AssertX.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,7 +54,7 @@ class SelfMangaTest : MangaParserTest {
|
||||
val tag = tags.first()
|
||||
Assert.assertFalse(tag.title.isBlank())
|
||||
Assert.assertEquals(tag.source, MangaSource.SELFMANGA)
|
||||
TestUtil.assertValidUrl("https://selfmanga.ru/list/genre/${tag.key}")
|
||||
AssertX.assertValidUrl("https://selfmanga.ru/list/genre/${tag.key}")
|
||||
}
|
||||
|
||||
companion object : RepositoryTestEnvironment() {
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.junit.Assert
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
|
||||
object TestUtil {
|
||||
object AssertX {
|
||||
|
||||
private val VALID_RESPONSE_CODES = arrayOf(
|
||||
HttpURLConnection.HTTP_OK,
|
||||
Reference in New Issue
Block a user