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' extName = 'Loading Artist'
pkgNameSuffix = 'en.loadingartist' pkgNameSuffix = 'en.loadingartist'
extClass = '.LoadingArtist' extClass = '.LoadingArtist'
extVersionCode = 1 extVersionCode = 2
libVersion = '1.2' libVersion = '1.2'
} }

View File

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