Initial commit
This commit is contained in:
166
multisrc/overrides/mangareader/mangafire/src/Filters.kt
Normal file
166
multisrc/overrides/mangareader/mangafire/src/Filters.kt
Normal file
@@ -0,0 +1,166 @@
|
||||
package eu.kanade.tachiyomi.extension.all.mangafire
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.Filter
|
||||
|
||||
class Entry(name: String, val id: String) : Filter.CheckBox(name) {
|
||||
constructor(name: String) : this(name, name)
|
||||
}
|
||||
|
||||
sealed class Group(
|
||||
name: String,
|
||||
val param: String,
|
||||
values: List<Entry>,
|
||||
) : Filter.Group<Entry>(name, values)
|
||||
|
||||
sealed class Select(
|
||||
name: String,
|
||||
val param: String,
|
||||
private val valuesMap: Map<String, String>,
|
||||
) : Filter.Select<String>(name, valuesMap.keys.toTypedArray()) {
|
||||
open val selection: String
|
||||
get() = valuesMap[values[state]]!!
|
||||
}
|
||||
|
||||
class TypeFilter : Group("Type", "type[]", types)
|
||||
|
||||
private val types: List<Entry>
|
||||
get() = listOf(
|
||||
Entry("Manga", "manga"),
|
||||
Entry("One-Shot", "one_shot"),
|
||||
Entry("Doujinshi", "doujinshi"),
|
||||
Entry("Light-Novel", "light_novel"),
|
||||
Entry("Novel", "novel"),
|
||||
Entry("Manhwa", "manhwa"),
|
||||
Entry("Manhua", "manhua"),
|
||||
)
|
||||
|
||||
class Genre(name: String, val id: String) : Filter.TriState(name) {
|
||||
val selection: String
|
||||
get() = (if (isExcluded()) "-" else "") + id
|
||||
}
|
||||
|
||||
class GenresFilter : Filter.Group<Genre>("Genre", genres) {
|
||||
val param = "genre[]"
|
||||
|
||||
val combineMode: Boolean
|
||||
get() = state.filter { !it.isIgnored() }.size > 1
|
||||
}
|
||||
|
||||
private val genres: List<Genre>
|
||||
get() = listOf(
|
||||
Genre("Action", "1"),
|
||||
Genre("Adventure", "78"),
|
||||
Genre("Avant Garde", "3"),
|
||||
Genre("Boys Love", "4"),
|
||||
Genre("Comedy", "5"),
|
||||
Genre("Demons", "77"),
|
||||
Genre("Drama", "6"),
|
||||
Genre("Ecchi", "7"),
|
||||
Genre("Fantasy", "79"),
|
||||
Genre("Girls Love", "9"),
|
||||
Genre("Gourmet", "10"),
|
||||
Genre("Harem", "11"),
|
||||
Genre("Horror", "530"),
|
||||
Genre("Isekai", "13"),
|
||||
Genre("Iyashikei", "531"),
|
||||
Genre("Josei", "15"),
|
||||
Genre("Kids", "532"),
|
||||
Genre("Magic", "539"),
|
||||
Genre("Mahou Shoujo", "533"),
|
||||
Genre("Martial Arts", "534"),
|
||||
Genre("Mecha", "19"),
|
||||
Genre("Military", "535"),
|
||||
Genre("Music", "21"),
|
||||
Genre("Mystery", "22"),
|
||||
Genre("Parody", "23"),
|
||||
Genre("Psychological", "536"),
|
||||
Genre("Reverse Harem", "25"),
|
||||
Genre("Romance", "26"),
|
||||
Genre("School", "73"),
|
||||
Genre("Sci-Fi", "28"),
|
||||
Genre("Seinen", "537"),
|
||||
Genre("Shoujo", "30"),
|
||||
Genre("Shounen", "31"),
|
||||
Genre("Slice of Life", "538"),
|
||||
Genre("Space", "33"),
|
||||
Genre("Sports", "34"),
|
||||
Genre("Super Power", "75"),
|
||||
Genre("Supernatural", "76"),
|
||||
Genre("Suspense", "37"),
|
||||
Genre("Thriller", "38"),
|
||||
Genre("Vampire", "39"),
|
||||
)
|
||||
|
||||
class StatusFilter : Group("Status", "status[]", statuses)
|
||||
|
||||
private val statuses: List<Entry>
|
||||
get() = listOf(
|
||||
Entry("Completed", "completed"),
|
||||
Entry("Releasing", "releasing"),
|
||||
Entry("On Hiatus", "on_hiatus"),
|
||||
Entry("Discontinued", "discontinued"),
|
||||
Entry("Not Yet Published", "info"),
|
||||
)
|
||||
|
||||
class YearFilter : Group("Year", "year[]", years)
|
||||
|
||||
private val years: List<Entry>
|
||||
get() = listOf(
|
||||
Entry("2023"),
|
||||
Entry("2022"),
|
||||
Entry("2021"),
|
||||
Entry("2020"),
|
||||
Entry("2019"),
|
||||
Entry("2018"),
|
||||
Entry("2017"),
|
||||
Entry("2016"),
|
||||
Entry("2015"),
|
||||
Entry("2014"),
|
||||
Entry("2013"),
|
||||
Entry("2012"),
|
||||
Entry("2011"),
|
||||
Entry("2010"),
|
||||
Entry("2009"),
|
||||
Entry("2008"),
|
||||
Entry("2007"),
|
||||
Entry("2006"),
|
||||
Entry("2005"),
|
||||
Entry("2004"),
|
||||
Entry("2003"),
|
||||
Entry("2000s"),
|
||||
Entry("1990s"),
|
||||
Entry("1980s"),
|
||||
Entry("1970s"),
|
||||
Entry("1960s"),
|
||||
Entry("1950s"),
|
||||
Entry("1940s"),
|
||||
)
|
||||
|
||||
class ChapterCountFilter : Select("Chapter Count", "minchap", chapterCounts)
|
||||
|
||||
private val chapterCounts
|
||||
get() = mapOf(
|
||||
"Any" to "",
|
||||
"At least 1 chapter" to "1",
|
||||
"At least 3 chapters" to "3",
|
||||
"At least 5 chapters" to "5",
|
||||
"At least 10 chapters" to "10",
|
||||
"At least 20 chapters" to "20",
|
||||
"At least 30 chapters" to "30",
|
||||
"At least 50 chapters" to "50",
|
||||
)
|
||||
|
||||
class SortFilter : Select("Sort", "sort", orders)
|
||||
|
||||
private val orders
|
||||
get() = mapOf(
|
||||
"Trending" to "trending",
|
||||
"Recently updated" to "recently_updated",
|
||||
"Recently added" to "recently_added",
|
||||
"Release date" to "release_date",
|
||||
"Name A-Z" to "title_az",
|
||||
"Score" to "scores",
|
||||
"MAL score" to "mal_scores",
|
||||
"Most viewed" to "most_viewed",
|
||||
"Most favourited" to "most_favourited",
|
||||
)
|
||||
@@ -0,0 +1,79 @@
|
||||
package eu.kanade.tachiyomi.extension.all.mangafire
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Rect
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.InputStream
|
||||
import kotlin.math.min
|
||||
|
||||
object ImageInterceptor : Interceptor {
|
||||
|
||||
const val SCRAMBLED = "scrambled"
|
||||
private const val PIECE_SIZE = 200
|
||||
private const val MIN_SPLIT_COUNT = 5
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
val response = chain.proceed(request)
|
||||
val fragment = request.url.fragment ?: return response
|
||||
if (SCRAMBLED !in fragment) return response
|
||||
val offset = fragment.substringAfterLast('_').toInt()
|
||||
|
||||
val image = response.body.byteStream().use { descramble(it, offset) }
|
||||
val body = image.toResponseBody("image/jpeg".toMediaType())
|
||||
return response.newBuilder().body(body).build()
|
||||
}
|
||||
|
||||
private fun descramble(image: InputStream, offset: Int): ByteArray {
|
||||
// obfuscated code: https://mangafire.to/assets/t1/min/all.js
|
||||
// it shuffles arrays of the image slices
|
||||
|
||||
val bitmap = BitmapFactory.decodeStream(image)
|
||||
val width = bitmap.width
|
||||
val height = bitmap.height
|
||||
|
||||
val result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(result)
|
||||
|
||||
val pieceWidth = min(PIECE_SIZE, width.ceilDiv(MIN_SPLIT_COUNT))
|
||||
val pieceHeight = min(PIECE_SIZE, height.ceilDiv(MIN_SPLIT_COUNT))
|
||||
val xMax = width.ceilDiv(pieceWidth) - 1
|
||||
val yMax = height.ceilDiv(pieceHeight) - 1
|
||||
|
||||
for (y in 0..yMax) {
|
||||
for (x in 0..xMax) {
|
||||
val xDst = pieceWidth * x
|
||||
val yDst = pieceHeight * y
|
||||
val w = min(pieceWidth, width - xDst)
|
||||
val h = min(pieceHeight, height - yDst)
|
||||
|
||||
val xSrc = pieceWidth * when (x) {
|
||||
xMax -> x // margin
|
||||
else -> (xMax - x + offset) % xMax
|
||||
}
|
||||
val ySrc = pieceHeight * when (y) {
|
||||
yMax -> y // margin
|
||||
else -> (yMax - y + offset) % yMax
|
||||
}
|
||||
|
||||
val srcRect = Rect(xSrc, ySrc, xSrc + w, ySrc + h)
|
||||
val dstRect = Rect(xDst, yDst, xDst + w, yDst + h)
|
||||
|
||||
canvas.drawBitmap(bitmap, srcRect, dstRect, null)
|
||||
}
|
||||
}
|
||||
|
||||
val output = ByteArrayOutputStream()
|
||||
result.compress(Bitmap.CompressFormat.JPEG, 90, output)
|
||||
return output.toByteArray()
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
private inline fun Int.ceilDiv(other: Int) = (this + (other - 1)) / other
|
||||
}
|
||||
231
multisrc/overrides/mangareader/mangafire/src/MangaFire.kt
Normal file
231
multisrc/overrides/mangareader/mangafire/src/MangaFire.kt
Normal file
@@ -0,0 +1,231 @@
|
||||
package eu.kanade.tachiyomi.extension.all.mangafire
|
||||
|
||||
import eu.kanade.tachiyomi.multisrc.mangareader.MangaReader
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.source.model.Filter
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.int
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import org.jsoup.select.Evaluator
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
open class MangaFire(
|
||||
override val lang: String,
|
||||
private val langCode: String = lang,
|
||||
) : MangaReader() {
|
||||
override val name = "MangaFire"
|
||||
|
||||
override val baseUrl = "https://mangafire.to"
|
||||
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
override val client = network.cloudflareClient.newBuilder()
|
||||
.addInterceptor(ImageInterceptor)
|
||||
.build()
|
||||
|
||||
override fun latestUpdatesRequest(page: Int) =
|
||||
GET("$baseUrl/filter?sort=recently_updated&language[]=$langCode&page=$page", headers)
|
||||
|
||||
override fun popularMangaRequest(page: Int) =
|
||||
GET("$baseUrl/filter?sort=most_viewed&language[]=$langCode&page=$page", headers)
|
||||
|
||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||
val urlBuilder = baseUrl.toHttpUrl().newBuilder()
|
||||
if (query.isNotBlank()) {
|
||||
urlBuilder.addPathSegment("filter").apply {
|
||||
addQueryParameter("keyword", query)
|
||||
addQueryParameter("page", page.toString())
|
||||
}
|
||||
} else {
|
||||
urlBuilder.addPathSegment("filter").apply {
|
||||
addQueryParameter("language[]", langCode)
|
||||
addQueryParameter("page", page.toString())
|
||||
filters.ifEmpty(::getFilterList).forEach { filter ->
|
||||
when (filter) {
|
||||
is Group -> {
|
||||
filter.state.forEach {
|
||||
if (it.state) {
|
||||
addQueryParameter(filter.param, it.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
is Select -> {
|
||||
addQueryParameter(filter.param, filter.selection)
|
||||
}
|
||||
is GenresFilter -> {
|
||||
filter.state.forEach {
|
||||
if (it.state != 0) {
|
||||
addQueryParameter(filter.param, it.selection)
|
||||
}
|
||||
}
|
||||
if (filter.combineMode) {
|
||||
addQueryParameter("genre_mode", "and")
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return GET(urlBuilder.build(), headers)
|
||||
}
|
||||
|
||||
override fun searchMangaNextPageSelector() = ".page-item.active + .page-item .page-link"
|
||||
|
||||
override fun searchMangaSelector() = ".original.card-lg .unit .inner"
|
||||
|
||||
override fun searchMangaFromElement(element: Element) =
|
||||
SManga.create().apply {
|
||||
element.selectFirst(".info > a")!!.let {
|
||||
setUrlWithoutDomain(it.attr("href"))
|
||||
title = it.ownText()
|
||||
}
|
||||
element.selectFirst(Evaluator.Tag("img"))!!.let {
|
||||
thumbnail_url = it.attr("src")
|
||||
}
|
||||
}
|
||||
|
||||
override fun mangaDetailsParse(document: Document) = SManga.create().apply {
|
||||
val root = document.selectFirst(".info")!!
|
||||
val mangaTitle = root.child(1).ownText()
|
||||
title = mangaTitle
|
||||
description = document.run {
|
||||
val description = selectFirst(Evaluator.Class("description"))!!.ownText()
|
||||
when (val altTitle = root.child(2).ownText()) {
|
||||
"", mangaTitle -> description
|
||||
else -> "$description\n\nAlternative Title: $altTitle"
|
||||
}
|
||||
}
|
||||
thumbnail_url = document.selectFirst(".poster")!!
|
||||
.selectFirst("img")!!.attr("src")
|
||||
status = when (root.child(0).ownText()) {
|
||||
"Completed" -> SManga.COMPLETED
|
||||
"Releasing" -> SManga.ONGOING
|
||||
"On_hiatus" -> SManga.ON_HIATUS
|
||||
"Discontinued" -> SManga.CANCELLED
|
||||
else -> SManga.UNKNOWN
|
||||
}
|
||||
with(document.selectFirst(Evaluator.Class("meta"))!!) {
|
||||
author = selectFirst("span:contains(Author:) + span")?.text()
|
||||
val type = selectFirst("span:contains(Type:) + span")?.text()
|
||||
val genres = selectFirst("span:contains(Genres:) + span")?.text()
|
||||
genre = listOfNotNull(type, genres).joinToString()
|
||||
}
|
||||
}
|
||||
|
||||
override val chapterType get() = "chapter"
|
||||
override val volumeType get() = "volume"
|
||||
|
||||
override fun chapterListRequest(mangaUrl: String, type: String): Request {
|
||||
val id = mangaUrl.substringAfterLast('.')
|
||||
return GET("$baseUrl/ajax/manga/$id/$type/$langCode", headers)
|
||||
}
|
||||
|
||||
override fun parseChapterElements(response: Response, isVolume: Boolean): List<Element> {
|
||||
val result = json.decodeFromString<ResponseDto<String>>(response.body.string()).result
|
||||
val document = Jsoup.parse(result)
|
||||
|
||||
val elements = document.select("ul li")
|
||||
if (elements.size > 0) {
|
||||
val linkToFirstChapter = elements[0].selectFirst(Evaluator.Tag("a"))!!.attr("href")
|
||||
val mangaId = linkToFirstChapter.toString().substringAfter('.').substringBefore('/')
|
||||
|
||||
val request = GET("$baseUrl/ajax/read/$mangaId/chapter/$langCode", headers)
|
||||
val response = client.newCall(request).execute()
|
||||
val res = json.decodeFromString<ResponseDto<ChapterIdsDto>>(response.body.string()).result.html
|
||||
val chapterInfoDocument = Jsoup.parse(res)
|
||||
val chapters = chapterInfoDocument.select("ul li")
|
||||
for ((i, it) in elements.withIndex()) {
|
||||
it.attr("data-id", chapters[i].select("a").attr("data-id"))
|
||||
}
|
||||
}
|
||||
return elements.toList()
|
||||
}
|
||||
|
||||
@Serializable
|
||||
class ChapterIdsDto(
|
||||
val html: String,
|
||||
val title_format: String,
|
||||
)
|
||||
|
||||
override fun updateChapterList(manga: SManga, chapters: List<SChapter>) {
|
||||
val request = chapterListRequest(manga.url, chapterType)
|
||||
val response = client.newCall(request).execute()
|
||||
val result = json.decodeFromString<ResponseDto<String>>(response.body.string()).result
|
||||
val document = Jsoup.parse(result)
|
||||
|
||||
val elements = document.selectFirst(".scroll-sm")!!.children()
|
||||
val chapterCount = chapters.size
|
||||
if (elements.size != chapterCount) throw Exception("Chapter count doesn't match. Try updating again.")
|
||||
val dateFormat = SimpleDateFormat("MMM dd, yyyy", Locale.US)
|
||||
for (i in 0 until chapterCount) {
|
||||
val chapter = chapters[i]
|
||||
val element = elements[i]
|
||||
val number = element.attr("data-number").toFloatOrNull() ?: -1f
|
||||
if (chapter.chapter_number != number) throw Exception("Chapter number doesn't match. Try updating again.")
|
||||
val date = element.select(Evaluator.Tag("span"))[1].ownText()
|
||||
chapter.date_upload = try {
|
||||
dateFormat.parse(date)!!.time
|
||||
} catch (_: Throwable) {
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun pageListRequest(chapter: SChapter): Request {
|
||||
val typeAndId = chapter.url.substringAfterLast('#')
|
||||
return GET("$baseUrl/ajax/read/$typeAndId", headers)
|
||||
}
|
||||
|
||||
override fun pageListParse(response: Response): List<Page> {
|
||||
val result = json.decodeFromString<ResponseDto<PageListDto>>(response.body.string()).result
|
||||
|
||||
return result.pages.mapIndexed { index, image ->
|
||||
val url = image.url
|
||||
val offset = image.offset
|
||||
val imageUrl = if (offset > 0) "$url#${ImageInterceptor.SCRAMBLED}_$offset" else url
|
||||
|
||||
Page(index, imageUrl = imageUrl)
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
class PageListDto(private val images: List<List<JsonPrimitive>>) {
|
||||
val pages get() = images.map {
|
||||
Image(it[0].content, it[2].int)
|
||||
}
|
||||
}
|
||||
class Image(val url: String, val offset: Int)
|
||||
|
||||
@Serializable
|
||||
class ResponseDto<T>(
|
||||
val result: T,
|
||||
val status: Int,
|
||||
)
|
||||
|
||||
override fun getFilterList() =
|
||||
FilterList(
|
||||
Filter.Header("NOTE: Ignored if using text search!"),
|
||||
Filter.Separator(),
|
||||
TypeFilter(),
|
||||
GenresFilter(),
|
||||
StatusFilter(),
|
||||
YearFilter(),
|
||||
ChapterCountFilter(),
|
||||
SortFilter(),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package eu.kanade.tachiyomi.extension.all.mangafire
|
||||
|
||||
import eu.kanade.tachiyomi.source.SourceFactory
|
||||
|
||||
class MangaFireFactory : SourceFactory {
|
||||
override fun createSources() = listOf(
|
||||
MangaFire("en"),
|
||||
MangaFire("es"),
|
||||
MangaFire("es-419", "es-la"),
|
||||
MangaFire("fr"),
|
||||
MangaFire("ja"),
|
||||
MangaFire("pt"),
|
||||
MangaFire("pt-BR", "pt-br"),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user