[Komga] metadata update (#4194)

* clarify changelog

* remove the 1000 chapters limit

* remove old dto (was required before Komga 0.48.0)
align to new metadata model (Komga 0.58.0)
add description and genre for Series
This commit is contained in:
Gauthier 2020-08-24 19:14:32 +08:00 committed by GitHub
parent 03aad1addc
commit fcff37890d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 103 deletions

View File

@ -1,6 +1,14 @@
## 1.2.15
Minimum Komga version required: `0.56.0`
### Features
* remove the 1000 chapters limit
## 1.2.14
Requires Komga `0.41.0`
Minimum Komga version required: `0.41.0`
### Features
@ -8,7 +16,7 @@ Requires Komga `0.41.0`
## 1.2.13
Requires Komga `0.41.0`
Minimum Komga version required: `0.41.0`
### Features
@ -16,7 +24,7 @@ Requires Komga `0.41.0`
## 1.2.12
Requires Komga `0.41.0`
Minimum Komga version required: `0.41.0`
### Features
@ -24,7 +32,7 @@ Requires Komga `0.41.0`
## 1.2.11
Requires Komga `0.35.2`
Minimum Komga version required: `0.35.2`
### Features
@ -32,7 +40,7 @@ Requires Komga `0.35.2`
## 1.2.10
Requires Komga `0.35.2`
Minimum Komga version required: `0.35.2`
### Features
@ -41,7 +49,7 @@ Requires Komga `0.35.2`
## 1.2.9
Requires Komga `0.22.0`
Minimum Komga version required: `0.22.0`
### Features
@ -49,7 +57,7 @@ Requires Komga `0.22.0`
## 1.2.8
Requires Komga `0.22.0`
Minimum Komga version required: `0.22.0`
### Features

View File

@ -5,7 +5,7 @@ ext {
extName = 'Komga'
pkgNameSuffix = 'all.komga'
extClass = '.KomgaFactory'
extVersionCode = 14
extVersionCode = 15
libVersion = '1.2'
}

View File

@ -10,15 +10,11 @@ import com.github.salomonbrys.kotson.fromJson
import com.google.gson.Gson
import eu.kanade.tachiyomi.extension.BuildConfig
import eu.kanade.tachiyomi.extension.all.komga.dto.BookDto
import eu.kanade.tachiyomi.extension.all.komga.dto.BookDtoOld
import eu.kanade.tachiyomi.extension.all.komga.dto.CollectionDto
import eu.kanade.tachiyomi.extension.all.komga.dto.CollectionDtoOld
import eu.kanade.tachiyomi.extension.all.komga.dto.LibraryDto
import eu.kanade.tachiyomi.extension.all.komga.dto.LibraryDtoOld
import eu.kanade.tachiyomi.extension.all.komga.dto.PageDto
import eu.kanade.tachiyomi.extension.all.komga.dto.PageWrapperDto
import eu.kanade.tachiyomi.extension.all.komga.dto.SeriesDto
import eu.kanade.tachiyomi.extension.all.komga.dto.SeriesDtoOld
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.Filter
@ -124,25 +120,15 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
GET(baseUrl + manga.url, headers)
override fun mangaDetailsParse(response: Response): SManga {
val series = try {
gson.fromJson<SeriesDto>(response.body()?.charStream()!!)
} catch (e: Exception) {
gson.fromJson<SeriesDtoOld>(response.body()?.charStream()!!)
.toSeriesDto()
}
val series = gson.fromJson<SeriesDto>(response.body()?.charStream()!!)
return series.toSManga()
}
override fun chapterListRequest(manga: SManga): Request =
GET("$baseUrl${manga.url}/books?size=1000&media_status=READY", headers)
GET("$baseUrl${manga.url}/books?unpaged=true&media_status=READY", headers)
override fun chapterListParse(response: Response): List<SChapter> {
val page = try {
gson.fromJson<PageWrapperDto<BookDto>>(response.body()?.charStream()!!).content
} catch (e: Exception) {
gson.fromJson<PageWrapperDto<BookDtoOld>>(response.body()?.charStream()!!).content
.map { it.toBookDto() }
}
val page = gson.fromJson<PageWrapperDto<BookDto>>(response.body()?.charStream()!!).content
return page.map { book ->
SChapter.create().apply {
@ -175,16 +161,9 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
private fun processSeriesPage(response: Response): MangasPage {
var lastPage: Boolean
val page = try {
with(gson.fromJson<PageWrapperDto<SeriesDto>>(response.body()?.charStream()!!)) {
lastPage = last
content
}
} catch (e: Exception) {
with(gson.fromJson<PageWrapperDto<SeriesDtoOld>>(response.body()?.charStream()!!)) {
lastPage = last
content.map { it.toSeriesDto() }
}
val page = with(gson.fromJson<PageWrapperDto<SeriesDto>>(response.body()?.charStream()!!)) {
lastPage = last
content
}
val mangas = page.map {
it.toSManga()
@ -202,6 +181,10 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
"ENDED" -> SManga.COMPLETED
else -> SManga.UNKNOWN
}
// TODO: remove safe calls in next iteration
genre = (metadata.genres?.plus(metadata.tags ?: emptySet())
?: emptySet()).joinToString(", ")
description = metadata.summary
}
private fun parseDate(date: String?): Long =
@ -346,12 +329,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
libraries = try {
gson.fromJson(response.body()?.charStream()!!)
} catch (e: Exception) {
try {
gson.fromJson<List<LibraryDtoOld>>(response.body()?.charStream()!!)
.map { it.toLibraryDto() }
} catch (e: Exception) {
emptyList()
}
emptyList()
}
}, {})
@ -364,12 +342,7 @@ open class Komga(suffix: String = "") : ConfigurableSource, HttpSource() {
collections = try {
gson.fromJson<PageWrapperDto<CollectionDto>>(response.body()?.charStream()!!).content
} catch (e: Exception) {
try {
gson.fromJson<PageWrapperDto<CollectionDtoOld>>(response.body()?.charStream()!!).content
.map { it.toCollectionDto() }
} catch (e: Exception) {
emptyList()
}
emptyList()
}
}, {})
}

View File

@ -21,7 +21,21 @@ data class SeriesMetadataDto(
val created: String?,
val lastModified: String?,
val title: String,
val titleSort: String
val titleSort: String,
val summary: String,
val summaryLock: Boolean,
val readingDirection: String,
val readingDirectionLock: Boolean,
val publisher: String,
val publisherLock: Boolean,
val ageRating: Int?,
val ageRatingLock: Boolean,
val language: String,
val languageLock: Boolean,
val genres: Set<String>?, //TODO: remove optional in next iteration
val genresLock: Boolean,
val tags: Set<String>?, //TODO: remove optional in next iteration
val tagsLock: Boolean
)
data class BookDto(
@ -59,12 +73,6 @@ data class BookMetadataDto(
val numberLock: Boolean,
val numberSort: Float,
val numberSortLock: Boolean,
val readingDirection: String,
val readingDirectionLock: Boolean,
val publisher: String,
val publisherLock: Boolean,
val ageRating: Int?,
val ageRatingLock: Boolean,
val releaseDate: String?,
val releaseDateLock: Boolean,
val authors: List<AuthorDto>,

View File

@ -1,49 +0,0 @@
package eu.kanade.tachiyomi.extension.all.komga.dto
data class LibraryDtoOld(
val id: Long,
val name: String
) {
fun toLibraryDto() = LibraryDto(id.toString(), name)
}
data class SeriesDtoOld(
val id: Long,
val libraryId: Long,
val name: String,
val created: String?,
val lastModified: String?,
val fileLastModified: String,
val booksCount: Int,
val metadata: SeriesMetadataDto
) {
fun toSeriesDto() = SeriesDto(id.toString(), libraryId.toString(), name, created, lastModified, fileLastModified, booksCount, metadata)
}
data class BookDtoOld(
val id: Long,
val seriesId: Long,
val name: String,
val number: Float,
val created: String?,
val lastModified: String?,
val fileLastModified: String,
val sizeBytes: Long,
val size: String,
val media: MediaDto,
val metadata: BookMetadataDto
) {
fun toBookDto() = BookDto(id.toString(), seriesId.toString(), name, number, created, lastModified, fileLastModified, sizeBytes, size, media, metadata)
}
data class CollectionDtoOld(
val id: Long,
val name: String,
val ordered: Boolean,
val seriesIds: List<Long>,
val createdDate: String,
val lastModifiedDate: String,
val filtered: Boolean
) {
fun toCollectionDto() = CollectionDto(id.toString(), name, ordered, seriesIds, createdDate, lastModifiedDate, filtered)
}