Rework source (#8800)

This commit is contained in:
Arraiment 2021-08-24 18:44:35 +08:00 committed by GitHub
parent ddb80df1fd
commit 08246bf4e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 41 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Loading Artist'
pkgNameSuffix = 'en.loadingartist'
extClass = '.LoadingArtist'
extVersionCode = 1
extVersionCode = 2
libVersion = '1.2'
}

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.extension.en.loadingartist
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.Page
@ -16,6 +17,9 @@ import okhttp3.Request
import okhttp3.Response
import rx.Observable
import uy.kohesive.injekt.injectLazy
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Locale
class LoadingArtist : HttpSource() {
override val name = "Loading Artist"
@ -28,53 +32,41 @@ class LoadingArtist : HttpSource() {
private val json: Json by injectLazy()
private val comicList: MutableList<SManga> = mutableListOf()
@Serializable
private data class Comic(
val url: String,
val img: String = "",
val title: String,
val date: String = "",
val section: String,
val keywords: List<String> = listOf()
val section: String
)
// Popular Section (list of comic archives by year)
// Retrieves the entire comic archive
override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/search.json")
override fun popularMangaParse(response: Response): MangasPage {
comicList.clear()
json.parseToJsonElement(response.body!!.string()).jsonObject.forEach {
val item = json.decodeFromJsonElement<Comic>(it.value)
if (listOf("comic", "art", "game").any { type -> item.section == type }) {
comicList.add(
override fun fetchPopularManga(page: Int): Observable<MangasPage> {
return Observable.just(
MangasPage(
listOf(
SManga.create().apply {
setUrlWithoutDomain(item.url)
title = item.title
thumbnail_url = if (item.img.isEmpty()) null else "$baseUrl${item.img}"
title = "Loading Artist"
setUrlWithoutDomain("/archives")
thumbnail_url = "$baseUrl/img/bg/logo-text_dark.png"
artist = "Loading Artist"
author = artist
description = if (item.date.isEmpty()) null else "Date Published: ${item.date}"
genre = item.keywords.joinToString(", ")
status = SManga.COMPLETED
status = SManga.ONGOING
}
)
}
}
return MangasPage(comicList, false)
}
// Search
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
return Observable.just(
MangasPage(comicList.filter { it.title.contains(query, true) }, false)
),
false
)
)
}
override fun popularMangaRequest(page: Int): Request = throw Exception("Not used")
override fun popularMangaParse(response: Response): MangasPage = throw Exception("Not used")
// Search
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> =
throw Exception("Search not available for this source")
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = throw Exception("Not used")
override fun searchMangaParse(response: Response): MangasPage = throw Exception("Not used")
@ -89,17 +81,30 @@ class LoadingArtist : HttpSource() {
// Chapters
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
return Observable.just(
listOf(
SChapter.create().apply {
setUrlWithoutDomain(manga.url)
name = manga.title
}
)
)
return client.newCall(GET("$baseUrl/search.json", headers))
.asObservableSuccess()
.map { response ->
chapterListParse(response)
}
}
override fun chapterListParse(response: Response): List<SChapter> = throw Exception("Not used")
override fun chapterListParse(response: Response): List<SChapter> {
val comics = json.parseToJsonElement(response.body!!.string()).jsonObject.map {
json.decodeFromJsonElement<Comic>(it.value)
}
val validTypes = listOf("comic", "game", "art")
return comics.filter { validTypes.any { type -> it.section == type } }.map {
SChapter.create().apply {
setUrlWithoutDomain(it.url)
name = it.title
date_upload = try {
SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse(it.date)?.time ?: 0
} catch (_: ParseException) {
0
}
}
}
}
// Pages