This commit is contained in:
Jobobby04 2020-11-06 14:24:28 -05:00
parent 319c41905e
commit acefd33e2e
3 changed files with 54 additions and 8 deletions

View File

@ -71,7 +71,7 @@ class ApiMangaParser(private val langs: List<String>) {
fun parseIntoMetadata(metadata: MangaDexSearchMetadata, input: Response, forceLatestCover: Boolean) { fun parseIntoMetadata(metadata: MangaDexSearchMetadata, input: Response, forceLatestCover: Boolean) {
with(metadata) { with(metadata) {
try { try {
val networkApiManga = MdUtil.jsonParser.decodeFromString(ApiMangaSerializer.serializer(), input.body!!.string()) val networkApiManga = MdUtil.jsonParser.decodeFromString<ApiMangaSerializer>(input.body!!.string())
val networkManga = networkApiManga.manga val networkManga = networkApiManga.manga
mdId = MdUtil.getMangaId(input.request.url.toString()) mdId = MdUtil.getMangaId(input.request.url.toString())
mdUrl = input.request.url.toString() mdUrl = input.request.url.toString()
@ -207,7 +207,7 @@ class ApiMangaParser(private val langs: List<String>) {
fun chapterListParse(jsonData: String): List<SChapter> { fun chapterListParse(jsonData: String): List<SChapter> {
val now = System.currentTimeMillis() val now = System.currentTimeMillis()
val networkApiManga = MdUtil.jsonParser.decodeFromString(ApiMangaSerializer.serializer(), jsonData) val networkApiManga = MdUtil.jsonParser.decodeFromString<ApiMangaSerializer>(jsonData)
val networkManga = networkApiManga.manga val networkManga = networkApiManga.manga
val networkChapters = networkApiManga.chapter val networkChapters = networkApiManga.chapter
if (networkChapters.isNullOrEmpty()) { if (networkChapters.isNullOrEmpty()) {

View File

@ -19,6 +19,7 @@ import exh.metadata.metadata.MangaDexSearchMetadata
import exh.util.floor import exh.util.floor
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.serialization.decodeFromString
import okhttp3.CacheControl import okhttp3.CacheControl
import okhttp3.FormBody import okhttp3.FormBody
import okhttp3.Headers import okhttp3.Headers
@ -47,12 +48,11 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
private fun followsParseMangaPage(response: Response, forceHd: Boolean = false): MetadataMangasPage { private fun followsParseMangaPage(response: Response, forceHd: Boolean = false): MetadataMangasPage {
val followsPageResult = try { val followsPageResult = try {
MdUtil.jsonParser.decodeFromString( MdUtil.jsonParser.decodeFromString(
FollowsPageResult.serializer(),
response.body?.string().orEmpty() response.body?.string().orEmpty()
) )
} catch (e: Exception) { } catch (e: Exception) {
XLog.e("error parsing follows", e) XLog.e("error parsing follows", e)
FollowsPageResult(emptyList()) FollowsPageResult()
} }
if (followsPageResult.result.isEmpty()) { if (followsPageResult.result.isEmpty()) {
@ -78,12 +78,11 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
private fun followStatusParse(response: Response): Track { private fun followStatusParse(response: Response): Track {
val followsPageResult = try { val followsPageResult = try {
MdUtil.jsonParser.decodeFromString( MdUtil.jsonParser.decodeFromString(
FollowsPageResult.serializer(),
response.body?.string().orEmpty() response.body?.string().orEmpty()
) )
} catch (e: Exception) { } catch (e: Exception) {
XLog.e("error parsing follows", e) XLog.e("error parsing follows", e)
FollowsPageResult(emptyList()) FollowsPageResult()
} }
val track = Track.create(TrackManager.MDLIST) val track = Track.create(TrackManager.MDLIST)
if (followsPageResult.result.isEmpty()) { if (followsPageResult.result.isEmpty()) {
@ -173,8 +172,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
"${MdUtil.baseUrl}/ajax/actions.ajax.php?function=manga_rating&id=$mangaID&rating=${track.score.toInt()}", "${MdUtil.baseUrl}/ajax/actions.ajax.php?function=manga_rating&id=$mangaID&rating=${track.score.toInt()}",
headers headers
) )
) ).await()
.await()
withContext(Dispatchers.IO) { response.body?.string().isNullOrEmpty() } withContext(Dispatchers.IO) { response.body?.string().isNullOrEmpty() }
} }

View File

@ -28,6 +28,31 @@ data class MangaSerializer(
val title: String val title: String
) )
@Serializable
data class MangaSerializerTwo(
val artist: List<String>,
val author: List<String>,
val mainCover: String,
val description: String,
val publication: Publication,
val tags: List<Int>,
// val covers: List<String>,
val isHentai: Boolean,
// val lang_flag: String,
// val lang_name: String,
val lastChapter: String? = null,
val links: LinksSerializer? = null,
val rating: RatingSerializerTwo? = null,
val title: String
)
@Serializable
data class Publication(
val language: String,
val status: Int,
val demographic: Int
)
@Serializable @Serializable
data class LinksSerializer( data class LinksSerializer(
val al: String? = null, val al: String? = null,
@ -47,6 +72,13 @@ data class RatingSerializer(
val users: String? = null val users: String? = null
) )
@Serializable
data class RatingSerializerTwo(
val bayesian: Float? = null,
val mean: Float? = null,
val users: Int? = null
)
@Serializable @Serializable
data class ChapterSerializer( data class ChapterSerializer(
val volume: String? = null, val volume: String? = null,
@ -62,6 +94,22 @@ data class ChapterSerializer(
val timestamp: Long val timestamp: Long
) )
@Serializable
data class ChapterSerializerTwo(
val volume: String? = null,
val chapter: String? = null,
val title: String? = null,
val language: String,
val groups: List<GroupSerializer> = emptyList(),
val timestamp: Long
)
@Serializable
data class GroupSerializer(
val id: Int,
val name: String? = null
)
@Serializable @Serializable
data class CoversResult( data class CoversResult(
val covers: List<String> = emptyList(), val covers: List<String> = emptyList(),