Netcomics: update for extensions-lib 1.4 (#15363)

This commit is contained in:
ObserverOfTime 2023-02-15 18:04:54 +02:00 committed by GitHub
parent ebfef9c387
commit 0922663031
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 35 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'NETCOMICS' extName = 'NETCOMICS'
pkgNameSuffix = 'all.netcomics' pkgNameSuffix = 'all.netcomics'
extClass = '.NetcomicsFactory' extClass = '.NetcomicsFactory'
extVersionCode = 2 extVersionCode = 3
isNsfw = true isNsfw = true
} }

View File

@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.extension.all.netcomics package eu.kanade.tachiyomi.extension.all.netcomics
import android.app.Application import android.app.Application
import android.net.Uri
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
@ -19,6 +18,8 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.decodeFromJsonElement
import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive import kotlinx.serialization.json.jsonPrimitive
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Response import okhttp3.Response
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -56,7 +57,7 @@ class Netcomics(
System.currentTimeMillis().toString() System.currentTimeMillis().toString()
} }
private val apiUri by lazy { Uri.parse(API_URL) } private val apiUrl by lazy { API_URL.toHttpUrl() }
private val apiHeaders by lazy { private val apiHeaders by lazy {
headers.newBuilder() headers.newBuilder()
@ -80,10 +81,6 @@ class Netcomics(
} }
} }
// Request the real URL for the webview
override fun mangaDetailsRequest(manga: SManga) =
GET("$baseUrl/$site/comic/${manga.slug}", headers)
override fun searchMangaParse(response: Response) = override fun searchMangaParse(response: Response) =
response.data<List<Title>>().ifEmpty { response.data<List<Title>>().ifEmpty {
error("No more pages") error("No more pages")
@ -119,50 +116,56 @@ class Netcomics(
} }
override fun fetchLatestUpdates(page: Int) = override fun fetchLatestUpdates(page: Int) =
apiUri.fetch("title", ::searchMangaParse) { apiUrl.fetch("title", ::searchMangaParse) {
appendEncodedPath("new") addEncodedPathSegment("new")
appendQueryParameter("no", page.toString()) addEncodedQueryParameter("no", page.toString())
appendQueryParameter("size", "20") addEncodedQueryParameter("size", "20")
appendQueryParameter("day", day) addEncodedQueryParameter("day", day)
} }
override fun fetchPopularManga(page: Int) = override fun fetchPopularManga(page: Int) =
apiUri.fetch("title", ::searchMangaParse) { apiUrl.fetch("title", ::searchMangaParse) {
appendEncodedPath("free") addEncodedPathSegment("free")
appendQueryParameter("no", page.toString()) addEncodedQueryParameter("no", page.toString())
appendQueryParameter("size", "20") addEncodedQueryParameter("size", "20")
} }
override fun fetchSearchManga(page: Int, query: String, filters: FilterList) = override fun fetchSearchManga(page: Int, query: String, filters: FilterList) =
apiUri.fetch("title", ::searchMangaParse) { apiUrl.fetch("title", ::searchMangaParse) {
if (query.isNotBlank()) { if (query.isNotBlank()) {
appendEncodedPath("search/text") addEncodedPathSegments("search/text")
appendQueryParameter("text", query) addQueryParameter("text", query)
} else { } else {
appendEncodedPath("genre") addEncodedPathSegment("genre")
appendQueryParameter("genre", filters.genre) addQueryParameter("genre", filters.genre)
} }
appendQueryParameter("no", page.toString()) addEncodedQueryParameter("no", page.toString())
appendQueryParameter("size", "20") addEncodedQueryParameter("size", "20")
} }
override fun fetchMangaDetails(manga: SManga) = override fun fetchMangaDetails(manga: SManga) =
rx.Observable.just(manga.apply { initialized = true })!! rx.Observable.just(manga.apply { initialized = true })!!
override fun fetchChapterList(manga: SManga) = override fun fetchChapterList(manga: SManga) =
apiUri.fetch("chapter", ::chapterListParse) { apiUrl.fetch("chapter", ::chapterListParse) {
appendEncodedPath("list") addEncodedPathSegment("list")
appendEncodedPath(manga.id) addEncodedPathSegment(manga.id)
appendEncodedPath("rent") addEncodedPathSegment("rent")
} }
override fun fetchPageList(chapter: SChapter) = override fun fetchPageList(chapter: SChapter) =
apiUri.fetch("chapter", ::pageListParse) { apiUrl.fetch("chapter", ::pageListParse) {
appendEncodedPath("viewer") addEncodedPathSegment("viewer")
appendEncodedPath(quality) addEncodedPathSegment(quality)
appendEncodedPath(chapter.url) addEncodedPathSegments(chapter.url)
} }
override fun getMangaUrl(manga: SManga) =
"$baseUrl/$site/comic/${manga.slug}"
override fun getChapterUrl(chapter: SChapter) =
"$baseUrl/viewer/${chapter.url}"
override fun getFilterList() = override fun getFilterList() =
FilterList(GenreFilter.NOTE, GenreFilter()) FilterList(GenreFilter.NOTE, GenreFilter())
@ -213,6 +216,9 @@ class Netcomics(
override fun searchMangaRequest(page: Int, query: String, filters: FilterList) = override fun searchMangaRequest(page: Int, query: String, filters: FilterList) =
throw UnsupportedOperationException("Not used") throw UnsupportedOperationException("Not used")
override fun mangaDetailsRequest(manga: SManga) =
throw UnsupportedOperationException("Not used")
override fun chapterListRequest(manga: SManga) = override fun chapterListRequest(manga: SManga) =
throw UnsupportedOperationException("Not used") throw UnsupportedOperationException("Not used")
@ -249,11 +255,11 @@ class Netcomics(
}, },
) )
private inline fun <R> Uri.fetch( private inline fun <R> HttpUrl.fetch(
path: String, path: String,
noinline parse: (Response) -> R, noinline parse: (Response) -> R,
block: Uri.Builder.() -> Uri.Builder, block: HttpUrl.Builder.() -> HttpUrl.Builder,
) = buildUpon().appendEncodedPath(path).let(block).toString().run { ) = newBuilder().addEncodedPathSegment(path).let(block).run {
client.newCall(GET(this, apiHeaders)).asObservable().map(parse)!! client.newCall(GET(build(), apiHeaders)).asObservable().map(parse)!!
} }
} }

View File

@ -1,3 +1,5 @@
@file:Suppress("PrivatePropertyName")
package eu.kanade.tachiyomi.extension.all.netcomics package eu.kanade.tachiyomi.extension.all.netcomics
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable