FMTeam: Migrate to PizzaReader (#1668)

* FMTeam: Migrate to PizzaReader

* Add missing trailing commas
This commit is contained in:
KirinRaikage 2024-03-03 03:15:05 +01:00 committed by GitHub
parent d67eb92fab
commit 3f5a763655
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6 additions and 180 deletions

View File

@ -21,7 +21,7 @@ data class PizzaReaderDto(
@Serializable
data class PizzaComicDto(
val artist: String = "",
val artist: String? = null,
val author: String = "",
val chapters: List<PizzaChapterDto> = emptyList(),
val description: String = "",

View File

@ -1,7 +1,9 @@
ext {
extName = 'FMTEAM'
extClass = '.FMTEAM'
extVersionCode = 2
themePkg = 'pizzareader'
baseUrl = 'https://fmteam.fr'
overrideVersionCode = 3
}
apply from: "$rootDir/common.gradle"

View File

@ -1,129 +1,7 @@
package eu.kanade.tachiyomi.extension.fr.fmteam
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import okhttp3.Request
import okhttp3.Response
import uy.kohesive.injekt.injectLazy
import java.text.SimpleDateFormat
import java.util.Locale
import java.util.TimeZone
import eu.kanade.tachiyomi.multisrc.pizzareader.PizzaReader
class FMTEAM : HttpSource() {
override val name = "FMTEAM"
override val baseUrl = "https://fmteam.fr"
override val lang = "fr"
override val supportsLatest = true
class FMTEAM : PizzaReader("FMTEAM", "https://fmteam.fr", "fr") {
override val versionId = 2
private val json: Json by injectLazy()
companion object {
private val DATE_FORMATTER by lazy {
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US).apply {
timeZone = TimeZone.getTimeZone("UTC")
}
}
}
// All manga
override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/api/comics")
override fun popularMangaParse(response: Response): MangasPage {
val results = json.decodeFromString<FmteamComicListPage>(response.body.string())
return MangasPage(results.comics.sortedByDescending { it.views }.map(::fmTeamComicToSManga), false)
}
// Latest
override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/api/comics")
override fun latestUpdatesParse(response: Response): MangasPage {
val results = json.decodeFromString<FmteamComicListPage>(response.body.string())
return MangasPage(results.comics.sortedByDescending { parseDate(it.last_chapter.published_on) }.map(::fmTeamComicToSManga), false)
}
// Search
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = GET("$baseUrl/api/search/$query")
override fun searchMangaParse(response: Response): MangasPage {
val results = json.decodeFromString<FmteamComicListPage>(response.body.string())
return MangasPage(results.comics.map(::fmTeamComicToSManga), false)
}
// Manga details
override fun mangaDetailsRequest(manga: SManga): Request = GET("$baseUrl/api${manga.url}")
override fun mangaDetailsParse(response: Response): SManga {
val results = json.decodeFromString<FmteamComicDetailPage>(response.body.string())
return fmTeamComicToSManga(results.comic)
}
override fun getMangaUrl(manga: SManga): String {
return "$baseUrl${manga.url}"
}
// Chapter list
override fun chapterListRequest(manga: SManga): Request = GET("$baseUrl/api${manga.url}")
override fun chapterListParse(response: Response): List<SChapter> {
val results = json.decodeFromString<FmteamComicDetailPage>(response.body.string())
return results.comic.chapters?.map(::fmTeamChapterToSChapter) ?: emptyList()
}
override fun getChapterUrl(chapter: SChapter): String {
return "$baseUrl${chapter.url}"
}
// Pages
override fun pageListRequest(chapter: SChapter): Request = GET("$baseUrl/api${chapter.url}")
override fun pageListParse(response: Response): List<Page> {
val results = json.decodeFromString<FmteamChapterDetailPage>(response.body.string())
return results.chapter.pages.orEmpty()
.mapIndexed { i, page -> Page(i, "${results.chapter.url}#${i + 1}", page) }
}
override fun imageUrlParse(response: Response): String = throw UnsupportedOperationException()
// Utils
private fun fmTeamComicToSManga(comic: FmteamComic): SManga = SManga.create().apply {
url = comic.url
title = comic.title
artist = comic.artist
author = comic.author
description = comic.description
genre = comic.genres.joinToString { it.name }
status = when (comic.status) {
"En cours" -> SManga.ONGOING
"Termin\u00e9" -> SManga.COMPLETED
else -> SManga.UNKNOWN
}
thumbnail_url = comic.thumbnail
initialized = true
}
private fun fmTeamChapterToSChapter(chapter: FmteamChapter): SChapter = SChapter.create().apply {
url = chapter.url
name = chapter.full_title
date_upload = parseDate(chapter.published_on)
scanlator = chapter.teams.filterNotNull().joinToString { it.name }
}
private fun parseDate(dateStr: String): Long {
return runCatching { DATE_FORMATTER.parse(dateStr)?.time }
.getOrNull() ?: 0L
}
}

View File

@ -1,54 +0,0 @@
package eu.kanade.tachiyomi.extension.fr.fmteam
import kotlinx.serialization.Serializable
@Serializable
data class FmteamComicListPage(
val comics: List<FmteamComic>,
)
@Serializable
data class FmteamComicDetailPage(
val comic: FmteamComic,
)
@Serializable
data class FmteamChapterDetailPage(
val chapter: FmteamChapter,
)
@Serializable
data class FmteamComic(
val title: String,
val thumbnail: String,
val description: String,
val author: String,
val artist: String?,
val genres: List<FmteamTag>,
val status: String,
val views: Int,
val url: String,
val last_chapter: FmteamChapter,
val chapters: List<FmteamChapter>?,
)
@Serializable
data class FmteamTag(
val name: String,
)
@Serializable
data class FmteamChapter(
val full_title: String,
val chapter: Int,
val subchapter: Int?,
val teams: List<FmteamTeam?>,
val published_on: String,
val url: String,
val pages: List<String>?,
)
@Serializable
data class FmteamTeam(
val name: String,
)