Merge branch 'devel' into feature/shikimori
commit
3b357eb509
@ -1 +1 @@
|
|||||||
custom: ["https://money.yandex.ru/to/410012543938752"]
|
custom: ["https://yoomoney.ru/to/410012543938752"]
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="KtlintProjectConfiguration">
|
||||||
|
<androidMode>true</androidMode>
|
||||||
|
<treatAsErrors>false</treatAsErrors>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
<bool name="leak_canary_add_launcher_icon">false</bool>
|
<bool name="leak_canary_add_launcher_icon" tools:node="replace">false</bool>
|
||||||
</resources>
|
</resources>
|
||||||
@ -1,100 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.base.domain
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.webkit.WebView
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import okhttp3.*
|
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.koin.core.component.KoinComponent
|
|
||||||
import org.koin.core.component.get
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.GraphQLException
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
|
||||||
import org.koitharu.kotatsu.utils.ext.await
|
|
||||||
import org.koitharu.kotatsu.utils.ext.parseJson
|
|
||||||
import kotlin.coroutines.resume
|
|
||||||
import kotlin.coroutines.suspendCoroutine
|
|
||||||
|
|
||||||
open class MangaLoaderContext(
|
|
||||||
private val okHttp: OkHttpClient,
|
|
||||||
val cookieJar: CookieJar,
|
|
||||||
) : KoinComponent {
|
|
||||||
|
|
||||||
suspend fun httpGet(url: String, headers: Headers? = null): Response {
|
|
||||||
val request = Request.Builder()
|
|
||||||
.get()
|
|
||||||
.url(url)
|
|
||||||
if (headers != null) {
|
|
||||||
request.headers(headers)
|
|
||||||
}
|
|
||||||
return okHttp.newCall(request.build()).await()
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun httpPost(
|
|
||||||
url: String,
|
|
||||||
form: Map<String, String>,
|
|
||||||
): Response {
|
|
||||||
val body = FormBody.Builder()
|
|
||||||
form.forEach { (k, v) ->
|
|
||||||
body.addEncoded(k, v)
|
|
||||||
}
|
|
||||||
val request = Request.Builder()
|
|
||||||
.post(body.build())
|
|
||||||
.url(url)
|
|
||||||
return okHttp.newCall(request.build()).await()
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun httpPost(
|
|
||||||
url: String,
|
|
||||||
payload: String,
|
|
||||||
): Response {
|
|
||||||
val body = FormBody.Builder()
|
|
||||||
payload.split('&').forEach {
|
|
||||||
val pos = it.indexOf('=')
|
|
||||||
if (pos != -1) {
|
|
||||||
val k = it.substring(0, pos)
|
|
||||||
val v = it.substring(pos + 1)
|
|
||||||
body.addEncoded(k, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val request = Request.Builder()
|
|
||||||
.post(body.build())
|
|
||||||
.url(url)
|
|
||||||
return okHttp.newCall(request.build()).await()
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun graphQLQuery(endpoint: String, query: String): JSONObject {
|
|
||||||
val body = JSONObject()
|
|
||||||
body.put("operationName", null)
|
|
||||||
body.put("variables", JSONObject())
|
|
||||||
body.put("query", "{${query}}")
|
|
||||||
val mediaType = "application/json; charset=utf-8".toMediaType()
|
|
||||||
val requestBody = body.toString().toRequestBody(mediaType)
|
|
||||||
val request = Request.Builder()
|
|
||||||
.post(requestBody)
|
|
||||||
.url(endpoint)
|
|
||||||
val json = okHttp.newCall(request.build()).await().parseJson()
|
|
||||||
json.optJSONArray("errors")?.let {
|
|
||||||
if (it.length() != 0) {
|
|
||||||
throw GraphQLException(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return json
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
|
||||||
open suspend fun evaluateJs(script: String): String? = withContext(Dispatchers.Main) {
|
|
||||||
val webView = WebView(get())
|
|
||||||
webView.settings.javaScriptEnabled = true
|
|
||||||
suspendCoroutine { cont ->
|
|
||||||
webView.evaluateJavascript(script) { result ->
|
|
||||||
cont.resume(result?.takeUnless { it == "null" })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun getSettings(source: MangaSource) = SourceSettings(get(), source)
|
|
||||||
}
|
|
||||||
@ -0,0 +1,111 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.list.decor
|
||||||
|
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Rect
|
||||||
|
import android.graphics.RectF
|
||||||
|
import android.view.View
|
||||||
|
import androidx.core.view.children
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView.NO_ID
|
||||||
|
|
||||||
|
abstract class AbstractSelectionItemDecoration : RecyclerView.ItemDecoration() {
|
||||||
|
|
||||||
|
private val bounds = Rect()
|
||||||
|
private val boundsF = RectF()
|
||||||
|
private val selection = HashSet<Long>()
|
||||||
|
|
||||||
|
protected var hasBackground: Boolean = true
|
||||||
|
protected var hasForeground: Boolean = false
|
||||||
|
protected var isIncludeDecorAndMargins: Boolean = true
|
||||||
|
|
||||||
|
val checkedItemsCount: Int
|
||||||
|
get() = selection.size
|
||||||
|
|
||||||
|
val checkedItemsIds: Set<Long>
|
||||||
|
get() = selection
|
||||||
|
|
||||||
|
fun toggleItemChecked(id: Long) {
|
||||||
|
if (!selection.remove(id)) {
|
||||||
|
selection.add(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setItemIsChecked(id: Long, isChecked: Boolean) {
|
||||||
|
if (isChecked) {
|
||||||
|
selection.add(id)
|
||||||
|
} else {
|
||||||
|
selection.remove(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun checkAll(ids: Collection<Long>) {
|
||||||
|
selection.addAll(ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearSelection() {
|
||||||
|
selection.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {
|
||||||
|
if (hasBackground) {
|
||||||
|
doDraw(canvas, parent, state, false)
|
||||||
|
} else {
|
||||||
|
super.onDraw(canvas, parent, state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDrawOver(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {
|
||||||
|
if (hasForeground) {
|
||||||
|
doDraw(canvas, parent, state, true)
|
||||||
|
} else {
|
||||||
|
super.onDrawOver(canvas, parent, state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State, isOver: Boolean) {
|
||||||
|
val checkpoint = canvas.save()
|
||||||
|
if (parent.clipToPadding) {
|
||||||
|
canvas.clipRect(
|
||||||
|
parent.paddingLeft, parent.paddingTop, parent.width - parent.paddingRight,
|
||||||
|
parent.height - parent.paddingBottom
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (child in parent.children) {
|
||||||
|
val itemId = getItemId(parent, child)
|
||||||
|
if (itemId != NO_ID && itemId in selection) {
|
||||||
|
if (isIncludeDecorAndMargins) {
|
||||||
|
parent.getDecoratedBoundsWithMargins(child, bounds)
|
||||||
|
} else {
|
||||||
|
bounds.set(child.left, child.top, child.right, child.bottom)
|
||||||
|
}
|
||||||
|
boundsF.set(bounds)
|
||||||
|
boundsF.offset(child.translationX, child.translationY)
|
||||||
|
if (isOver) {
|
||||||
|
onDrawForeground(canvas, parent, child, boundsF, state)
|
||||||
|
} else {
|
||||||
|
onDrawBackground(canvas, parent, child, boundsF, state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canvas.restoreToCount(checkpoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun getItemId(parent: RecyclerView, child: View) = parent.getChildItemId(child)
|
||||||
|
|
||||||
|
protected open fun onDrawBackground(
|
||||||
|
canvas: Canvas,
|
||||||
|
parent: RecyclerView,
|
||||||
|
child: View,
|
||||||
|
bounds: RectF,
|
||||||
|
state: RecyclerView.State,
|
||||||
|
) = Unit
|
||||||
|
|
||||||
|
protected open fun onDrawForeground(
|
||||||
|
canvas: Canvas,
|
||||||
|
parent: RecyclerView,
|
||||||
|
child: View,
|
||||||
|
bounds: RectF,
|
||||||
|
state: RecyclerView.State,
|
||||||
|
) = Unit
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import androidx.appcompat.view.ActionMode
|
||||||
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
|
||||||
|
class ActionModeDelegate {
|
||||||
|
|
||||||
|
private var activeActionMode: ActionMode? = null
|
||||||
|
private var listeners: MutableList<ActionModeListener>? = null
|
||||||
|
|
||||||
|
val isActionModeStarted: Boolean
|
||||||
|
get() = activeActionMode != null
|
||||||
|
|
||||||
|
fun onSupportActionModeStarted(mode: ActionMode) {
|
||||||
|
activeActionMode = mode
|
||||||
|
listeners?.forEach { it.onActionModeStarted(mode) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onSupportActionModeFinished(mode: ActionMode) {
|
||||||
|
activeActionMode = null
|
||||||
|
listeners?.forEach { it.onActionModeFinished(mode) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addListener(listener: ActionModeListener) {
|
||||||
|
if (listeners == null) {
|
||||||
|
listeners = ArrayList()
|
||||||
|
}
|
||||||
|
checkNotNull(listeners).add(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeListener(listener: ActionModeListener) {
|
||||||
|
listeners?.remove(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addListener(listener: ActionModeListener, owner: LifecycleOwner) {
|
||||||
|
addListener(listener)
|
||||||
|
owner.lifecycle.addObserver(ListenerLifecycleObserver(listener))
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class ListenerLifecycleObserver(
|
||||||
|
private val listener: ActionModeListener,
|
||||||
|
) : DefaultLifecycleObserver {
|
||||||
|
|
||||||
|
override fun onDestroy(owner: LifecycleOwner) {
|
||||||
|
super.onDestroy(owner)
|
||||||
|
removeListener(listener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import androidx.appcompat.view.ActionMode
|
||||||
|
|
||||||
|
interface ActionModeListener {
|
||||||
|
|
||||||
|
fun onActionModeStarted(mode: ActionMode)
|
||||||
|
|
||||||
|
fun onActionModeFinished(mode: ActionMode)
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
|
interface RecyclerViewOwner {
|
||||||
|
|
||||||
|
val recyclerView: RecyclerView
|
||||||
|
}
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
|
|
||||||
|
class ShrinkOnScrollBehavior : Behavior<ExtendedFloatingActionButton> {
|
||||||
|
|
||||||
|
@Suppress("unused") constructor() : super()
|
||||||
|
@Suppress("unused") constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
||||||
|
|
||||||
|
override fun onStartNestedScroll(
|
||||||
|
coordinatorLayout: CoordinatorLayout,
|
||||||
|
child: ExtendedFloatingActionButton,
|
||||||
|
directTargetChild: View,
|
||||||
|
target: View,
|
||||||
|
axes: Int,
|
||||||
|
type: Int
|
||||||
|
): Boolean {
|
||||||
|
return axes == ViewCompat.SCROLL_AXIS_VERTICAL
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNestedScroll(
|
||||||
|
coordinatorLayout: CoordinatorLayout,
|
||||||
|
child: ExtendedFloatingActionButton,
|
||||||
|
target: View,
|
||||||
|
dxConsumed: Int,
|
||||||
|
dyConsumed: Int,
|
||||||
|
dxUnconsumed: Int,
|
||||||
|
dyUnconsumed: Int,
|
||||||
|
type: Int,
|
||||||
|
consumed: IntArray
|
||||||
|
) {
|
||||||
|
if (dyConsumed > 0) {
|
||||||
|
if (child.isExtended) {
|
||||||
|
child.shrink()
|
||||||
|
}
|
||||||
|
} else if (dyConsumed < 0) {
|
||||||
|
if (!child.isExtended) {
|
||||||
|
child.extend()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.core.graphics.Insets
|
||||||
|
import androidx.core.view.OnApplyWindowInsetsListener
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
|
||||||
|
class WindowInsetsDelegate(
|
||||||
|
private val listener: WindowInsetsListener,
|
||||||
|
) : OnApplyWindowInsetsListener, View.OnLayoutChangeListener {
|
||||||
|
|
||||||
|
var handleImeInsets: Boolean = false
|
||||||
|
|
||||||
|
var interceptingWindowInsetsListener: OnApplyWindowInsetsListener? = null
|
||||||
|
|
||||||
|
private var lastInsets: Insets? = null
|
||||||
|
|
||||||
|
override fun onApplyWindowInsets(v: View?, insets: WindowInsetsCompat?): WindowInsetsCompat? {
|
||||||
|
if (insets == null) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val handledInsets = interceptingWindowInsetsListener?.onApplyWindowInsets(v, insets) ?: insets
|
||||||
|
val newInsets = if (handleImeInsets) {
|
||||||
|
Insets.max(
|
||||||
|
handledInsets.getInsets(WindowInsetsCompat.Type.systemBars()),
|
||||||
|
handledInsets.getInsets(WindowInsetsCompat.Type.ime()),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
handledInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
|
}
|
||||||
|
if (newInsets != lastInsets) {
|
||||||
|
listener.onWindowInsetsChanged(newInsets)
|
||||||
|
lastInsets = newInsets
|
||||||
|
}
|
||||||
|
return handledInsets
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLayoutChange(
|
||||||
|
view: View,
|
||||||
|
left: Int,
|
||||||
|
top: Int,
|
||||||
|
right: Int,
|
||||||
|
bottom: Int,
|
||||||
|
oldLeft: Int,
|
||||||
|
oldTop: Int,
|
||||||
|
oldRight: Int,
|
||||||
|
oldBottom: Int,
|
||||||
|
) {
|
||||||
|
view.removeOnLayoutChangeListener(this)
|
||||||
|
if (lastInsets == null) { // Listener may not be called
|
||||||
|
onApplyWindowInsets(view, ViewCompat.getRootWindowInsets(view))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onViewCreated(view: View) {
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(view, this)
|
||||||
|
view.addOnLayoutChangeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onDestroyView() {
|
||||||
|
lastInsets = null
|
||||||
|
}
|
||||||
|
|
||||||
|
interface WindowInsetsListener {
|
||||||
|
|
||||||
|
fun onWindowInsetsChanged(insets: Insets)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,126 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.ColorStateList
|
||||||
|
import android.content.res.TypedArray
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.graphics.drawable.InsetDrawable
|
||||||
|
import android.graphics.drawable.RippleDrawable
|
||||||
|
import android.graphics.drawable.ShapeDrawable
|
||||||
|
import android.graphics.drawable.shapes.RectShape
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import androidx.annotation.AttrRes
|
||||||
|
import androidx.appcompat.widget.AppCompatCheckedTextView
|
||||||
|
import androidx.core.content.res.use
|
||||||
|
import androidx.core.content.withStyledAttributes
|
||||||
|
import com.google.android.material.ripple.RippleUtils
|
||||||
|
import com.google.android.material.shape.MaterialShapeDrawable
|
||||||
|
import com.google.android.material.shape.ShapeAppearanceModel
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
|
class ListItemTextView @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
@AttrRes defStyleAttr: Int = R.attr.listItemTextViewStyle,
|
||||||
|
) : AppCompatCheckedTextView(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
private var checkedDrawableStart: Drawable? = null
|
||||||
|
private var checkedDrawableEnd: Drawable? = null
|
||||||
|
private var isInitialized = false
|
||||||
|
private var isCheckDrawablesVisible: Boolean = false
|
||||||
|
private var defaultPaddingStart: Int = 0
|
||||||
|
private var defaultPaddingEnd: Int = 0
|
||||||
|
|
||||||
|
init {
|
||||||
|
context.withStyledAttributes(attrs, R.styleable.ListItemTextView, defStyleAttr) {
|
||||||
|
val itemRippleColor = getColorStateList(R.styleable.ListItemTextView_rippleColor)
|
||||||
|
?: getRippleColorFallback(context)
|
||||||
|
val shape = createShapeDrawable(this)
|
||||||
|
background = RippleDrawable(
|
||||||
|
RippleUtils.sanitizeRippleDrawableColor(itemRippleColor),
|
||||||
|
shape,
|
||||||
|
ShapeDrawable(RectShape()),
|
||||||
|
)
|
||||||
|
checkedDrawableStart = getDrawable(R.styleable.ListItemTextView_checkedDrawableStart)
|
||||||
|
checkedDrawableEnd = getDrawable(R.styleable.ListItemTextView_checkedDrawableEnd)
|
||||||
|
}
|
||||||
|
checkedDrawableStart?.setTintList(textColors)
|
||||||
|
checkedDrawableEnd?.setTintList(textColors)
|
||||||
|
defaultPaddingStart = paddingStart
|
||||||
|
defaultPaddingEnd = paddingEnd
|
||||||
|
isInitialized = true
|
||||||
|
adjustCheckDrawables()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun refreshDrawableState() {
|
||||||
|
super.refreshDrawableState()
|
||||||
|
adjustCheckDrawables()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setTextColor(colors: ColorStateList?) {
|
||||||
|
checkedDrawableStart?.setTintList(colors)
|
||||||
|
checkedDrawableEnd?.setTintList(colors)
|
||||||
|
super.setTextColor(colors)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setPaddingRelative(start: Int, top: Int, end: Int, bottom: Int) {
|
||||||
|
defaultPaddingStart = start
|
||||||
|
defaultPaddingEnd = end
|
||||||
|
super.setPaddingRelative(start, top, end, bottom)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setPadding(left: Int, top: Int, right: Int, bottom: Int) {
|
||||||
|
val isRtl = layoutDirection == LAYOUT_DIRECTION_RTL
|
||||||
|
defaultPaddingStart = if (isRtl) right else left
|
||||||
|
defaultPaddingEnd = if (isRtl) left else right
|
||||||
|
super.setPadding(left, top, right, bottom)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun adjustCheckDrawables() {
|
||||||
|
if (isInitialized && isCheckDrawablesVisible != isChecked) {
|
||||||
|
setCompoundDrawablesRelativeWithIntrinsicBounds(
|
||||||
|
if (isChecked) checkedDrawableStart else null,
|
||||||
|
null,
|
||||||
|
if (isChecked) checkedDrawableEnd else null,
|
||||||
|
null,
|
||||||
|
)
|
||||||
|
super.setPaddingRelative(
|
||||||
|
if (isChecked && checkedDrawableStart != null) {
|
||||||
|
defaultPaddingStart + compoundDrawablePadding
|
||||||
|
} else defaultPaddingStart,
|
||||||
|
paddingTop,
|
||||||
|
if (isChecked && checkedDrawableEnd != null) {
|
||||||
|
defaultPaddingEnd + compoundDrawablePadding
|
||||||
|
} else defaultPaddingEnd,
|
||||||
|
paddingBottom,
|
||||||
|
)
|
||||||
|
isCheckDrawablesVisible = isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createShapeDrawable(ta: TypedArray): InsetDrawable {
|
||||||
|
val shapeAppearance = ShapeAppearanceModel.builder(
|
||||||
|
context,
|
||||||
|
ta.getResourceId(R.styleable.ListItemTextView_shapeAppearance, 0),
|
||||||
|
ta.getResourceId(R.styleable.ListItemTextView_shapeAppearanceOverlay, 0),
|
||||||
|
).build()
|
||||||
|
val shapeDrawable = MaterialShapeDrawable(shapeAppearance)
|
||||||
|
shapeDrawable.fillColor = ta.getColorStateList(R.styleable.ListItemTextView_backgroundTint)
|
||||||
|
return InsetDrawable(
|
||||||
|
shapeDrawable,
|
||||||
|
ta.getDimensionPixelOffset(R.styleable.ListItemTextView_android_insetLeft, 0),
|
||||||
|
ta.getDimensionPixelOffset(R.styleable.ListItemTextView_android_insetTop, 0),
|
||||||
|
ta.getDimensionPixelOffset(R.styleable.ListItemTextView_android_insetRight, 0),
|
||||||
|
ta.getDimensionPixelOffset(R.styleable.ListItemTextView_android_insetBottom, 0),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getRippleColorFallback(context: Context): ColorStateList {
|
||||||
|
return context.obtainStyledAttributes(intArrayOf(android.R.attr.colorControlHighlight)).use {
|
||||||
|
it.getColorStateList(0)
|
||||||
|
} ?: ColorStateList.valueOf(Color.TRANSPARENT)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,28 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.db
|
package org.koitharu.kotatsu.core.db
|
||||||
|
|
||||||
import androidx.room.Room
|
|
||||||
import org.koin.android.ext.koin.androidContext
|
import org.koin.android.ext.koin.androidContext
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koitharu.kotatsu.core.db.migrations.*
|
|
||||||
|
|
||||||
val databaseModule
|
val databaseModule
|
||||||
get() = module {
|
get() = module {
|
||||||
single {
|
single { MangaDatabase.create(androidContext()) }
|
||||||
Room.databaseBuilder(
|
|
||||||
androidContext(),
|
|
||||||
MangaDatabase::class.java,
|
|
||||||
"kotatsu-db"
|
|
||||||
).addMigrations(
|
|
||||||
Migration1To2(),
|
|
||||||
Migration2To3(),
|
|
||||||
Migration3To4(),
|
|
||||||
Migration4To5(),
|
|
||||||
Migration5To6(),
|
|
||||||
Migration6To7(),
|
|
||||||
Migration7To8(),
|
|
||||||
Migration8To9(),
|
|
||||||
).addCallback(
|
|
||||||
DatabasePrePopulateCallback(androidContext().resources)
|
|
||||||
).build()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.entity
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
import org.koitharu.kotatsu.core.model.TrackingLogItem
|
||||||
|
import org.koitharu.kotatsu.parsers.model.*
|
||||||
|
import org.koitharu.kotatsu.parsers.util.longHashCode
|
||||||
|
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||||
|
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||||
|
|
||||||
|
// Entity to model
|
||||||
|
|
||||||
|
fun TagEntity.toMangaTag() = MangaTag(
|
||||||
|
key = this.key,
|
||||||
|
title = this.title.toTitleCase(),
|
||||||
|
source = MangaSource.valueOf(this.source),
|
||||||
|
)
|
||||||
|
|
||||||
|
fun Collection<TagEntity>.toMangaTags() = mapToSet(TagEntity::toMangaTag)
|
||||||
|
|
||||||
|
fun MangaEntity.toManga(tags: Set<MangaTag>) = Manga(
|
||||||
|
id = this.id,
|
||||||
|
title = this.title,
|
||||||
|
altTitle = this.altTitle,
|
||||||
|
state = this.state?.let { MangaState.valueOf(it) },
|
||||||
|
rating = this.rating,
|
||||||
|
isNsfw = this.isNsfw,
|
||||||
|
url = this.url,
|
||||||
|
publicUrl = this.publicUrl,
|
||||||
|
coverUrl = this.coverUrl,
|
||||||
|
largeCoverUrl = this.largeCoverUrl,
|
||||||
|
author = this.author,
|
||||||
|
source = MangaSource.valueOf(this.source),
|
||||||
|
tags = tags
|
||||||
|
)
|
||||||
|
|
||||||
|
fun MangaWithTags.toManga() = manga.toManga(tags.toMangaTags())
|
||||||
|
|
||||||
|
fun TrackLogWithManga.toTrackingLogItem() = TrackingLogItem(
|
||||||
|
id = trackLog.id,
|
||||||
|
chapters = trackLog.chapters.split('\n').filterNot { x -> x.isEmpty() },
|
||||||
|
manga = manga.toManga(tags.toMangaTags()),
|
||||||
|
createdAt = Date(trackLog.createdAt)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Model to entity
|
||||||
|
|
||||||
|
fun Manga.toEntity() = MangaEntity(
|
||||||
|
id = id,
|
||||||
|
url = url,
|
||||||
|
publicUrl = publicUrl,
|
||||||
|
source = source.name,
|
||||||
|
largeCoverUrl = largeCoverUrl,
|
||||||
|
coverUrl = coverUrl,
|
||||||
|
altTitle = altTitle,
|
||||||
|
rating = rating,
|
||||||
|
isNsfw = isNsfw,
|
||||||
|
state = state?.name,
|
||||||
|
title = title,
|
||||||
|
author = author,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun MangaTag.toEntity() = TagEntity(
|
||||||
|
title = title,
|
||||||
|
key = key,
|
||||||
|
source = source.name,
|
||||||
|
id = "${key}_${source.name}".longHashCode()
|
||||||
|
)
|
||||||
|
|
||||||
|
fun Collection<MangaTag>.toEntities() = map(MangaTag::toEntity)
|
||||||
|
|
||||||
|
// Other
|
||||||
|
|
||||||
|
@Suppress("FunctionName")
|
||||||
|
fun SortOrder(name: String, fallback: SortOrder): SortOrder = runCatching {
|
||||||
|
SortOrder.valueOf(name)
|
||||||
|
}.getOrDefault(fallback)
|
||||||
@ -1,14 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions
|
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ResolvableException
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
|
|
||||||
class AuthRequiredException(
|
|
||||||
val source: MangaSource,
|
|
||||||
) : RuntimeException("Authorization required"), ResolvableException {
|
|
||||||
|
|
||||||
@StringRes
|
|
||||||
override val resolveTextId: Int = R.string.sign_in
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions
|
|
||||||
|
|
||||||
import org.json.JSONArray
|
|
||||||
import org.koitharu.kotatsu.utils.ext.map
|
|
||||||
|
|
||||||
class GraphQLException(private val errors: JSONArray) : RuntimeException() {
|
|
||||||
|
|
||||||
val messages = errors.map {
|
|
||||||
it.getString("message")
|
|
||||||
}
|
|
||||||
|
|
||||||
override val message: String
|
|
||||||
get() = messages.joinToString("\n")
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions
|
|
||||||
|
|
||||||
class ParseException(message: String? = null, cause: Throwable? = null) :
|
|
||||||
RuntimeException(message, cause)
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions.resolve
|
|
||||||
|
|
||||||
interface ResolvableException {
|
|
||||||
|
|
||||||
val resolveTextId: Int
|
|
||||||
}
|
|
||||||
@ -1,29 +1,28 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
import android.os.Parcelable
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import kotlinx.parcelize.Parcelize
|
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||||
|
|
||||||
@Parcelize
|
fun Manga.withoutChapters() = if (chapters.isNullOrEmpty()) {
|
||||||
data class Manga(
|
this
|
||||||
val id: Long,
|
} else {
|
||||||
val title: String,
|
Manga(
|
||||||
val altTitle: String? = null,
|
id = id,
|
||||||
val url: String, // relative url for internal use
|
title = title,
|
||||||
val publicUrl: String,
|
altTitle = altTitle,
|
||||||
val rating: Float = NO_RATING, //normalized value [0..1] or -1
|
url = url,
|
||||||
val isNsfw: Boolean = false,
|
publicUrl = publicUrl,
|
||||||
val coverUrl: String,
|
rating = rating,
|
||||||
val largeCoverUrl: String? = null,
|
isNsfw = isNsfw,
|
||||||
val description: String? = null, //HTML
|
coverUrl = coverUrl,
|
||||||
val tags: Set<MangaTag> = emptySet(),
|
tags = tags,
|
||||||
val state: MangaState? = null,
|
state = state,
|
||||||
val author: String? = null,
|
author = author,
|
||||||
val chapters: List<MangaChapter>? = null,
|
largeCoverUrl = largeCoverUrl,
|
||||||
val source: MangaSource
|
description = description,
|
||||||
) : Parcelable {
|
chapters = null,
|
||||||
|
source = source,
|
||||||
companion object {
|
)
|
||||||
|
|
||||||
const val NO_RATING = -1f
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Collection<Manga>.ids() = mapToSet { it.id }
|
||||||
@ -1,21 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
import kotlinx.parcelize.Parcelize
|
|
||||||
|
|
||||||
@Parcelize
|
|
||||||
data class MangaChapter(
|
|
||||||
val id: Long,
|
|
||||||
val name: String,
|
|
||||||
val number: Int,
|
|
||||||
val url: String,
|
|
||||||
val scanlator: String?,
|
|
||||||
val uploadDate: Long,
|
|
||||||
val branch: String?,
|
|
||||||
val source: MangaSource,
|
|
||||||
) : Parcelable, Comparable<MangaChapter> {
|
|
||||||
|
|
||||||
override fun compareTo(other: MangaChapter): Int {
|
|
||||||
return number.compareTo(other.number)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
import kotlinx.parcelize.Parcelize
|
|
||||||
|
|
||||||
@Parcelize
|
|
||||||
data class MangaPage(
|
|
||||||
val id: Long,
|
|
||||||
val url: String,
|
|
||||||
val referer: String,
|
|
||||||
val preview: String?,
|
|
||||||
val source: MangaSource,
|
|
||||||
) : Parcelable
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
import kotlinx.parcelize.Parcelize
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
@Parcelize
|
|
||||||
enum class MangaSource(
|
|
||||||
val title: String,
|
|
||||||
val locale: String?,
|
|
||||||
) : Parcelable {
|
|
||||||
LOCAL("Local", null),
|
|
||||||
READMANGA_RU("ReadManga", "ru"),
|
|
||||||
MINTMANGA("MintManga", "ru"),
|
|
||||||
SELFMANGA("SelfManga", "ru"),
|
|
||||||
MANGACHAN("Манга-тян", "ru"),
|
|
||||||
DESUME("Desu.me", "ru"),
|
|
||||||
HENCHAN("Хентай-тян", "ru"),
|
|
||||||
YAOICHAN("Яой-тян", "ru"),
|
|
||||||
MANGATOWN("MangaTown", "en"),
|
|
||||||
MANGALIB("MangaLib", "ru"),
|
|
||||||
NUDEMOON("Nude-Moon", "ru"),
|
|
||||||
MANGAREAD("MangaRead", "en"),
|
|
||||||
REMANGA("Remanga", "ru"),
|
|
||||||
HENTAILIB("HentaiLib", "ru"),
|
|
||||||
ANIBEL("Anibel", "be"),
|
|
||||||
NINEMANGA_EN("NineManga English", "en"),
|
|
||||||
NINEMANGA_ES("NineManga Español", "es"),
|
|
||||||
NINEMANGA_RU("NineManga Русский", "ru"),
|
|
||||||
NINEMANGA_DE("NineManga Deutsch", "de"),
|
|
||||||
NINEMANGA_IT("NineManga Italiano", "it"),
|
|
||||||
NINEMANGA_BR("NineManga Brasil", "pt"),
|
|
||||||
NINEMANGA_FR("NineManga Français", "fr"),
|
|
||||||
EXHENTAI("ExHentai", null),
|
|
||||||
MANGAOWL("MangaOwl", "en"),
|
|
||||||
MANGADEX("MangaDex", null),
|
|
||||||
BATOTO("Bato.To", null),
|
|
||||||
COMICK_FUN("ComicK", null),
|
|
||||||
;
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
|
||||||
|
|
||||||
enum class MangaState {
|
|
||||||
ONGOING, FINISHED
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
import kotlinx.parcelize.Parcelize
|
|
||||||
|
|
||||||
@Parcelize
|
|
||||||
data class MangaTag(
|
|
||||||
val title: String,
|
|
||||||
val key: String,
|
|
||||||
val source: MangaSource,
|
|
||||||
) : Parcelable
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
|
|
||||||
enum class SortOrder(@StringRes val titleRes: Int) {
|
|
||||||
UPDATED(R.string.updated),
|
|
||||||
POPULARITY(R.string.popular),
|
|
||||||
RATING(R.string.by_rating),
|
|
||||||
NEWEST(R.string.newest),
|
|
||||||
ALPHABETICAL(R.string.by_name)
|
|
||||||
}
|
|
||||||
@ -0,0 +1,95 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model.parcelable
|
||||||
|
|
||||||
|
import android.os.Parcel
|
||||||
|
import androidx.core.os.ParcelCompat
|
||||||
|
import org.koitharu.kotatsu.parsers.model.*
|
||||||
|
|
||||||
|
fun Manga.writeToParcel(out: Parcel, flags: Int, withChapters: Boolean) {
|
||||||
|
out.writeLong(id)
|
||||||
|
out.writeString(title)
|
||||||
|
out.writeString(altTitle)
|
||||||
|
out.writeString(url)
|
||||||
|
out.writeString(publicUrl)
|
||||||
|
out.writeFloat(rating)
|
||||||
|
ParcelCompat.writeBoolean(out, isNsfw)
|
||||||
|
out.writeString(coverUrl)
|
||||||
|
out.writeString(largeCoverUrl)
|
||||||
|
out.writeString(description)
|
||||||
|
out.writeParcelable(ParcelableMangaTags(tags), flags)
|
||||||
|
out.writeSerializable(state)
|
||||||
|
out.writeString(author)
|
||||||
|
if (withChapters) {
|
||||||
|
out.writeParcelable(chapters?.let(::ParcelableMangaChapters), flags)
|
||||||
|
} else {
|
||||||
|
out.writeString(null)
|
||||||
|
}
|
||||||
|
out.writeSerializable(source)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Parcel.readManga() = Manga(
|
||||||
|
id = readLong(),
|
||||||
|
title = requireNotNull(readString()),
|
||||||
|
altTitle = readString(),
|
||||||
|
url = requireNotNull(readString()),
|
||||||
|
publicUrl = requireNotNull(readString()),
|
||||||
|
rating = readFloat(),
|
||||||
|
isNsfw = ParcelCompat.readBoolean(this),
|
||||||
|
coverUrl = requireNotNull(readString()),
|
||||||
|
largeCoverUrl = readString(),
|
||||||
|
description = readString(),
|
||||||
|
tags = requireNotNull(readParcelable<ParcelableMangaTags>(ParcelableMangaTags::class.java.classLoader)).tags,
|
||||||
|
state = readSerializable() as MangaState?,
|
||||||
|
author = readString(),
|
||||||
|
chapters = readParcelable<ParcelableMangaChapters>(ParcelableMangaChapters::class.java.classLoader)?.chapters,
|
||||||
|
source = readSerializable() as MangaSource,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun MangaPage.writeToParcel(out: Parcel) {
|
||||||
|
out.writeLong(id)
|
||||||
|
out.writeString(url)
|
||||||
|
out.writeString(referer)
|
||||||
|
out.writeString(preview)
|
||||||
|
out.writeSerializable(source)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Parcel.readMangaPage() = MangaPage(
|
||||||
|
id = readLong(),
|
||||||
|
url = requireNotNull(readString()),
|
||||||
|
referer = requireNotNull(readString()),
|
||||||
|
preview = readString(),
|
||||||
|
source = readSerializable() as MangaSource,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun MangaChapter.writeToParcel(out: Parcel) {
|
||||||
|
out.writeLong(id)
|
||||||
|
out.writeString(name)
|
||||||
|
out.writeInt(number)
|
||||||
|
out.writeString(url)
|
||||||
|
out.writeString(scanlator)
|
||||||
|
out.writeLong(uploadDate)
|
||||||
|
out.writeString(branch)
|
||||||
|
out.writeSerializable(source)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Parcel.readMangaChapter() = MangaChapter(
|
||||||
|
id = readLong(),
|
||||||
|
name = requireNotNull(readString()),
|
||||||
|
number = readInt(),
|
||||||
|
url = requireNotNull(readString()),
|
||||||
|
scanlator = readString(),
|
||||||
|
uploadDate = readLong(),
|
||||||
|
branch = readString(),
|
||||||
|
source = readSerializable() as MangaSource,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun MangaTag.writeToParcel(out: Parcel) {
|
||||||
|
out.writeString(title)
|
||||||
|
out.writeString(key)
|
||||||
|
out.writeSerializable(source)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Parcel.readMangaTag() = MangaTag(
|
||||||
|
title = requireNotNull(readString()),
|
||||||
|
key = requireNotNull(readString()),
|
||||||
|
source = readSerializable() as MangaSource,
|
||||||
|
)
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model.parcelable
|
||||||
|
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
|
||||||
|
// Limits to avoid TransactionTooLargeException
|
||||||
|
private const val MAX_SAFE_SIZE = 1024 * 512 // Assume that 512 kb is safe parcel size
|
||||||
|
private const val MAX_SAFE_CHAPTERS_COUNT = 40 // this is 100% safe
|
||||||
|
|
||||||
|
class ParcelableManga(
|
||||||
|
val manga: Manga,
|
||||||
|
) : Parcelable {
|
||||||
|
|
||||||
|
constructor(parcel: Parcel) : this(parcel.readManga())
|
||||||
|
|
||||||
|
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||||
|
val chapters = manga.chapters
|
||||||
|
if (chapters == null || chapters.size <= MAX_SAFE_CHAPTERS_COUNT) {
|
||||||
|
// fast path
|
||||||
|
manga.writeToParcel(parcel, flags, withChapters = true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val tempParcel = Parcel.obtain()
|
||||||
|
manga.writeToParcel(tempParcel, flags, withChapters = true)
|
||||||
|
val size = tempParcel.dataSize()
|
||||||
|
if (size < MAX_SAFE_SIZE) {
|
||||||
|
parcel.appendFrom(tempParcel, 0, size)
|
||||||
|
} else {
|
||||||
|
manga.writeToParcel(parcel, flags, withChapters = false)
|
||||||
|
}
|
||||||
|
tempParcel.recycle()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun describeContents(): Int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object CREATOR : Parcelable.Creator<ParcelableManga> {
|
||||||
|
override fun createFromParcel(parcel: Parcel): ParcelableManga {
|
||||||
|
return ParcelableManga(parcel)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<ParcelableManga?> {
|
||||||
|
return arrayOfNulls(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model.parcelable
|
||||||
|
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.utils.ext.createList
|
||||||
|
|
||||||
|
class ParcelableMangaChapters(
|
||||||
|
val chapters: List<MangaChapter>,
|
||||||
|
) : Parcelable {
|
||||||
|
|
||||||
|
constructor(parcel: Parcel) : this(
|
||||||
|
createList(parcel.readInt()) { parcel.readMangaChapter() }
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||||
|
parcel.writeInt(chapters.size)
|
||||||
|
for (chapter in chapters) {
|
||||||
|
chapter.writeToParcel(parcel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun describeContents(): Int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object CREATOR : Parcelable.Creator<ParcelableMangaChapters> {
|
||||||
|
override fun createFromParcel(parcel: Parcel): ParcelableMangaChapters {
|
||||||
|
return ParcelableMangaChapters(parcel)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<ParcelableMangaChapters?> {
|
||||||
|
return arrayOfNulls(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model.parcelable
|
||||||
|
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.createList
|
||||||
|
|
||||||
|
class ParcelableMangaPages(
|
||||||
|
val pages: List<MangaPage>,
|
||||||
|
) : Parcelable {
|
||||||
|
|
||||||
|
constructor(parcel: Parcel) : this(
|
||||||
|
createList(parcel.readInt()) { parcel.readMangaPage() }
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||||
|
parcel.writeInt(pages.size)
|
||||||
|
for (page in pages) {
|
||||||
|
page.writeToParcel(parcel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun describeContents(): Int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object CREATOR : Parcelable.Creator<ParcelableMangaPages> {
|
||||||
|
override fun createFromParcel(parcel: Parcel): ParcelableMangaPages {
|
||||||
|
return ParcelableMangaPages(parcel)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<ParcelableMangaPages?> {
|
||||||
|
return arrayOfNulls(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model.parcelable
|
||||||
|
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.utils.ext.createSet
|
||||||
|
|
||||||
|
class ParcelableMangaTags(
|
||||||
|
val tags: Set<MangaTag>,
|
||||||
|
) : Parcelable {
|
||||||
|
|
||||||
|
constructor(parcel: Parcel) : this(
|
||||||
|
createSet(parcel.readInt()) { parcel.readMangaTag() }
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||||
|
parcel.writeInt(tags.size)
|
||||||
|
for (tag in tags) {
|
||||||
|
tag.writeToParcel(parcel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun describeContents(): Int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object CREATOR : Parcelable.Creator<ParcelableMangaTags> {
|
||||||
|
override fun createFromParcel(parcel: Parcel): ParcelableMangaTags {
|
||||||
|
return ParcelableMangaTags(parcel)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<ParcelableMangaTags?> {
|
||||||
|
return arrayOfNulls(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,56 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.network
|
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import okhttp3.Interceptor
|
|
||||||
import okhttp3.Request
|
|
||||||
import okhttp3.Response
|
|
||||||
import okio.Buffer
|
|
||||||
import java.io.IOException
|
|
||||||
import java.nio.charset.StandardCharsets
|
|
||||||
|
|
||||||
private const val TAG = "CURL"
|
|
||||||
|
|
||||||
class CurlLoggingInterceptor(
|
|
||||||
private val extraCurlOptions: String? = null,
|
|
||||||
) : Interceptor {
|
|
||||||
|
|
||||||
@Throws(IOException::class)
|
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
|
||||||
val request: Request = chain.request()
|
|
||||||
var compressed = false
|
|
||||||
val curlCmd = StringBuilder("curl")
|
|
||||||
if (extraCurlOptions != null) {
|
|
||||||
curlCmd.append(" ").append(extraCurlOptions)
|
|
||||||
}
|
|
||||||
curlCmd.append(" -X ").append(request.method)
|
|
||||||
val headers = request.headers
|
|
||||||
var i = 0
|
|
||||||
val count = headers.size
|
|
||||||
while (i < count) {
|
|
||||||
val name = headers.name(i)
|
|
||||||
val value = headers.value(i)
|
|
||||||
if ("Accept-Encoding".equals(name, ignoreCase = true) && "gzip".equals(value,
|
|
||||||
ignoreCase = true)
|
|
||||||
) {
|
|
||||||
compressed = true
|
|
||||||
}
|
|
||||||
curlCmd.append(" -H " + "\"").append(name).append(": ").append(value).append("\"")
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
val requestBody = request.body
|
|
||||||
if (requestBody != null) {
|
|
||||||
val buffer = Buffer()
|
|
||||||
requestBody.writeTo(buffer)
|
|
||||||
val contentType = requestBody.contentType()
|
|
||||||
val charset = contentType?.charset(StandardCharsets.UTF_8) ?: StandardCharsets.UTF_8
|
|
||||||
curlCmd.append(" --data $'")
|
|
||||||
.append(buffer.readString(charset).replace("\n", "\\n"))
|
|
||||||
.append("'")
|
|
||||||
}
|
|
||||||
curlCmd.append(if (compressed) " --compressed " else " ").append(request.url)
|
|
||||||
Log.d(TAG, "╭--- cURL (" + request.url + ")")
|
|
||||||
Log.d(TAG, curlCmd.toString())
|
|
||||||
Log.d(TAG, "╰--- (copy and paste the above line to a terminal)")
|
|
||||||
return chain.proceed(request)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.Base64
|
||||||
|
import android.webkit.WebView
|
||||||
|
import androidx.core.os.LocaleListCompat
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
||||||
|
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||||
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.parsers.config.MangaSourceConfig
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.utils.ext.toList
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
|
class MangaLoaderContextImpl(
|
||||||
|
override val httpClient: OkHttpClient,
|
||||||
|
override val cookieJar: AndroidCookieJar,
|
||||||
|
private val androidContext: Context,
|
||||||
|
) : MangaLoaderContext() {
|
||||||
|
|
||||||
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
|
override suspend fun evaluateJs(script: String): String? = withContext(Dispatchers.Main) {
|
||||||
|
val webView = WebView(androidContext)
|
||||||
|
webView.settings.javaScriptEnabled = true
|
||||||
|
suspendCoroutine { cont ->
|
||||||
|
webView.evaluateJavascript(script) { result ->
|
||||||
|
cont.resume(result?.takeUnless { it == "null" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getConfig(source: MangaSource): MangaSourceConfig {
|
||||||
|
return SourceSettings(androidContext, source)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun encodeBase64(data: ByteArray): String {
|
||||||
|
return Base64.encodeToString(data, Base64.NO_PADDING)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decodeBase64(data: String): ByteArray {
|
||||||
|
return Base64.decode(data, Base64.DEFAULT)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getPreferredLocales(): List<Locale> {
|
||||||
|
return LocaleListCompat.getAdjustedDefault().toList()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
|
||||||
|
|
||||||
interface MangaRepositoryAuthProvider {
|
|
||||||
|
|
||||||
val authUrl: String
|
|
||||||
|
|
||||||
fun isAuthorized(): Boolean
|
|
||||||
|
|
||||||
suspend fun getUsername(): String
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
|
||||||
|
|
||||||
import org.koin.core.qualifier.named
|
|
||||||
import org.koin.dsl.module
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
import org.koitharu.kotatsu.core.parser.site.*
|
|
||||||
|
|
||||||
val parserModule
|
|
||||||
get() = module {
|
|
||||||
|
|
||||||
factory<MangaRepository>(named(MangaSource.READMANGA_RU)) { ReadmangaRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.MINTMANGA)) { MintMangaRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.SELFMANGA)) { SelfMangaRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.MANGACHAN)) { MangaChanRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.DESUME)) { DesuMeRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.HENCHAN)) { HenChanRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.YAOICHAN)) { YaoiChanRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.MANGATOWN)) { MangaTownRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.MANGALIB)) { MangaLibRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.NUDEMOON)) { NudeMoonRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.MANGAREAD)) { MangareadRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.REMANGA)) { RemangaRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.HENTAILIB)) { HentaiLibRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.ANIBEL)) { AnibelRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.NINEMANGA_EN)) { NineMangaRepository.English(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.NINEMANGA_BR)) { NineMangaRepository.Brazil(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.NINEMANGA_DE)) { NineMangaRepository.Deutsch(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.NINEMANGA_ES)) { NineMangaRepository.Spanish(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.NINEMANGA_RU)) { NineMangaRepository.Russian(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.NINEMANGA_IT)) { NineMangaRepository.Italiano(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.NINEMANGA_FR)) { NineMangaRepository.Francais(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.EXHENTAI)) { ExHentaiRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.MANGAOWL)) { MangaOwlRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.MANGADEX)) { MangaDexRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.BATOTO)) { BatoToRepository(get()) }
|
|
||||||
factory<MangaRepository>(named(MangaSource.COMICK_FUN)) { ComickFunRepository(get()) }
|
|
||||||
}
|
|
||||||
@ -1,84 +1,51 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaPage
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaTag
|
|
||||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||||
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
abstract class RemoteMangaRepository(
|
import org.koitharu.kotatsu.parsers.MangaParser
|
||||||
protected val loaderContext: MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaParserAuthProvider
|
||||||
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||||
|
import org.koitharu.kotatsu.parsers.model.*
|
||||||
|
import org.koitharu.kotatsu.parsers.newParser
|
||||||
|
|
||||||
|
class RemoteMangaRepository(
|
||||||
|
override val source: MangaSource,
|
||||||
|
loaderContext: MangaLoaderContext,
|
||||||
) : MangaRepository {
|
) : MangaRepository {
|
||||||
|
|
||||||
protected abstract val defaultDomain: String
|
private val parser: MangaParser = source.newParser(loaderContext)
|
||||||
|
|
||||||
private val conf by lazy {
|
override val sortOrders: Set<SortOrder>
|
||||||
loaderContext.getSettings(source)
|
get() = parser.sortOrders
|
||||||
}
|
|
||||||
|
|
||||||
val title: String
|
var defaultSortOrder: SortOrder?
|
||||||
get() = source.title
|
get() = getConfig().defaultSortOrder ?: sortOrders.firstOrNull()
|
||||||
|
set(value) {
|
||||||
|
getConfig().defaultSortOrder = value
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getPageUrl(page: MangaPage): String = page.url.withDomain()
|
override suspend fun getList(
|
||||||
|
offset: Int,
|
||||||
|
query: String?,
|
||||||
|
tags: Set<MangaTag>?,
|
||||||
|
sortOrder: SortOrder?
|
||||||
|
): List<Manga> = parser.getList(offset, query, tags, sortOrder)
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> = emptySet()
|
override suspend fun getDetails(manga: Manga): Manga = parser.getDetails(manga)
|
||||||
|
|
||||||
open fun getFaviconUrl() = "https://${getDomain()}/favicon.ico"
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> = parser.getPages(chapter)
|
||||||
|
|
||||||
open fun onCreatePreferences(map: MutableMap<String, Any>) {
|
override suspend fun getPageUrl(page: MangaPage): String = parser.getPageUrl(page)
|
||||||
map[SourceSettings.KEY_DOMAIN] = defaultDomain
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun getDomain() = conf.getDomain(defaultDomain)
|
override suspend fun getTags(): Set<MangaTag> = parser.getTags()
|
||||||
|
|
||||||
protected fun String.withDomain(subdomain: String? = null) = when {
|
fun getFaviconUrl(): String = parser.getFaviconUrl()
|
||||||
this.startsWith("//") -> buildString {
|
|
||||||
append("http")
|
|
||||||
if (conf.isUseSsl(true)) {
|
|
||||||
append('s')
|
|
||||||
}
|
|
||||||
append(":")
|
|
||||||
append(this@withDomain)
|
|
||||||
}
|
|
||||||
this.startsWith("/") -> buildString {
|
|
||||||
append("http")
|
|
||||||
if (conf.isUseSsl(true)) {
|
|
||||||
append('s')
|
|
||||||
}
|
|
||||||
append("://")
|
|
||||||
if (subdomain != null) {
|
|
||||||
append(subdomain)
|
|
||||||
append('.')
|
|
||||||
append(conf.getDomain(defaultDomain).removePrefix("www."))
|
|
||||||
} else {
|
|
||||||
append(conf.getDomain(defaultDomain))
|
|
||||||
}
|
|
||||||
append(this@withDomain)
|
|
||||||
}
|
|
||||||
else -> this
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun generateUid(url: String): Long {
|
fun getAuthProvider(): MangaParserAuthProvider? = parser as? MangaParserAuthProvider
|
||||||
var h = 1125899906842597L
|
|
||||||
source.name.forEach { c ->
|
|
||||||
h = 31 * h + c.code
|
|
||||||
}
|
|
||||||
url.forEach { c ->
|
|
||||||
h = 31 * h + c.code
|
|
||||||
}
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun generateUid(id: Long): Long {
|
fun getConfigKeys(): List<ConfigKey<*>> = ArrayList<ConfigKey<*>>().also {
|
||||||
var h = 1125899906842597L
|
parser.onCreateConfig(it)
|
||||||
source.name.forEach { c ->
|
|
||||||
h = 31 * h + c.code
|
|
||||||
}
|
|
||||||
h = 31 * h + id
|
|
||||||
return h
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun parseFailed(message: String? = null): Nothing {
|
private fun getConfig() = parser.config as SourceSettings
|
||||||
throw ParseException(message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,262 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import androidx.collection.ArraySet
|
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.map
|
|
||||||
import org.koitharu.kotatsu.utils.ext.mapIndexed
|
|
||||||
import org.koitharu.kotatsu.utils.ext.stringIterator
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class AnibelRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val source = MangaSource.ANIBEL
|
|
||||||
|
|
||||||
override val defaultDomain = "anibel.net"
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.NEWEST
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun getFaviconUrl(): String {
|
|
||||||
return "https://cdn.${getDomain()}/favicons/favicon.png"
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?,
|
|
||||||
): List<Manga> {
|
|
||||||
if (!query.isNullOrEmpty()) {
|
|
||||||
return if (offset == 0) {
|
|
||||||
search(query)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val filters = tags?.takeUnless { it.isEmpty() }?.joinToString(
|
|
||||||
separator = ",",
|
|
||||||
prefix = "genres: [",
|
|
||||||
postfix = "]"
|
|
||||||
) { "\"it.key\"" }.orEmpty()
|
|
||||||
val array = apiCall(
|
|
||||||
"""
|
|
||||||
getMediaList(offset: $offset, limit: 20, mediaType: manga, filters: {$filters}) {
|
|
||||||
docs {
|
|
||||||
mediaId
|
|
||||||
title {
|
|
||||||
be
|
|
||||||
alt
|
|
||||||
}
|
|
||||||
rating
|
|
||||||
poster
|
|
||||||
genres
|
|
||||||
slug
|
|
||||||
mediaType
|
|
||||||
status
|
|
||||||
}
|
|
||||||
}
|
|
||||||
""".trimIndent()
|
|
||||||
).getJSONObject("getMediaList").getJSONArray("docs")
|
|
||||||
return array.map { jo ->
|
|
||||||
val mediaId = jo.getString("mediaId")
|
|
||||||
val title = jo.getJSONObject("title")
|
|
||||||
val href = "${jo.getString("mediaType")}/${jo.getString("slug")}"
|
|
||||||
Manga(
|
|
||||||
id = generateUid(mediaId),
|
|
||||||
title = title.getString("be"),
|
|
||||||
coverUrl = jo.getString("poster").removePrefix("/cdn")
|
|
||||||
.withDomain("cdn") + "?width=200&height=280",
|
|
||||||
altTitle = title.getString("alt").takeUnless(String::isEmpty),
|
|
||||||
author = null,
|
|
||||||
rating = jo.getDouble("rating").toFloat() / 10f,
|
|
||||||
url = href,
|
|
||||||
publicUrl = "https://${getDomain()}/${href}",
|
|
||||||
tags = jo.getJSONArray("genres").mapToTags(),
|
|
||||||
state = when (jo.getString("status")) {
|
|
||||||
"ongoing" -> MangaState.ONGOING
|
|
||||||
"finished" -> MangaState.FINISHED
|
|
||||||
else -> null
|
|
||||||
},
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val (type, slug) = manga.url.split('/')
|
|
||||||
val details = apiCall(
|
|
||||||
"""
|
|
||||||
media(mediaType: $type, slug: "$slug") {
|
|
||||||
mediaId
|
|
||||||
title {
|
|
||||||
be
|
|
||||||
alt
|
|
||||||
}
|
|
||||||
description {
|
|
||||||
be
|
|
||||||
}
|
|
||||||
status
|
|
||||||
poster
|
|
||||||
rating
|
|
||||||
genres
|
|
||||||
}
|
|
||||||
""".trimIndent()
|
|
||||||
).getJSONObject("media")
|
|
||||||
val title = details.getJSONObject("title")
|
|
||||||
val poster = details.getString("poster").removePrefix("/cdn")
|
|
||||||
.withDomain("cdn")
|
|
||||||
val chapters = apiCall(
|
|
||||||
"""
|
|
||||||
chapters(mediaId: "${details.getString("mediaId")}") {
|
|
||||||
id
|
|
||||||
chapter
|
|
||||||
released
|
|
||||||
}
|
|
||||||
""".trimIndent()
|
|
||||||
).getJSONArray("chapters")
|
|
||||||
return manga.copy(
|
|
||||||
title = title.getString("be"),
|
|
||||||
altTitle = title.getString("alt"),
|
|
||||||
coverUrl = "$poster?width=200&height=280",
|
|
||||||
largeCoverUrl = poster,
|
|
||||||
description = details.getJSONObject("description").getString("be"),
|
|
||||||
rating = details.getDouble("rating").toFloat() / 10f,
|
|
||||||
tags = details.getJSONArray("genres").mapToTags(),
|
|
||||||
state = when (details.getString("status")) {
|
|
||||||
"ongoing" -> MangaState.ONGOING
|
|
||||||
"finished" -> MangaState.FINISHED
|
|
||||||
else -> null
|
|
||||||
},
|
|
||||||
chapters = chapters.map { jo ->
|
|
||||||
val number = jo.getInt("chapter")
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(jo.getString("id")),
|
|
||||||
name = "Глава $number",
|
|
||||||
number = number,
|
|
||||||
url = "${manga.url}/read/$number",
|
|
||||||
scanlator = null,
|
|
||||||
uploadDate = jo.getLong("released"),
|
|
||||||
branch = null,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val (_, slug, _, number) = chapter.url.split('/')
|
|
||||||
val chapterJson = apiCall(
|
|
||||||
"""
|
|
||||||
chapter(slug: "$slug", chapter: $number) {
|
|
||||||
id
|
|
||||||
images {
|
|
||||||
large
|
|
||||||
thumbnail
|
|
||||||
}
|
|
||||||
}
|
|
||||||
""".trimIndent()
|
|
||||||
).getJSONObject("chapter")
|
|
||||||
val pages = chapterJson.getJSONArray("images")
|
|
||||||
val chapterUrl = "https://${getDomain()}/${chapter.url}"
|
|
||||||
return pages.mapIndexed { i, jo ->
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid("${chapter.url}/$i"),
|
|
||||||
url = jo.getString("large"),
|
|
||||||
referer = chapterUrl,
|
|
||||||
preview = jo.getString("thumbnail"),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val json = apiCall(
|
|
||||||
"""
|
|
||||||
getFilters(mediaType: manga) {
|
|
||||||
genres
|
|
||||||
}
|
|
||||||
""".trimIndent()
|
|
||||||
)
|
|
||||||
val array = json.getJSONObject("getFilters").getJSONArray("genres")
|
|
||||||
return array.mapToTags()
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun search(query: String): List<Manga> {
|
|
||||||
val json = apiCall(
|
|
||||||
"""
|
|
||||||
search(query: "$query", limit: 40) {
|
|
||||||
id
|
|
||||||
title {
|
|
||||||
be
|
|
||||||
en
|
|
||||||
}
|
|
||||||
poster
|
|
||||||
url
|
|
||||||
type
|
|
||||||
}
|
|
||||||
""".trimIndent()
|
|
||||||
)
|
|
||||||
val array = json.getJSONArray("search")
|
|
||||||
return array.map { jo ->
|
|
||||||
val mediaId = jo.getString("id")
|
|
||||||
val title = jo.getJSONObject("title")
|
|
||||||
val href = "${jo.getString("type").lowercase()}/${jo.getString("url")}"
|
|
||||||
Manga(
|
|
||||||
id = generateUid(mediaId),
|
|
||||||
title = title.getString("be"),
|
|
||||||
coverUrl = jo.getString("poster").removePrefix("/cdn")
|
|
||||||
.withDomain("cdn") + "?width=200&height=280",
|
|
||||||
altTitle = title.getString("en").takeUnless(String::isEmpty),
|
|
||||||
author = null,
|
|
||||||
rating = Manga.NO_RATING,
|
|
||||||
url = href,
|
|
||||||
publicUrl = "https://${getDomain()}/${href}",
|
|
||||||
tags = emptySet(),
|
|
||||||
state = null,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun apiCall(request: String): JSONObject {
|
|
||||||
return loaderContext.graphQLQuery("https://api.${getDomain()}/graphql", request)
|
|
||||||
.getJSONObject("data")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun JSONArray.mapToTags(): Set<MangaTag> {
|
|
||||||
|
|
||||||
fun toTitle(slug: String): String {
|
|
||||||
val builder = StringBuilder(slug)
|
|
||||||
var capitalize = true
|
|
||||||
for ((i, c) in builder.withIndex()) {
|
|
||||||
when {
|
|
||||||
c == '-' -> {
|
|
||||||
builder.setCharAt(i, ' ')
|
|
||||||
}
|
|
||||||
capitalize -> {
|
|
||||||
builder.setCharAt(i, c.uppercaseChar())
|
|
||||||
capitalize = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
val result = ArraySet<MangaTag>(length())
|
|
||||||
stringIterator().forEach {
|
|
||||||
result.add(
|
|
||||||
MangaTag(
|
|
||||||
title = toTitle(it),
|
|
||||||
key = it,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,307 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import android.util.Base64
|
|
||||||
import androidx.collection.ArraySet
|
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.jsoup.nodes.Element
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.nio.charset.StandardCharsets
|
|
||||||
import java.security.MessageDigest
|
|
||||||
import java.util.*
|
|
||||||
import javax.crypto.Cipher
|
|
||||||
import javax.crypto.spec.IvParameterSpec
|
|
||||||
import javax.crypto.spec.SecretKeySpec
|
|
||||||
|
|
||||||
private const val PAGE_SIZE = 60
|
|
||||||
private const val PAGE_SIZE_SEARCH = 20
|
|
||||||
|
|
||||||
class BatoToRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val source = MangaSource.BATOTO
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.NEWEST,
|
|
||||||
SortOrder.UPDATED,
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
SortOrder.ALPHABETICAL
|
|
||||||
)
|
|
||||||
|
|
||||||
override val defaultDomain: String = "bato.to"
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
if (!query.isNullOrEmpty()) {
|
|
||||||
return search(offset, query)
|
|
||||||
}
|
|
||||||
val page = (offset / PAGE_SIZE) + 1
|
|
||||||
|
|
||||||
@Suppress("NON_EXHAUSTIVE_WHEN_STATEMENT")
|
|
||||||
val url = buildString {
|
|
||||||
append("https://")
|
|
||||||
append(getDomain())
|
|
||||||
append("/browse?sort=")
|
|
||||||
when (sortOrder) {
|
|
||||||
null,
|
|
||||||
SortOrder.UPDATED -> append("update.za")
|
|
||||||
SortOrder.POPULARITY -> append("views_a.za")
|
|
||||||
SortOrder.NEWEST -> append("create.za")
|
|
||||||
SortOrder.ALPHABETICAL -> append("title.az")
|
|
||||||
}
|
|
||||||
if (!tags.isNullOrEmpty()) {
|
|
||||||
append("&genres=")
|
|
||||||
appendAll(tags, ",") { it.key }
|
|
||||||
}
|
|
||||||
append("&page=")
|
|
||||||
append(page)
|
|
||||||
}
|
|
||||||
return parseList(url, page)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val root = loaderContext.httpGet(manga.url.withDomain()).parseHtml()
|
|
||||||
.getElementById("mainer") ?: parseFailed("Cannot find root")
|
|
||||||
val details = root.selectFirst(".detail-set") ?: parseFailed("Cannot find detail-set")
|
|
||||||
val attrs = details.selectFirst(".attr-main")?.select(".attr-item")?.associate {
|
|
||||||
it.child(0).text().trim() to it.child(1)
|
|
||||||
}.orEmpty()
|
|
||||||
return manga.copy(
|
|
||||||
title = root.selectFirst("h3.item-title")?.text() ?: manga.title,
|
|
||||||
isNsfw = !root.selectFirst("alert")?.getElementsContainingOwnText("NSFW").isNullOrEmpty(),
|
|
||||||
largeCoverUrl = details.selectFirst("img[src]")?.absUrl("src"),
|
|
||||||
description = details.getElementById("limit-height-body-summary")
|
|
||||||
?.selectFirst(".limit-html")
|
|
||||||
?.html(),
|
|
||||||
tags = manga.tags + attrs["Genres:"]?.parseTags().orEmpty(),
|
|
||||||
state = when (attrs["Release status:"]?.text()) {
|
|
||||||
"Ongoing" -> MangaState.ONGOING
|
|
||||||
"Completed" -> MangaState.FINISHED
|
|
||||||
else -> manga.state
|
|
||||||
},
|
|
||||||
author = attrs["Authors:"]?.text()?.trim() ?: manga.author,
|
|
||||||
chapters = root.selectFirst(".episode-list")
|
|
||||||
?.selectFirst(".main")
|
|
||||||
?.children()
|
|
||||||
?.reversed()
|
|
||||||
?.mapIndexedNotNull { i, div ->
|
|
||||||
div.parseChapter(i)
|
|
||||||
}.orEmpty()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val fullUrl = chapter.url.withDomain()
|
|
||||||
val scripts = loaderContext.httpGet(fullUrl).parseHtml().select("script")
|
|
||||||
for (script in scripts) {
|
|
||||||
val scriptSrc = script.html()
|
|
||||||
val p = scriptSrc.indexOf("const images =")
|
|
||||||
if (p == -1) continue
|
|
||||||
val start = scriptSrc.indexOf('[', p)
|
|
||||||
val end = scriptSrc.indexOf(';', start)
|
|
||||||
if (start == -1 || end == -1) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val images = JSONArray(scriptSrc.substring(start, end))
|
|
||||||
val batoJs = scriptSrc.substringBetweenFirst("batojs =", ";")?.trim(' ', '"', '\n')
|
|
||||||
?: parseFailed("Cannot find batojs")
|
|
||||||
val server = scriptSrc.substringBetweenFirst("server =", ";")?.trim(' ', '"', '\n')
|
|
||||||
?: parseFailed("Cannot find server")
|
|
||||||
val password = loaderContext.evaluateJs(batoJs)?.removeSurrounding('"')
|
|
||||||
?: parseFailed("Cannot evaluate batojs")
|
|
||||||
val serverDecrypted = decryptAES(server, password).removeSurrounding('"')
|
|
||||||
val result = ArrayList<MangaPage>(images.length())
|
|
||||||
repeat(images.length()) { i ->
|
|
||||||
val url = images.getString(i)
|
|
||||||
result += MangaPage(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = if (url.startsWith("http")) url else "$serverDecrypted$url",
|
|
||||||
referer = fullUrl,
|
|
||||||
preview = null,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
parseFailed("Cannot find images list")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val scripts = loaderContext.httpGet(
|
|
||||||
"https://${getDomain()}/browse"
|
|
||||||
).parseHtml().select("script")
|
|
||||||
for (script in scripts) {
|
|
||||||
val genres = script.html().substringBetweenFirst("const _genres =", ";") ?: continue
|
|
||||||
val jo = JSONObject(genres)
|
|
||||||
val result = ArraySet<MangaTag>(jo.length())
|
|
||||||
jo.keys().forEach { key ->
|
|
||||||
val item = jo.getJSONObject(key)
|
|
||||||
result += MangaTag(
|
|
||||||
title = item.getString("text").toTitleCase(),
|
|
||||||
key = item.getString("file"),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
parseFailed("Cannot find gernes list")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getFaviconUrl(): String = "https://styles.amarkcdn.com/img/batoto/favicon.ico?v0"
|
|
||||||
|
|
||||||
private suspend fun search(offset: Int, query: String): List<Manga> {
|
|
||||||
val page = (offset / PAGE_SIZE_SEARCH) + 1
|
|
||||||
val url = buildString {
|
|
||||||
append("https://")
|
|
||||||
append(getDomain())
|
|
||||||
append("/search?word=")
|
|
||||||
append(query.replace(' ', '+'))
|
|
||||||
append("&page=")
|
|
||||||
append(page)
|
|
||||||
}
|
|
||||||
return parseList(url, page)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getActivePage(body: Element): Int = body.select("nav ul.pagination > li.page-item.active")
|
|
||||||
.lastOrNull()
|
|
||||||
?.text()
|
|
||||||
?.toIntOrNull() ?: parseFailed("Cannot determine current page")
|
|
||||||
|
|
||||||
private suspend fun parseList(url: String, page: Int): List<Manga> {
|
|
||||||
val body = loaderContext.httpGet(url).parseHtml().body()
|
|
||||||
if (body.selectFirst(".browse-no-matches") != null) {
|
|
||||||
return emptyList()
|
|
||||||
}
|
|
||||||
val activePage = getActivePage(body)
|
|
||||||
if (activePage != page) {
|
|
||||||
return emptyList()
|
|
||||||
}
|
|
||||||
val root = body.getElementById("series-list") ?: parseFailed("Cannot find root")
|
|
||||||
return root.children().map { div ->
|
|
||||||
val a = div.selectFirst("a") ?: parseFailed()
|
|
||||||
val href = a.relUrl("href")
|
|
||||||
val title = div.selectFirst(".item-title")?.text() ?: parseFailed("Title not found")
|
|
||||||
Manga(
|
|
||||||
id = generateUid(href),
|
|
||||||
title = title,
|
|
||||||
altTitle = div.selectFirst(".item-alias")?.text()?.takeUnless { it == title },
|
|
||||||
url = href,
|
|
||||||
publicUrl = a.absUrl("href"),
|
|
||||||
rating = Manga.NO_RATING,
|
|
||||||
isNsfw = false,
|
|
||||||
coverUrl = div.selectFirst("img[src]")?.absUrl("src").orEmpty(),
|
|
||||||
largeCoverUrl = null,
|
|
||||||
description = null,
|
|
||||||
tags = div.selectFirst(".item-genre")?.parseTags().orEmpty(),
|
|
||||||
state = null,
|
|
||||||
author = null,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Element.parseTags() = children().mapToSet { span ->
|
|
||||||
val text = span.ownText()
|
|
||||||
MangaTag(
|
|
||||||
title = text.toTitleCase(),
|
|
||||||
key = text.lowercase(Locale.ENGLISH).replace(' ', '_'),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Element.parseChapter(index: Int): MangaChapter? {
|
|
||||||
val a = selectFirst("a.chapt") ?: return null
|
|
||||||
val extra = selectFirst(".extra")
|
|
||||||
val href = a.relUrl("href")
|
|
||||||
return MangaChapter(
|
|
||||||
id = generateUid(href),
|
|
||||||
name = a.text(),
|
|
||||||
number = index + 1,
|
|
||||||
url = href,
|
|
||||||
scanlator = extra?.getElementsByAttributeValueContaining("href", "/group/")?.text(),
|
|
||||||
uploadDate = runCatching {
|
|
||||||
parseChapterDate(extra?.select("i")?.lastOrNull()?.ownText())
|
|
||||||
}.getOrDefault(0),
|
|
||||||
branch = null,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseChapterDate(date: String?): Long {
|
|
||||||
if (date.isNullOrEmpty()) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
val value = date.substringBefore(' ').toInt()
|
|
||||||
val field = when {
|
|
||||||
"sec" in date -> Calendar.SECOND
|
|
||||||
"min" in date -> Calendar.MINUTE
|
|
||||||
"hour" in date -> Calendar.HOUR
|
|
||||||
"day" in date -> Calendar.DAY_OF_MONTH
|
|
||||||
"week" in date -> Calendar.WEEK_OF_YEAR
|
|
||||||
"month" in date -> Calendar.MONTH
|
|
||||||
"year" in date -> Calendar.YEAR
|
|
||||||
else -> return 0
|
|
||||||
}
|
|
||||||
val calendar = Calendar.getInstance()
|
|
||||||
calendar.add(field, -value)
|
|
||||||
return calendar.timeInMillis
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun decryptAES(encrypted: String, password: String): String {
|
|
||||||
val cipherData = Base64.decode(encrypted, Base64.DEFAULT)
|
|
||||||
val saltData = cipherData.copyOfRange(8, 16)
|
|
||||||
val (key, iv) = generateKeyAndIV(
|
|
||||||
keyLength = 32,
|
|
||||||
ivLength = 16,
|
|
||||||
iterations = 1,
|
|
||||||
salt = saltData,
|
|
||||||
password = password.toByteArray(StandardCharsets.UTF_8),
|
|
||||||
md = MessageDigest.getInstance("MD5"),
|
|
||||||
)
|
|
||||||
val encryptedData = cipherData.copyOfRange(16, cipherData.size)
|
|
||||||
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, key, iv)
|
|
||||||
return cipher.doFinal(encryptedData).toString(Charsets.UTF_8)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("SameParameterValue")
|
|
||||||
private fun generateKeyAndIV(
|
|
||||||
keyLength: Int,
|
|
||||||
ivLength: Int,
|
|
||||||
iterations: Int,
|
|
||||||
salt: ByteArray,
|
|
||||||
password: ByteArray,
|
|
||||||
md: MessageDigest,
|
|
||||||
): Pair<SecretKeySpec, IvParameterSpec> {
|
|
||||||
val digestLength = md.digestLength
|
|
||||||
val requiredLength = (keyLength + ivLength + digestLength - 1) / digestLength * digestLength
|
|
||||||
val generatedData = ByteArray(requiredLength)
|
|
||||||
var generatedLength = 0
|
|
||||||
md.reset()
|
|
||||||
while (generatedLength < keyLength + ivLength) {
|
|
||||||
if (generatedLength > 0) {
|
|
||||||
md.update(generatedData, generatedLength - digestLength, digestLength)
|
|
||||||
}
|
|
||||||
md.update(password)
|
|
||||||
md.update(salt, 0, 8)
|
|
||||||
md.digest(generatedData, generatedLength, digestLength)
|
|
||||||
repeat(iterations - 1) {
|
|
||||||
md.update(generatedData, generatedLength, digestLength)
|
|
||||||
md.digest(generatedData, generatedLength, digestLength)
|
|
||||||
}
|
|
||||||
generatedLength += digestLength
|
|
||||||
}
|
|
||||||
|
|
||||||
return SecretKeySpec(generatedData.copyOfRange(0, keyLength), "AES") to IvParameterSpec(
|
|
||||||
if (ivLength > 0) {
|
|
||||||
generatedData.copyOfRange(keyLength, keyLength + ivLength)
|
|
||||||
} else byteArrayOf()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,163 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
abstract class ChanRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(
|
|
||||||
loaderContext
|
|
||||||
) {
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.NEWEST,
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
SortOrder.ALPHABETICAL
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val url = when {
|
|
||||||
!query.isNullOrEmpty() -> {
|
|
||||||
if (offset != 0) {
|
|
||||||
return emptyList()
|
|
||||||
}
|
|
||||||
"https://$domain/?do=search&subaction=search&story=${query.urlEncoded()}"
|
|
||||||
}
|
|
||||||
!tags.isNullOrEmpty() -> tags.joinToString(
|
|
||||||
prefix = "https://$domain/tags/",
|
|
||||||
postfix = "&n=${getSortKey2(sortOrder)}?offset=$offset",
|
|
||||||
separator = "+",
|
|
||||||
) { tag -> tag.key }
|
|
||||||
else -> "https://$domain/${getSortKey(sortOrder)}?offset=$offset"
|
|
||||||
}
|
|
||||||
val doc = loaderContext.httpGet(url).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("div.main_fon")?.getElementById("content")
|
|
||||||
?: throw ParseException("Cannot find root")
|
|
||||||
return root.select("div.content_row").mapNotNull { row ->
|
|
||||||
val a = row.selectFirst("div.manga_row1")?.selectFirst("h2")?.selectFirst("a")
|
|
||||||
?: return@mapNotNull null
|
|
||||||
val href = a.relUrl("href")
|
|
||||||
Manga(
|
|
||||||
id = generateUid(href),
|
|
||||||
url = href,
|
|
||||||
publicUrl = href.inContextOf(a),
|
|
||||||
altTitle = a.attr("title"),
|
|
||||||
title = a.text().substringAfterLast('(').substringBeforeLast(')'),
|
|
||||||
author = row.getElementsByAttributeValueStarting(
|
|
||||||
"href",
|
|
||||||
"/mangaka"
|
|
||||||
).firstOrNull()?.text(),
|
|
||||||
coverUrl = row.selectFirst("div.manga_images")?.selectFirst("img")
|
|
||||||
?.absUrl("src").orEmpty(),
|
|
||||||
tags = runCatching {
|
|
||||||
row.selectFirst("div.genre")?.select("a")?.mapToSet {
|
|
||||||
MangaTag(
|
|
||||||
title = it.text().toTagName(),
|
|
||||||
key = it.attr("href").substringAfterLast('/').urlEncoded(),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}.getOrNull().orEmpty(),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val doc = loaderContext.httpGet(manga.url.withDomain()).parseHtml()
|
|
||||||
val root =
|
|
||||||
doc.body().getElementById("dle-content") ?: throw ParseException("Cannot find root")
|
|
||||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.US)
|
|
||||||
return manga.copy(
|
|
||||||
description = root.getElementById("description")?.html()?.substringBeforeLast("<div"),
|
|
||||||
largeCoverUrl = root.getElementById("cover")?.absUrl("src"),
|
|
||||||
chapters = root.select("table.table_cha tr:gt(1)").reversed().mapIndexedNotNull { i, tr ->
|
|
||||||
val href = tr?.selectFirst("a")?.relUrl("href") ?: return@mapIndexedNotNull null
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(href),
|
|
||||||
name = tr.selectFirst("a")?.text().orEmpty(),
|
|
||||||
number = i + 1,
|
|
||||||
url = href,
|
|
||||||
scanlator = null,
|
|
||||||
branch = null,
|
|
||||||
uploadDate = dateFormat.tryParse(tr.selectFirst("div.date")?.text()),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val fullUrl = chapter.url.withDomain()
|
|
||||||
val doc = loaderContext.httpGet(fullUrl).parseHtml()
|
|
||||||
val scripts = doc.select("script")
|
|
||||||
for (script in scripts) {
|
|
||||||
val data = script.html()
|
|
||||||
val pos = data.indexOf("\"fullimg")
|
|
||||||
if (pos == -1) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val json = data.substring(pos).substringAfter('[').substringBefore(';')
|
|
||||||
.substringBeforeLast(']')
|
|
||||||
val domain = getDomain()
|
|
||||||
return json.split(",").mapNotNull {
|
|
||||||
it.trim()
|
|
||||||
.removeSurrounding('"', '\'')
|
|
||||||
.toRelativeUrl(domain)
|
|
||||||
.takeUnless(String::isBlank)
|
|
||||||
}.map { url ->
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = url,
|
|
||||||
preview = null,
|
|
||||||
referer = fullUrl,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw ParseException("Pages list not found at ${chapter.url}")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val doc = loaderContext.httpGet("https://$domain/catalog").parseHtml()
|
|
||||||
val root = doc.body().selectFirst("div.main_fon")?.getElementById("side")
|
|
||||||
?.select("ul")?.last() ?: throw ParseException("Cannot find root")
|
|
||||||
return root.select("li.sidetag").mapToSet { li ->
|
|
||||||
val a = li.children().last() ?: throw ParseException("a is null")
|
|
||||||
MangaTag(
|
|
||||||
title = a.text().toTagName(),
|
|
||||||
key = a.attr("href").substringAfterLast('/'),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSortKey(sortOrder: SortOrder?) =
|
|
||||||
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {
|
|
||||||
SortOrder.ALPHABETICAL -> "catalog"
|
|
||||||
SortOrder.POPULARITY -> "mostfavorites"
|
|
||||||
SortOrder.NEWEST -> "manga/new"
|
|
||||||
else -> "mostfavorites"
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSortKey2(sortOrder: SortOrder?) =
|
|
||||||
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {
|
|
||||||
SortOrder.ALPHABETICAL -> "abcasc"
|
|
||||||
SortOrder.POPULARITY -> "favdesc"
|
|
||||||
SortOrder.NEWEST -> "datedesc"
|
|
||||||
else -> "favdesc"
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun String.toTagName() = replace('_', ' ').toTitleCase()
|
|
||||||
}
|
|
||||||
@ -1,212 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import android.util.SparseArray
|
|
||||||
import androidx.collection.ArraySet
|
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://api.comick.fun/docs/static/index.html
|
|
||||||
*/
|
|
||||||
|
|
||||||
private const val PAGE_SIZE = 20
|
|
||||||
private const val CHAPTERS_LIMIT = 99999
|
|
||||||
|
|
||||||
class ComickFunRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val defaultDomain = "comick.fun"
|
|
||||||
override val source = MangaSource.COMICK_FUN
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
SortOrder.UPDATED,
|
|
||||||
SortOrder.RATING,
|
|
||||||
)
|
|
||||||
|
|
||||||
@Volatile
|
|
||||||
private var cachedTags: SparseArray<MangaTag>? = null
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val url = buildString {
|
|
||||||
append("https://api.")
|
|
||||||
append(domain)
|
|
||||||
append("/search?tachiyomi=true")
|
|
||||||
if (!query.isNullOrEmpty()) {
|
|
||||||
if (offset > 0) {
|
|
||||||
return emptyList()
|
|
||||||
}
|
|
||||||
append("&q=")
|
|
||||||
append(query.urlEncoded())
|
|
||||||
} else {
|
|
||||||
append("&limit=")
|
|
||||||
append(PAGE_SIZE)
|
|
||||||
append("&page=")
|
|
||||||
append((offset / PAGE_SIZE) + 1)
|
|
||||||
if (!tags.isNullOrEmpty()) {
|
|
||||||
append("&genres=")
|
|
||||||
appendAll(tags, "&genres=", MangaTag::key)
|
|
||||||
}
|
|
||||||
append("&sort=") // view, uploaded, rating, follow, user_follow_count
|
|
||||||
append(
|
|
||||||
when (sortOrder) {
|
|
||||||
SortOrder.POPULARITY -> "view"
|
|
||||||
SortOrder.RATING -> "rating"
|
|
||||||
else -> "uploaded"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val ja = loaderContext.httpGet(url).parseJsonArray()
|
|
||||||
val tagsMap = cachedTags ?: loadTags()
|
|
||||||
return ja.map { jo ->
|
|
||||||
val slug = jo.getString("slug")
|
|
||||||
Manga(
|
|
||||||
id = generateUid(slug),
|
|
||||||
title = jo.getString("title"),
|
|
||||||
altTitle = null,
|
|
||||||
url = slug,
|
|
||||||
publicUrl = "https://$domain/comic/$slug",
|
|
||||||
rating = jo.getDouble("rating").toFloat() / 10f,
|
|
||||||
isNsfw = false,
|
|
||||||
coverUrl = jo.getString("cover_url"),
|
|
||||||
largeCoverUrl = null,
|
|
||||||
description = jo.getStringOrNull("desc"),
|
|
||||||
tags = jo.selectGenres("genres", tagsMap),
|
|
||||||
state = runCatching {
|
|
||||||
if (jo.getBoolean("translation_completed")) {
|
|
||||||
MangaState.FINISHED
|
|
||||||
} else {
|
|
||||||
MangaState.ONGOING
|
|
||||||
}
|
|
||||||
}.getOrNull(),
|
|
||||||
author = null,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val domain = getDomain()
|
|
||||||
val url = "https://api.$domain/comic/${manga.url}?tachiyomi=true"
|
|
||||||
val jo = loaderContext.httpGet(url).parseJson()
|
|
||||||
val comic = jo.getJSONObject("comic")
|
|
||||||
return manga.copy(
|
|
||||||
title = comic.getString("title"),
|
|
||||||
altTitle = null, // TODO
|
|
||||||
isNsfw = jo.getBoolean("matureContent") || comic.getBoolean("hentai"),
|
|
||||||
description = comic.getStringOrNull("parsed") ?: comic.getString("desc"),
|
|
||||||
tags = manga.tags + jo.getJSONArray("genres").mapToSet {
|
|
||||||
MangaTag(
|
|
||||||
title = it.getString("name"),
|
|
||||||
key = it.getString("slug"),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
author = jo.getJSONArray("artists").optJSONObject(0)?.getString("name"),
|
|
||||||
chapters = getChapters(comic.getLong("id")),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val jo = loaderContext.httpGet(
|
|
||||||
"https://api.${getDomain()}/chapter/${chapter.url}?tachiyomi=true"
|
|
||||||
).parseJson().getJSONObject("chapter")
|
|
||||||
val referer = "https://${getDomain()}/"
|
|
||||||
return jo.getJSONArray("images").map {
|
|
||||||
val url = it.getString("url")
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = url,
|
|
||||||
referer = referer,
|
|
||||||
preview = null,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val sparseArray = cachedTags ?: loadTags()
|
|
||||||
val set = ArraySet<MangaTag>(sparseArray.size())
|
|
||||||
for (i in 0 until sparseArray.size()) {
|
|
||||||
set.add(sparseArray.valueAt(i))
|
|
||||||
}
|
|
||||||
return set
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun loadTags(): SparseArray<MangaTag> {
|
|
||||||
val ja = loaderContext.httpGet("https://api.${getDomain()}/genre").parseJsonArray()
|
|
||||||
val tags = SparseArray<MangaTag>(ja.length())
|
|
||||||
for (jo in ja) {
|
|
||||||
tags.append(
|
|
||||||
jo.getInt("id"),
|
|
||||||
MangaTag(
|
|
||||||
title = jo.getString("name"),
|
|
||||||
key = jo.getString("slug"),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
cachedTags = tags
|
|
||||||
return tags
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun getChapters(id: Long): List<MangaChapter> {
|
|
||||||
val ja = loaderContext.httpGet(
|
|
||||||
url = "https://api.${getDomain()}/comic/$id/chapter?tachiyomi=true&limit=$CHAPTERS_LIMIT"
|
|
||||||
).parseJson().getJSONArray("chapters")
|
|
||||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
|
|
||||||
val counters = HashMap<Locale, Int>()
|
|
||||||
return ja.mapReversed { jo ->
|
|
||||||
val locale = Locale.forLanguageTag(jo.getString("lang"))
|
|
||||||
var number = counters[locale] ?: 0
|
|
||||||
number++
|
|
||||||
counters[locale] = number
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(jo.getLong("id")),
|
|
||||||
name = buildString {
|
|
||||||
jo.getStringOrNull("vol")?.let { append("Vol ").append(it).append(' ') }
|
|
||||||
jo.getStringOrNull("chap")?.let { append("Chap ").append(it) }
|
|
||||||
jo.getStringOrNull("title")?.let { append(": ").append(it) }
|
|
||||||
},
|
|
||||||
number = number,
|
|
||||||
url = jo.getString("hid"),
|
|
||||||
scanlator = jo.optJSONArray("group_name")?.optString(0),
|
|
||||||
uploadDate = dateFormat.tryParse(jo.getString("created_at").substringBefore('T')),
|
|
||||||
branch = locale.getDisplayName(locale).toTitleCase(locale),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun <R> JSONArray.mapReversed(block: (JSONObject) -> R): List<R> {
|
|
||||||
val len = length()
|
|
||||||
val destination = ArrayList<R>(len)
|
|
||||||
for (i in (0 until len).reversed()) {
|
|
||||||
val jo = getJSONObject(i)
|
|
||||||
destination.add(block(jo))
|
|
||||||
}
|
|
||||||
return destination
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun JSONObject.selectGenres(name: String, tags: SparseArray<MangaTag>): Set<MangaTag> {
|
|
||||||
val array = optJSONArray(name) ?: return emptySet()
|
|
||||||
val res = ArraySet<MangaTag>(array.length())
|
|
||||||
for (i in 0 until array.length()) {
|
|
||||||
val id = array.getInt(i)
|
|
||||||
val tag = tags.get(id) ?: continue
|
|
||||||
res.add(tag)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,149 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class DesuMeRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val source = MangaSource.DESUME
|
|
||||||
|
|
||||||
override val defaultDomain = "desu.me"
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.UPDATED,
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
SortOrder.NEWEST,
|
|
||||||
SortOrder.ALPHABETICAL
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
if (query != null && offset != 0) {
|
|
||||||
return emptyList()
|
|
||||||
}
|
|
||||||
val domain = getDomain()
|
|
||||||
val url = buildString {
|
|
||||||
append("https://")
|
|
||||||
append(domain)
|
|
||||||
append("/manga/api/?limit=20&order=")
|
|
||||||
append(getSortKey(sortOrder))
|
|
||||||
append("&page=")
|
|
||||||
append((offset / 20) + 1)
|
|
||||||
if (!tags.isNullOrEmpty()) {
|
|
||||||
append("&genres=")
|
|
||||||
appendAll(tags, ",") { it.key }
|
|
||||||
}
|
|
||||||
if (query != null) {
|
|
||||||
append("&search=")
|
|
||||||
append(query)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val json = loaderContext.httpGet(url).parseJson().getJSONArray("response")
|
|
||||||
?: throw ParseException("Invalid response")
|
|
||||||
val total = json.length()
|
|
||||||
val list = ArrayList<Manga>(total)
|
|
||||||
for (i in 0 until total) {
|
|
||||||
val jo = json.getJSONObject(i)
|
|
||||||
val cover = jo.getJSONObject("image")
|
|
||||||
val id = jo.getLong("id")
|
|
||||||
list += Manga(
|
|
||||||
url = "/manga/api/$id",
|
|
||||||
publicUrl = jo.getString("url"),
|
|
||||||
source = MangaSource.DESUME,
|
|
||||||
title = jo.getString("russian"),
|
|
||||||
altTitle = jo.getString("name"),
|
|
||||||
coverUrl = cover.getString("preview"),
|
|
||||||
largeCoverUrl = cover.getString("original"),
|
|
||||||
state = when {
|
|
||||||
jo.getInt("ongoing") == 1 -> MangaState.ONGOING
|
|
||||||
else -> null
|
|
||||||
},
|
|
||||||
rating = jo.getDouble("score").toFloat().coerceIn(0f, 1f),
|
|
||||||
id = generateUid(id),
|
|
||||||
description = jo.getString("description")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val url = manga.url.withDomain()
|
|
||||||
val json = loaderContext.httpGet(url).parseJson().getJSONObject("response")
|
|
||||||
?: throw ParseException("Invalid response")
|
|
||||||
val baseChapterUrl = manga.url + "/chapter/"
|
|
||||||
val chaptersList = json.getJSONObject("chapters").getJSONArray("list")
|
|
||||||
val totalChapters = chaptersList.length()
|
|
||||||
return manga.copy(
|
|
||||||
tags = json.getJSONArray("genres").mapToSet {
|
|
||||||
MangaTag(
|
|
||||||
key = it.getString("text"),
|
|
||||||
title = it.getString("russian").toTitleCase(),
|
|
||||||
source = manga.source
|
|
||||||
)
|
|
||||||
},
|
|
||||||
publicUrl = json.getString("url"),
|
|
||||||
description = json.getString("description"),
|
|
||||||
chapters = chaptersList.mapIndexed { i, it ->
|
|
||||||
val chid = it.getLong("id")
|
|
||||||
val volChap = "Том " + it.optString("vol", "0") + ". " + "Глава " + it.optString("ch", "0")
|
|
||||||
val title = it.optString("title", "null").takeUnless { it == "null" }
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(chid),
|
|
||||||
source = manga.source,
|
|
||||||
url = "$baseChapterUrl$chid",
|
|
||||||
uploadDate = it.getLong("date") * 1000,
|
|
||||||
name = if (title.isNullOrEmpty()) volChap else "$volChap: $title",
|
|
||||||
number = totalChapters - i,
|
|
||||||
scanlator = null,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
}.reversed()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val fullUrl = chapter.url.withDomain()
|
|
||||||
val json = loaderContext.httpGet(fullUrl)
|
|
||||||
.parseJson()
|
|
||||||
.getJSONObject("response") ?: throw ParseException("Invalid response")
|
|
||||||
return json.getJSONObject("pages").getJSONArray("list").map { jo ->
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(jo.getLong("id")),
|
|
||||||
referer = fullUrl,
|
|
||||||
preview = null,
|
|
||||||
source = chapter.source,
|
|
||||||
url = jo.getString("img"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val doc = loaderContext.httpGet("https://${getDomain()}/manga/").parseHtml()
|
|
||||||
val root = doc.body().getElementById("animeFilter")
|
|
||||||
?.selectFirst(".catalog-genres") ?: throw ParseException("Root not found")
|
|
||||||
return root.select("li").mapToSet {
|
|
||||||
MangaTag(
|
|
||||||
source = source,
|
|
||||||
key = it.selectFirst("input")?.attr("data-genre") ?: parseFailed(),
|
|
||||||
title = it.selectFirst("label")?.text()?.toTitleCase() ?: parseFailed()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSortKey(sortOrder: SortOrder?) =
|
|
||||||
when (sortOrder) {
|
|
||||||
SortOrder.ALPHABETICAL -> "name"
|
|
||||||
SortOrder.POPULARITY -> "popular"
|
|
||||||
SortOrder.UPDATED -> "updated"
|
|
||||||
SortOrder.NEWEST -> "id"
|
|
||||||
else -> "updated"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,281 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.jsoup.nodes.Element
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.AuthRequiredException
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepositoryAuthProvider
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.util.*
|
|
||||||
import kotlin.math.pow
|
|
||||||
|
|
||||||
private const val DOMAIN_UNAUTHORIZED = "e-hentai.org"
|
|
||||||
private const val DOMAIN_AUTHORIZED = "exhentai.org"
|
|
||||||
|
|
||||||
class ExHentaiRepository(
|
|
||||||
loaderContext: MangaLoaderContext,
|
|
||||||
) : RemoteMangaRepository(loaderContext), MangaRepositoryAuthProvider {
|
|
||||||
|
|
||||||
override val source = MangaSource.EXHENTAI
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.NEWEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
override val defaultDomain: String
|
|
||||||
get() = if (isAuthorized()) DOMAIN_AUTHORIZED else DOMAIN_UNAUTHORIZED
|
|
||||||
|
|
||||||
override val authUrl: String
|
|
||||||
get() = "https://${getDomain()}/bounce_login.php"
|
|
||||||
|
|
||||||
private val ratingPattern = Regex("-?[0-9]+px")
|
|
||||||
private val authCookies = arrayOf("ipb_member_id", "ipb_pass_hash")
|
|
||||||
private var updateDm = false
|
|
||||||
|
|
||||||
init {
|
|
||||||
loaderContext.cookieJar.insertCookies(DOMAIN_AUTHORIZED, "nw=1", "sl=dm_2")
|
|
||||||
loaderContext.cookieJar.insertCookies(DOMAIN_UNAUTHORIZED, "nw=1", "sl=dm_2")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?,
|
|
||||||
): List<Manga> {
|
|
||||||
val page = (offset / 25f).toIntUp()
|
|
||||||
var search = query?.urlEncoded().orEmpty()
|
|
||||||
val url = buildString {
|
|
||||||
append("https://")
|
|
||||||
append(getDomain())
|
|
||||||
append("/?page=")
|
|
||||||
append(page)
|
|
||||||
if (!tags.isNullOrEmpty()) {
|
|
||||||
var fCats = 0
|
|
||||||
for (tag in tags) {
|
|
||||||
tag.key.toIntOrNull()?.let { fCats = fCats or it } ?: run {
|
|
||||||
search += tag.key + " "
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fCats != 0) {
|
|
||||||
append("&f_cats=")
|
|
||||||
append(1023 - fCats)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (search.isNotEmpty()) {
|
|
||||||
append("&f_search=")
|
|
||||||
append(search.trim().replace(' ', '+'))
|
|
||||||
}
|
|
||||||
// by unknown reason cookie "sl=dm_2" is ignored, so, we should request it again
|
|
||||||
if (updateDm) {
|
|
||||||
append("&inline_set=dm_e")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val body = loaderContext.httpGet(url).parseHtml().body()
|
|
||||||
val root = body.selectFirst("table.itg")
|
|
||||||
?.selectFirst("tbody")
|
|
||||||
?: if (updateDm) {
|
|
||||||
parseFailed("Cannot find root")
|
|
||||||
} else {
|
|
||||||
updateDm = true
|
|
||||||
return getList2(offset, query, tags, sortOrder)
|
|
||||||
}
|
|
||||||
updateDm = false
|
|
||||||
return root.children().mapNotNull { tr ->
|
|
||||||
if (tr.childrenSize() != 2) return@mapNotNull null
|
|
||||||
val (td1, td2) = tr.children()
|
|
||||||
val glink = td2.selectFirst("div.glink") ?: parseFailed("glink not found")
|
|
||||||
val a = glink.parents().select("a").first() ?: parseFailed("link not found")
|
|
||||||
val href = a.relUrl("href")
|
|
||||||
val tagsDiv = glink.nextElementSibling() ?: parseFailed("tags div not found")
|
|
||||||
val mainTag = td2.selectFirst("div.cn")?.let { div ->
|
|
||||||
MangaTag(
|
|
||||||
title = div.text().toTitleCase(),
|
|
||||||
key = tagIdByClass(div.classNames()) ?: return@let null,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Manga(
|
|
||||||
id = generateUid(href),
|
|
||||||
title = glink.text().cleanupTitle(),
|
|
||||||
altTitle = null,
|
|
||||||
url = href,
|
|
||||||
publicUrl = a.absUrl("href"),
|
|
||||||
rating = td2.selectFirst("div.ir")?.parseRating() ?: Manga.NO_RATING,
|
|
||||||
isNsfw = true,
|
|
||||||
coverUrl = td1.selectFirst("img")?.absUrl("src").orEmpty(),
|
|
||||||
tags = setOfNotNull(mainTag),
|
|
||||||
state = null,
|
|
||||||
author = tagsDiv.getElementsContainingOwnText("artist:").first()
|
|
||||||
?.nextElementSibling()?.text(),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val doc = loaderContext.httpGet(manga.url.withDomain()).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("div.gm") ?: parseFailed("Cannot find root")
|
|
||||||
val cover = root.getElementById("gd1")?.children()?.first()
|
|
||||||
val title = root.getElementById("gd2")
|
|
||||||
val taglist = root.getElementById("taglist")
|
|
||||||
val tabs = doc.body().selectFirst("table.ptt")?.selectFirst("tr")
|
|
||||||
return manga.copy(
|
|
||||||
title = title?.getElementById("gn")?.text()?.cleanupTitle() ?: manga.title,
|
|
||||||
altTitle = title?.getElementById("gj")?.text()?.cleanupTitle() ?: manga.altTitle,
|
|
||||||
publicUrl = doc.baseUri().ifEmpty { manga.publicUrl },
|
|
||||||
rating = root.getElementById("rating_label")?.text()
|
|
||||||
?.substringAfterLast(' ')
|
|
||||||
?.toFloatOrNull()
|
|
||||||
?.div(5f) ?: manga.rating,
|
|
||||||
largeCoverUrl = cover?.css("background")?.cssUrl(),
|
|
||||||
description = taglist?.select("tr")?.joinToString("<br>") { tr ->
|
|
||||||
val (tc, td) = tr.children()
|
|
||||||
val subtags = td.select("a").joinToString { it.html() }
|
|
||||||
"<b>${tc.html()}</b> $subtags"
|
|
||||||
},
|
|
||||||
chapters = tabs?.select("a")?.findLast { a ->
|
|
||||||
a.text().toIntOrNull() != null
|
|
||||||
}?.let { a ->
|
|
||||||
val count = a.text().toInt()
|
|
||||||
val chapters = ArrayList<MangaChapter>(count)
|
|
||||||
for (i in 1..count) {
|
|
||||||
val url = "${manga.url}?p=$i"
|
|
||||||
chapters += MangaChapter(
|
|
||||||
id = generateUid(url),
|
|
||||||
name = "${manga.title} #$i",
|
|
||||||
number = i,
|
|
||||||
url = url,
|
|
||||||
uploadDate = 0L,
|
|
||||||
source = source,
|
|
||||||
scanlator = null,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
chapters
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val doc = loaderContext.httpGet(chapter.url.withDomain()).parseHtml()
|
|
||||||
val root = doc.body().getElementById("gdt") ?: parseFailed("Root not found")
|
|
||||||
return root.select("a").mapNotNull { a ->
|
|
||||||
val url = a.relUrl("href")
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = url,
|
|
||||||
referer = a.absUrl("href"),
|
|
||||||
preview = null,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPageUrl(page: MangaPage): String {
|
|
||||||
val doc = loaderContext.httpGet(page.url.withDomain()).parseHtml()
|
|
||||||
return doc.body().getElementById("img")?.absUrl("src")
|
|
||||||
?: parseFailed("Image not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val doc = loaderContext.httpGet("https://${getDomain()}").parseHtml()
|
|
||||||
val root = doc.body().getElementById("searchbox")?.selectFirst("table")
|
|
||||||
?: parseFailed("Root not found")
|
|
||||||
return root.select("div.cs").mapNotNullToSet { div ->
|
|
||||||
val id = div.id().substringAfterLast('_').toIntOrNull()
|
|
||||||
?: return@mapNotNullToSet null
|
|
||||||
MangaTag(
|
|
||||||
title = div.text().toTitleCase(),
|
|
||||||
key = id.toString(),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isAuthorized(): Boolean {
|
|
||||||
val authorized = isAuthorized(DOMAIN_UNAUTHORIZED)
|
|
||||||
if (authorized) {
|
|
||||||
if (!isAuthorized(DOMAIN_AUTHORIZED)) {
|
|
||||||
loaderContext.cookieJar.copyCookies(
|
|
||||||
DOMAIN_UNAUTHORIZED,
|
|
||||||
DOMAIN_AUTHORIZED,
|
|
||||||
authCookies,
|
|
||||||
)
|
|
||||||
loaderContext.cookieJar.insertCookies(DOMAIN_AUTHORIZED, "yay=louder")
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getUsername(): String {
|
|
||||||
val doc = loaderContext.httpGet("https://forums.${DOMAIN_UNAUTHORIZED}/").parseHtml().body()
|
|
||||||
val username = doc.getElementById("userlinks")
|
|
||||||
?.getElementsByAttributeValueContaining("href", "?showuser=")
|
|
||||||
?.firstOrNull()
|
|
||||||
?.ownText()
|
|
||||||
?: if (doc.getElementById("userlinksguest") != null) {
|
|
||||||
throw AuthRequiredException(source)
|
|
||||||
} else {
|
|
||||||
throw ParseException()
|
|
||||||
}
|
|
||||||
return username
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isAuthorized(domain: String): Boolean {
|
|
||||||
val cookies = loaderContext.cookieJar.getCookies(domain).mapToSet { x -> x.name }
|
|
||||||
return authCookies.all { it in cookies }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Element.parseRating(): Float {
|
|
||||||
return runCatching {
|
|
||||||
val style = requireNotNull(attr("style"))
|
|
||||||
val (v1, v2) = ratingPattern.find(style)!!.destructured
|
|
||||||
var p1 = v1.dropLast(2).toInt()
|
|
||||||
val p2 = v2.dropLast(2).toInt()
|
|
||||||
if (p2 != -1) {
|
|
||||||
p1 += 8
|
|
||||||
}
|
|
||||||
(80 - p1) / 80f
|
|
||||||
}.getOrDefault(Manga.NO_RATING)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun String.cleanupTitle(): String {
|
|
||||||
val result = StringBuilder(length)
|
|
||||||
var skip = false
|
|
||||||
for (c in this) {
|
|
||||||
when {
|
|
||||||
c == '[' -> skip = true
|
|
||||||
c == ']' -> skip = false
|
|
||||||
c.isWhitespace() && result.isEmpty() -> continue
|
|
||||||
!skip -> result.append(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (result.lastOrNull()?.isWhitespace() == true) {
|
|
||||||
result.deleteCharAt(result.lastIndex)
|
|
||||||
}
|
|
||||||
return result.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun String.cssUrl(): String? {
|
|
||||||
val fromIndex = indexOf("url(")
|
|
||||||
if (fromIndex == -1) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
val toIndex = indexOf(')', startIndex = fromIndex)
|
|
||||||
return if (toIndex == -1) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
substring(fromIndex + 4, toIndex).trim()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun tagIdByClass(classNames: Collection<String>): String? {
|
|
||||||
val className = classNames.find { x -> x.startsWith("ct") } ?: return null
|
|
||||||
val num = className.drop(2).toIntOrNull(16) ?: return null
|
|
||||||
return 2.0.pow(num).toInt().toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,246 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import okhttp3.Headers
|
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
|
||||||
import okhttp3.Response
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
private const val PAGE_SIZE = 70
|
|
||||||
private const val PAGE_SIZE_SEARCH = 50
|
|
||||||
|
|
||||||
abstract class GroupleRepository(loaderContext: MangaLoaderContext) :
|
|
||||||
RemoteMangaRepository(loaderContext) {
|
|
||||||
|
|
||||||
private val headers = Headers.Builder()
|
|
||||||
.add("User-Agent", "readmangafun")
|
|
||||||
.build()
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.UPDATED,
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
SortOrder.NEWEST,
|
|
||||||
SortOrder.RATING
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val doc = when {
|
|
||||||
!query.isNullOrEmpty() -> loaderContext.httpPost(
|
|
||||||
"https://$domain/search",
|
|
||||||
mapOf(
|
|
||||||
"q" to query.urlEncoded(),
|
|
||||||
"offset" to (offset upBy PAGE_SIZE_SEARCH).toString()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
tags.isNullOrEmpty() -> loaderContext.httpGet(
|
|
||||||
"https://$domain/list?sortType=${
|
|
||||||
getSortKey(
|
|
||||||
sortOrder
|
|
||||||
)
|
|
||||||
}&offset=${offset upBy PAGE_SIZE}", headers
|
|
||||||
)
|
|
||||||
tags.size == 1 -> loaderContext.httpGet(
|
|
||||||
"https://$domain/list/genre/${tags.first().key}?sortType=${
|
|
||||||
getSortKey(
|
|
||||||
sortOrder
|
|
||||||
)
|
|
||||||
}&offset=${offset upBy PAGE_SIZE}", headers
|
|
||||||
)
|
|
||||||
offset > 0 -> return emptyList()
|
|
||||||
else -> advancedSearch(domain, tags)
|
|
||||||
}.parseHtml().body()
|
|
||||||
val root = (doc.getElementById("mangaBox") ?: doc.getElementById("mangaResults"))
|
|
||||||
?.selectFirst("div.tiles.row") ?: throw ParseException("Cannot find root")
|
|
||||||
val baseHost = root.baseUri().toHttpUrl().host
|
|
||||||
return root.select("div.tile").mapNotNull { node ->
|
|
||||||
val imgDiv = node.selectFirst("div.img") ?: return@mapNotNull null
|
|
||||||
val descDiv = node.selectFirst("div.desc") ?: return@mapNotNull null
|
|
||||||
if (descDiv.selectFirst("i.fa-user") != null) {
|
|
||||||
return@mapNotNull null //skip author
|
|
||||||
}
|
|
||||||
val href = imgDiv.selectFirst("a")?.attr("href")?.inContextOf(node)
|
|
||||||
if (href == null || href.toHttpUrl().host != baseHost) {
|
|
||||||
return@mapNotNull null // skip external links
|
|
||||||
}
|
|
||||||
val title = descDiv.selectFirst("h3")?.selectFirst("a")?.text()
|
|
||||||
?: return@mapNotNull null
|
|
||||||
val tileInfo = descDiv.selectFirst("div.tile-info")
|
|
||||||
val relUrl = href.toRelativeUrl(baseHost)
|
|
||||||
Manga(
|
|
||||||
id = generateUid(relUrl),
|
|
||||||
url = relUrl,
|
|
||||||
publicUrl = href,
|
|
||||||
title = title,
|
|
||||||
altTitle = descDiv.selectFirst("h4")?.text(),
|
|
||||||
coverUrl = imgDiv.selectFirst("img.lazy")?.attr("data-original").orEmpty(),
|
|
||||||
rating = runCatching {
|
|
||||||
node.selectFirst("div.rating")
|
|
||||||
?.attr("title")
|
|
||||||
?.substringBefore(' ')
|
|
||||||
?.toFloatOrNull()
|
|
||||||
?.div(10f)
|
|
||||||
}.getOrNull() ?: Manga.NO_RATING,
|
|
||||||
author = tileInfo?.selectFirst("a.person-link")?.text(),
|
|
||||||
tags = runCatching {
|
|
||||||
tileInfo?.select("a.element-link")
|
|
||||||
?.mapToSet {
|
|
||||||
MangaTag(
|
|
||||||
title = it.text().toTitleCase(),
|
|
||||||
key = it.attr("href").substringAfterLast('/'),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}.getOrNull().orEmpty(),
|
|
||||||
state = when {
|
|
||||||
node.selectFirst("div.tags")
|
|
||||||
?.selectFirst("span.mangaCompleted") != null -> MangaState.FINISHED
|
|
||||||
else -> null
|
|
||||||
},
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val doc = loaderContext.httpGet(manga.url.withDomain(), headers).parseHtml()
|
|
||||||
val root = doc.body().getElementById("mangaBox")?.selectFirst("div.leftContent")
|
|
||||||
?: throw ParseException("Cannot find root")
|
|
||||||
val dateFormat = SimpleDateFormat("dd.MM.yy", Locale.US)
|
|
||||||
val coverImg = root.selectFirst("div.subject-cover")?.selectFirst("img")
|
|
||||||
return manga.copy(
|
|
||||||
description = root.selectFirst("div.manga-description")?.html(),
|
|
||||||
largeCoverUrl = coverImg?.attr("data-full"),
|
|
||||||
coverUrl = coverImg?.attr("data-thumb") ?: manga.coverUrl,
|
|
||||||
tags = manga.tags + root.select("div.subject-meta").select("span.elem_genre ")
|
|
||||||
.mapNotNull {
|
|
||||||
val a = it.selectFirst("a.element-link") ?: return@mapNotNull null
|
|
||||||
MangaTag(
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
key = a.attr("href").substringAfterLast('/'),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
},
|
|
||||||
chapters = root.selectFirst("div.chapters-link")?.selectFirst("table")
|
|
||||||
?.select("tr:has(td > a)")?.asReversed()?.mapIndexedNotNull { i, tr ->
|
|
||||||
val a = tr.selectFirst("a") ?: return@mapIndexedNotNull null
|
|
||||||
val href = a.relUrl("href")
|
|
||||||
var translators = ""
|
|
||||||
val translatorElement = a.attr("title")
|
|
||||||
if (!translatorElement.isNullOrBlank()) {
|
|
||||||
translators = translatorElement
|
|
||||||
.replace("(Переводчик),", "&")
|
|
||||||
.removeSuffix(" (Переводчик)")
|
|
||||||
}
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(href),
|
|
||||||
name = tr.selectFirst("a")?.text().orEmpty().removePrefix(manga.title).trim(),
|
|
||||||
number = i + 1,
|
|
||||||
url = href,
|
|
||||||
uploadDate = dateFormat.tryParse(tr.selectFirst("td.d-none")?.text()),
|
|
||||||
scanlator = translators,
|
|
||||||
source = source,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val doc = loaderContext.httpGet(chapter.url.withDomain() + "?mtr=1", headers).parseHtml()
|
|
||||||
val scripts = doc.select("script")
|
|
||||||
for (script in scripts) {
|
|
||||||
val data = script.html()
|
|
||||||
val pos = data.indexOf("rm_h.init")
|
|
||||||
if (pos == -1) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val json = data.substring(pos).substringAfter('[').substringBeforeLast(']')
|
|
||||||
val matches = Regex("\\[.*?]").findAll(json).toList()
|
|
||||||
val regex = Regex("['\"].*?['\"]")
|
|
||||||
return matches.map { x ->
|
|
||||||
val parts = regex.findAll(x.value).toList()
|
|
||||||
val url = parts[0].value.removeSurrounding('"', '\'') +
|
|
||||||
parts[2].value.removeSurrounding('"', '\'')
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = url,
|
|
||||||
preview = null,
|
|
||||||
referer = chapter.url,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw ParseException("Pages list not found at ${chapter.url}")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val doc = loaderContext.httpGet("https://${getDomain()}/list/genres/sort_name", headers).parseHtml()
|
|
||||||
val root = doc.body().getElementById("mangaBox")?.selectFirst("div.leftContent")
|
|
||||||
?.selectFirst("table.table") ?: parseFailed("Cannot find root")
|
|
||||||
return root.select("a.element-link").mapToSet { a ->
|
|
||||||
MangaTag(
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
key = a.attr("href").substringAfterLast('/'),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSortKey(sortOrder: SortOrder?) =
|
|
||||||
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {
|
|
||||||
SortOrder.ALPHABETICAL -> "name"
|
|
||||||
SortOrder.POPULARITY -> "rate"
|
|
||||||
SortOrder.UPDATED -> "updated"
|
|
||||||
SortOrder.NEWEST -> "created"
|
|
||||||
SortOrder.RATING -> "votes"
|
|
||||||
null -> "updated"
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun advancedSearch(domain: String, tags: Set<MangaTag>): Response {
|
|
||||||
val url = "https://$domain/search/advanced"
|
|
||||||
// Step 1: map catalog genres names to advanced-search genres ids
|
|
||||||
val tagsIndex = loaderContext.httpGet(url, headers).parseHtml()
|
|
||||||
.body().selectFirst("form.search-form")
|
|
||||||
?.select("div.form-group")
|
|
||||||
?.get(1) ?: parseFailed("Genres filter element not found")
|
|
||||||
val tagNames = tags.map { it.title.lowercase() }
|
|
||||||
val payload = HashMap<String, String>()
|
|
||||||
var foundGenres = 0
|
|
||||||
tagsIndex.select("li.property").forEach { li ->
|
|
||||||
val name = li.text().trim().lowercase()
|
|
||||||
val id = li.selectFirst("input")?.id()
|
|
||||||
?: parseFailed("Id for tag $name not found")
|
|
||||||
payload[id] = if (name in tagNames) {
|
|
||||||
foundGenres++
|
|
||||||
"in"
|
|
||||||
} else ""
|
|
||||||
}
|
|
||||||
if (foundGenres != tags.size) {
|
|
||||||
parseFailed("Some genres are not found")
|
|
||||||
}
|
|
||||||
// Step 2: advanced search
|
|
||||||
payload["q"] = ""
|
|
||||||
payload["s_high_rate"] = ""
|
|
||||||
payload["s_single"] = ""
|
|
||||||
payload["s_mature"] = ""
|
|
||||||
payload["s_completed"] = ""
|
|
||||||
payload["s_translated"] = ""
|
|
||||||
payload["s_many_chapters"] = ""
|
|
||||||
payload["s_wait_upload"] = ""
|
|
||||||
payload["s_sale"] = ""
|
|
||||||
payload["years"] = "1900,2099"
|
|
||||||
payload["+"] = "Искать".urlEncoded()
|
|
||||||
return loaderContext.httpPost(url, payload)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.utils.ext.mapToSet
|
|
||||||
import org.koitharu.kotatsu.utils.ext.parseHtml
|
|
||||||
import org.koitharu.kotatsu.utils.ext.toTitleCase
|
|
||||||
|
|
||||||
class HenChanRepository(loaderContext: MangaLoaderContext) : ChanRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val defaultDomain = "hentaichan.live"
|
|
||||||
override val source = MangaSource.HENCHAN
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
return super.getList2(offset, query, tags, sortOrder).map {
|
|
||||||
it.copy(
|
|
||||||
coverUrl = it.coverUrl.replace("_blur", ""),
|
|
||||||
isNsfw = true,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val doc = loaderContext.httpGet(manga.url.withDomain()).parseHtml()
|
|
||||||
val root =
|
|
||||||
doc.body().getElementById("dle-content") ?: throw ParseException("Cannot find root")
|
|
||||||
val readLink = manga.url.replace("manga", "online")
|
|
||||||
return manga.copy(
|
|
||||||
description = root.getElementById("description")?.html()?.substringBeforeLast("<div"),
|
|
||||||
largeCoverUrl = root.getElementById("cover")?.absUrl("src"),
|
|
||||||
tags = root.selectFirst("div.sidetags")?.select("li.sidetag")?.mapToSet {
|
|
||||||
val a = it.children().last() ?: parseFailed("Invalid tag")
|
|
||||||
MangaTag(
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
key = a.attr("href").substringAfterLast('/'),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
} ?: manga.tags,
|
|
||||||
chapters = listOf(
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(readLink),
|
|
||||||
url = readLink,
|
|
||||||
source = source,
|
|
||||||
number = 1,
|
|
||||||
uploadDate = 0L,
|
|
||||||
name = manga.title,
|
|
||||||
scanlator = null,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
|
|
||||||
class HentaiLibRepository(loaderContext: MangaLoaderContext) : MangaLibRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val defaultDomain = "hentailib.me"
|
|
||||||
|
|
||||||
override val source = MangaSource.HENTAILIB
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
|
|
||||||
class MangaChanRepository(loaderContext: MangaLoaderContext) : ChanRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val defaultDomain = "manga-chan.me"
|
|
||||||
override val source = MangaSource.MANGACHAN
|
|
||||||
}
|
|
||||||
@ -1,216 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import android.os.Build
|
|
||||||
import androidx.core.os.LocaleListCompat
|
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.coroutineScope
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
private const val PAGE_SIZE = 20
|
|
||||||
private const val CONTENT_RATING =
|
|
||||||
"contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic"
|
|
||||||
private const val LOCALE_FALLBACK = "en"
|
|
||||||
|
|
||||||
class MangaDexRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val source = MangaSource.MANGADEX
|
|
||||||
override val defaultDomain = "mangadex.org"
|
|
||||||
|
|
||||||
override val sortOrders: EnumSet<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.UPDATED,
|
|
||||||
SortOrder.ALPHABETICAL,
|
|
||||||
SortOrder.NEWEST,
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?,
|
|
||||||
): List<Manga> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val url = buildString {
|
|
||||||
append("https://api.")
|
|
||||||
append(domain)
|
|
||||||
append("/manga?limit=")
|
|
||||||
append(PAGE_SIZE)
|
|
||||||
append("&offset=")
|
|
||||||
append(offset)
|
|
||||||
append("&includes[]=cover_art&includes[]=author&includes[]=artist&")
|
|
||||||
tags?.forEach { tag ->
|
|
||||||
append("includedTags[]=")
|
|
||||||
append(tag.key)
|
|
||||||
append('&')
|
|
||||||
}
|
|
||||||
if (!query.isNullOrEmpty()) {
|
|
||||||
append("title=")
|
|
||||||
append(query.urlEncoded())
|
|
||||||
append('&')
|
|
||||||
}
|
|
||||||
append(CONTENT_RATING)
|
|
||||||
append("&order")
|
|
||||||
append(when (sortOrder) {
|
|
||||||
null,
|
|
||||||
SortOrder.UPDATED,
|
|
||||||
-> "[latestUploadedChapter]=desc"
|
|
||||||
SortOrder.ALPHABETICAL -> "[title]=asc"
|
|
||||||
SortOrder.NEWEST -> "[createdAt]=desc"
|
|
||||||
SortOrder.POPULARITY -> "[followedCount]=desc"
|
|
||||||
else -> "[followedCount]=desc"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
val json = loaderContext.httpGet(url).parseJson().getJSONArray("data")
|
|
||||||
return json.map { jo ->
|
|
||||||
val id = jo.getString("id")
|
|
||||||
val attrs = jo.getJSONObject("attributes")
|
|
||||||
val relations = jo.getJSONArray("relationships").associateByKey("type")
|
|
||||||
val cover = relations["cover_art"]
|
|
||||||
?.getJSONObject("attributes")
|
|
||||||
?.getString("fileName")
|
|
||||||
?.let {
|
|
||||||
"https://uploads.$domain/covers/$id/$it"
|
|
||||||
}
|
|
||||||
Manga(
|
|
||||||
id = generateUid(id),
|
|
||||||
title = requireNotNull(attrs.getJSONObject("title").selectByLocale()) {
|
|
||||||
"Title should not be null"
|
|
||||||
},
|
|
||||||
altTitle = attrs.optJSONObject("altTitles")?.selectByLocale(),
|
|
||||||
url = id,
|
|
||||||
publicUrl = "https://$domain/title/$id",
|
|
||||||
rating = Manga.NO_RATING,
|
|
||||||
isNsfw = attrs.getStringOrNull("contentRating") == "erotica",
|
|
||||||
coverUrl = cover?.plus(".256.jpg").orEmpty(),
|
|
||||||
largeCoverUrl = cover,
|
|
||||||
description = attrs.optJSONObject("description")?.selectByLocale(),
|
|
||||||
tags = attrs.getJSONArray("tags").mapToSet { tag ->
|
|
||||||
MangaTag(
|
|
||||||
title = tag.getJSONObject("attributes")
|
|
||||||
.getJSONObject("name")
|
|
||||||
.firstStringValue()
|
|
||||||
.toTitleCase(),
|
|
||||||
key = tag.getString("id"),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
state = when (jo.getStringOrNull("status")) {
|
|
||||||
"ongoing" -> MangaState.ONGOING
|
|
||||||
"completed" -> MangaState.FINISHED
|
|
||||||
else -> null
|
|
||||||
},
|
|
||||||
author = (relations["author"] ?: relations["artist"])
|
|
||||||
?.getJSONObject("attributes")
|
|
||||||
?.getStringOrNull("name"),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga = coroutineScope<Manga> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val attrsDeferred = async {
|
|
||||||
loaderContext.httpGet(
|
|
||||||
"https://api.$domain/manga/${manga.url}?includes[]=artist&includes[]=author&includes[]=cover_art"
|
|
||||||
).parseJson().getJSONObject("data").getJSONObject("attributes")
|
|
||||||
}
|
|
||||||
val feedDeferred = async {
|
|
||||||
val url = buildString {
|
|
||||||
append("https://api.")
|
|
||||||
append(domain)
|
|
||||||
append("/manga/")
|
|
||||||
append(manga.url)
|
|
||||||
append("/feed")
|
|
||||||
append("?limit=96&includes[]=scanlation_group&order[volume]=asc&order[chapter]=asc&offset=0&")
|
|
||||||
append(CONTENT_RATING)
|
|
||||||
}
|
|
||||||
loaderContext.httpGet(url).parseJson().getJSONArray("data")
|
|
||||||
}
|
|
||||||
val mangaAttrs = attrsDeferred.await()
|
|
||||||
val feed = feedDeferred.await()
|
|
||||||
//2022-01-02T00:27:11+00:00
|
|
||||||
val dateFormat = SimpleDateFormat(
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
"yyyy-MM-dd'T'HH:mm:ssX"
|
|
||||||
} else {
|
|
||||||
"yyyy-MM-dd'T'HH:mm:ss'+00:00'"
|
|
||||||
},
|
|
||||||
Locale.ROOT
|
|
||||||
)
|
|
||||||
manga.copy(
|
|
||||||
description = mangaAttrs.getJSONObject("description").selectByLocale()
|
|
||||||
?: manga.description,
|
|
||||||
chapters = feed.mapNotNull { jo ->
|
|
||||||
val id = jo.getString("id")
|
|
||||||
val attrs = jo.getJSONObject("attributes")
|
|
||||||
if (!attrs.isNull("externalUrl")) {
|
|
||||||
return@mapNotNull null
|
|
||||||
}
|
|
||||||
val locale = Locale.forLanguageTag(attrs.getString("translatedLanguage"))
|
|
||||||
val relations = jo.getJSONArray("relationships").associateByKey("type")
|
|
||||||
val number = attrs.optInt("chapter", 0)
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(id),
|
|
||||||
name = attrs.getStringOrNull("title")?.takeUnless(String::isEmpty)
|
|
||||||
?: "Chapter #$number",
|
|
||||||
number = number,
|
|
||||||
url = id,
|
|
||||||
scanlator = relations["scanlation_group"]?.getStringOrNull("name"),
|
|
||||||
uploadDate = dateFormat.tryParse(attrs.getString("publishAt")),
|
|
||||||
branch = locale.getDisplayName(locale).toTitleCase(locale),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val chapter = loaderContext.httpGet("https://api.$domain/at-home/server/${chapter.url}?forcePort443=false")
|
|
||||||
.parseJson()
|
|
||||||
.getJSONObject("chapter")
|
|
||||||
val pages = chapter.getJSONArray("data")
|
|
||||||
val prefix = "https://uploads.$domain/data/${chapter.getString("hash")}/"
|
|
||||||
val referer = "https://$domain/"
|
|
||||||
return List(pages.length()) { i ->
|
|
||||||
val url = prefix + pages.getString(i)
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = url,
|
|
||||||
referer = referer,
|
|
||||||
preview = null, // TODO prefix + dataSaver.getString(i),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val tags = loaderContext.httpGet("https://api.${getDomain()}/manga/tag").parseJson()
|
|
||||||
.getJSONArray("data")
|
|
||||||
return tags.mapToSet { jo ->
|
|
||||||
MangaTag(
|
|
||||||
title = jo.getJSONObject("attributes").getJSONObject("name").firstStringValue().toTitleCase(),
|
|
||||||
key = jo.getString("id"),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun JSONObject.firstStringValue() = values().next() as String
|
|
||||||
|
|
||||||
private fun JSONObject.selectByLocale(): String? {
|
|
||||||
val preferredLocales = LocaleListCompat.getAdjustedDefault()
|
|
||||||
repeat(preferredLocales.size()) { i ->
|
|
||||||
val locale = preferredLocales.get(i)
|
|
||||||
getStringOrNull(locale.language)?.let { return it }
|
|
||||||
getStringOrNull(locale.toLanguageTag())?.let { return it }
|
|
||||||
}
|
|
||||||
return getStringOrNull(LOCALE_FALLBACK) ?: values().nextOrNull() as? String
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,267 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import androidx.collection.ArraySet
|
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.AuthRequiredException
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepositoryAuthProvider
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
open class MangaLibRepository(loaderContext: MangaLoaderContext) :
|
|
||||||
RemoteMangaRepository(loaderContext), MangaRepositoryAuthProvider {
|
|
||||||
|
|
||||||
override val defaultDomain = "mangalib.me"
|
|
||||||
|
|
||||||
override val source = MangaSource.MANGALIB
|
|
||||||
|
|
||||||
override val authUrl: String
|
|
||||||
get() = "https://${getDomain()}/login"
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.RATING,
|
|
||||||
SortOrder.ALPHABETICAL,
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
SortOrder.UPDATED,
|
|
||||||
SortOrder.NEWEST
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
if (!query.isNullOrEmpty()) {
|
|
||||||
return if (offset == 0) search(query) else emptyList()
|
|
||||||
}
|
|
||||||
val page = (offset / 60f).toIntUp()
|
|
||||||
val url = buildString {
|
|
||||||
append("https://")
|
|
||||||
append(getDomain())
|
|
||||||
append("/manga-list?dir=")
|
|
||||||
append(getSortKey(sortOrder))
|
|
||||||
append("&page=")
|
|
||||||
append(page)
|
|
||||||
tags?.forEach { tag ->
|
|
||||||
append("&genres[include][]=")
|
|
||||||
append(tag.key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val doc = loaderContext.httpGet(url).parseHtml()
|
|
||||||
val root = doc.body().getElementById("manga-list") ?: throw ParseException("Root not found")
|
|
||||||
val items = root.selectFirst("div.media-cards-grid")?.select("div.media-card-wrap")
|
|
||||||
?: return emptyList()
|
|
||||||
return items.mapNotNull { card ->
|
|
||||||
val a = card.selectFirst("a.media-card") ?: return@mapNotNull null
|
|
||||||
val href = a.relUrl("href")
|
|
||||||
Manga(
|
|
||||||
id = generateUid(href),
|
|
||||||
title = card.selectFirst("h3")?.text().orEmpty(),
|
|
||||||
coverUrl = a.absUrl("data-src"),
|
|
||||||
altTitle = null,
|
|
||||||
author = null,
|
|
||||||
rating = Manga.NO_RATING,
|
|
||||||
url = href,
|
|
||||||
publicUrl = href.inContextOf(a),
|
|
||||||
tags = emptySet(),
|
|
||||||
state = null,
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val fullUrl = manga.url.withDomain()
|
|
||||||
val doc = loaderContext.httpGet("$fullUrl?section=info").parseHtml()
|
|
||||||
val root = doc.body().getElementById("main-page") ?: throw ParseException("Root not found")
|
|
||||||
val title = root.selectFirst("div.media-header__wrap")?.children()
|
|
||||||
val info = root.selectFirst("div.media-content")
|
|
||||||
val chaptersDoc = loaderContext.httpGet("$fullUrl?section=chapters").parseHtml()
|
|
||||||
val scripts = chaptersDoc.select("script")
|
|
||||||
val dateFormat = SimpleDateFormat("yyy-MM-dd", Locale.US)
|
|
||||||
var chapters: ArrayList<MangaChapter>? = null
|
|
||||||
scripts@ for (script in scripts) {
|
|
||||||
val raw = script.html().lines()
|
|
||||||
for (line in raw) {
|
|
||||||
if (line.startsWith("window.__DATA__")) {
|
|
||||||
val json = JSONObject(line.substringAfter('=').substringBeforeLast(';'))
|
|
||||||
val list = json.getJSONObject("chapters").getJSONArray("list")
|
|
||||||
val total = list.length()
|
|
||||||
chapters = ArrayList(total)
|
|
||||||
for (i in 0 until total) {
|
|
||||||
val item = list.getJSONObject(i)
|
|
||||||
val chapterId = item.getLong("chapter_id")
|
|
||||||
val scanlator = item.getStringOrNull("username")
|
|
||||||
val url = buildString {
|
|
||||||
append(manga.url)
|
|
||||||
append("/v")
|
|
||||||
append(item.getInt("chapter_volume"))
|
|
||||||
append("/c")
|
|
||||||
append(item.getString("chapter_number"))
|
|
||||||
@Suppress("BlockingMethodInNonBlockingContext") // lint issue
|
|
||||||
append('/')
|
|
||||||
append(item.optString("chapter_string"))
|
|
||||||
}
|
|
||||||
val nameChapter = item.getStringOrNull("chapter_name")
|
|
||||||
val volume = item.getInt("chapter_volume")
|
|
||||||
val number = item.getString("chapter_number")
|
|
||||||
val fullNameChapter = "Том $volume. Глава $number"
|
|
||||||
chapters.add(
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(chapterId),
|
|
||||||
url = url,
|
|
||||||
source = source,
|
|
||||||
number = total - i,
|
|
||||||
uploadDate = dateFormat.tryParse(
|
|
||||||
item.getString("chapter_created_at").substringBefore(" ")
|
|
||||||
),
|
|
||||||
scanlator = scanlator,
|
|
||||||
branch = null,
|
|
||||||
name = if (nameChapter.isNullOrBlank()) fullNameChapter else "$fullNameChapter - $nameChapter",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
chapters.reverse()
|
|
||||||
break@scripts
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return manga.copy(
|
|
||||||
title = title?.getOrNull(0)?.text()?.takeUnless(String::isBlank) ?: manga.title,
|
|
||||||
altTitle = title?.getOrNull(1)?.text()?.substringBefore('/')?.trim(),
|
|
||||||
rating = root.selectFirst("div.media-stats-item__score")
|
|
||||||
?.selectFirst("span")
|
|
||||||
?.text()?.toFloatOrNull()?.div(5f) ?: manga.rating,
|
|
||||||
author = info?.getElementsMatchingOwnText("Автор")?.firstOrNull()
|
|
||||||
?.nextElementSibling()?.text() ?: manga.author,
|
|
||||||
tags = info?.selectFirst("div.media-tags")
|
|
||||||
?.select("a.media-tag-item")?.mapToSet { a ->
|
|
||||||
MangaTag(
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
key = a.attr("href").substringAfterLast('='),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
} ?: manga.tags,
|
|
||||||
description = info?.selectFirst("div.media-description__text")?.html(),
|
|
||||||
chapters = chapters
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val fullUrl = chapter.url.withDomain()
|
|
||||||
val doc = loaderContext.httpGet(fullUrl).parseHtml()
|
|
||||||
if (doc.location().endsWith("/register")) {
|
|
||||||
throw AuthRequiredException(source)
|
|
||||||
}
|
|
||||||
val scripts = doc.head().select("script")
|
|
||||||
val pg = (doc.body().getElementById("pg")?.html() ?: parseFailed("Element #pg not found"))
|
|
||||||
.substringAfter('=')
|
|
||||||
.substringBeforeLast(';')
|
|
||||||
val pages = JSONArray(pg)
|
|
||||||
for (script in scripts) {
|
|
||||||
val raw = script.html().trim()
|
|
||||||
if (raw.contains("window.__info")) {
|
|
||||||
val json = JSONObject(
|
|
||||||
raw.substringAfter("window.__info")
|
|
||||||
.substringAfter('=')
|
|
||||||
.substringBeforeLast(';')
|
|
||||||
)
|
|
||||||
val domain = json.getJSONObject("servers").run {
|
|
||||||
getStringOrNull("main") ?: getString(
|
|
||||||
json.getJSONObject("img").getString("server")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
val url = json.getJSONObject("img").getString("url")
|
|
||||||
return pages.map { x ->
|
|
||||||
val pageUrl = "$domain/$url${x.getString("u")}"
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(pageUrl),
|
|
||||||
url = pageUrl,
|
|
||||||
preview = null,
|
|
||||||
referer = fullUrl,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw ParseException("Script with info not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val url = "https://${getDomain()}/manga-list"
|
|
||||||
val doc = loaderContext.httpGet(url).parseHtml()
|
|
||||||
val scripts = doc.body().select("script")
|
|
||||||
for (script in scripts) {
|
|
||||||
val raw = script.html().trim()
|
|
||||||
if (raw.startsWith("window.__DATA")) {
|
|
||||||
val json = JSONObject(raw.substringAfter('=').substringBeforeLast(';'))
|
|
||||||
val genres = json.getJSONObject("filters").getJSONArray("genres")
|
|
||||||
val result = ArraySet<MangaTag>(genres.length())
|
|
||||||
for (x in genres) {
|
|
||||||
result += MangaTag(
|
|
||||||
source = source,
|
|
||||||
key = x.getInt("id").toString(),
|
|
||||||
title = x.getString("name").toTitleCase(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw ParseException("Script with genres not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isAuthorized(): Boolean {
|
|
||||||
return loaderContext.cookieJar.getCookies(getDomain()).any {
|
|
||||||
it.name.startsWith("remember_web_")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getUsername(): String {
|
|
||||||
val body = loaderContext.httpGet("https://${getDomain()}/messages").parseHtml().body()
|
|
||||||
if (body.baseUri().endsWith("/login")) {
|
|
||||||
throw AuthRequiredException(source)
|
|
||||||
}
|
|
||||||
return body.selectFirst(".profile-user__username")?.text() ?: parseFailed("Cannot find username")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSortKey(sortOrder: SortOrder?) = when (sortOrder) {
|
|
||||||
SortOrder.RATING -> "desc&sort=rate"
|
|
||||||
SortOrder.ALPHABETICAL -> "asc&sort=name"
|
|
||||||
SortOrder.POPULARITY -> "desc&sort=views"
|
|
||||||
SortOrder.UPDATED -> "desc&sort=last_chapter_at"
|
|
||||||
SortOrder.NEWEST -> "desc&sort=created_at"
|
|
||||||
else -> "desc&sort=last_chapter_at"
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun search(query: String): List<Manga> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val json = loaderContext.httpGet("https://$domain/search?type=manga&q=$query")
|
|
||||||
.parseJsonArray()
|
|
||||||
return json.map { jo ->
|
|
||||||
val slug = jo.getString("slug")
|
|
||||||
val url = "/$slug"
|
|
||||||
val covers = jo.getJSONObject("covers")
|
|
||||||
Manga(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = url,
|
|
||||||
publicUrl = "https://$domain/$slug",
|
|
||||||
title = jo.getString("rus_name"),
|
|
||||||
altTitle = jo.getString("name"),
|
|
||||||
author = null,
|
|
||||||
tags = emptySet(),
|
|
||||||
rating = jo.getString("rate_avg")
|
|
||||||
.toFloatOrNull()?.div(5f) ?: Manga.NO_RATING,
|
|
||||||
state = null,
|
|
||||||
source = source,
|
|
||||||
coverUrl = covers.getString("thumbnail"),
|
|
||||||
largeCoverUrl = covers.getString("default")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,169 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import android.util.Base64
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class MangaOwlRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val source = MangaSource.MANGAOWL
|
|
||||||
|
|
||||||
override val defaultDomain = "mangaowls.com"
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
SortOrder.NEWEST,
|
|
||||||
SortOrder.UPDATED
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?,
|
|
||||||
): List<Manga> {
|
|
||||||
val page = (offset / 36f).toIntUp().inc()
|
|
||||||
val link = buildString {
|
|
||||||
append("https://")
|
|
||||||
append(getDomain())
|
|
||||||
when {
|
|
||||||
!query.isNullOrEmpty() -> {
|
|
||||||
append("/search/${page}?search=")
|
|
||||||
append(query.urlEncoded())
|
|
||||||
}
|
|
||||||
!tags.isNullOrEmpty() -> {
|
|
||||||
for (tag in tags) {
|
|
||||||
append(tag.key)
|
|
||||||
}
|
|
||||||
append("/${page}?type=${getAlternativeSortKey(sortOrder)}")
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
append("/${getSortKey(sortOrder)}/${page}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val doc = loaderContext.httpGet(link).parseHtml()
|
|
||||||
val slides = doc.body().select("ul.slides") ?: parseFailed("An error occurred while parsing")
|
|
||||||
val items = slides.select("div.col-md-2")
|
|
||||||
return items.mapNotNull { item ->
|
|
||||||
val href = item.selectFirst("h6 a")?.relUrl("href") ?: return@mapNotNull null
|
|
||||||
Manga(
|
|
||||||
id = generateUid(href),
|
|
||||||
title = item.selectFirst("h6 a")?.text() ?: return@mapNotNull null,
|
|
||||||
coverUrl = item.select("div.img-responsive").attr("abs:data-background-image"),
|
|
||||||
altTitle = null,
|
|
||||||
author = null,
|
|
||||||
rating = runCatching {
|
|
||||||
item.selectFirst("div.block-stars")
|
|
||||||
?.text()
|
|
||||||
?.toFloatOrNull()
|
|
||||||
?.div(10f)
|
|
||||||
}.getOrNull() ?: Manga.NO_RATING,
|
|
||||||
url = href,
|
|
||||||
publicUrl = href.withDomain(),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val doc = loaderContext.httpGet(manga.publicUrl).parseHtml()
|
|
||||||
val info = doc.body().selectFirst("div.single_detail") ?: parseFailed("An error occurred while parsing")
|
|
||||||
val table = doc.body().selectFirst("div.single-grid-right") ?: parseFailed("An error occurred while parsing")
|
|
||||||
val dateFormat = SimpleDateFormat("MM/dd/yyyy", Locale.US)
|
|
||||||
val trRegex = "window\\['tr'] = '([^']*)';".toRegex(RegexOption.IGNORE_CASE)
|
|
||||||
val trElement = doc.getElementsByTag("script").find { trRegex.find(it.data()) != null } ?: parseFailed("Oops, tr not found")
|
|
||||||
val tr = trRegex.find(trElement.data())!!.groups[1]!!.value
|
|
||||||
val s = Base64.encodeToString(defaultDomain.toByteArray(), Base64.NO_PADDING)
|
|
||||||
return manga.copy(
|
|
||||||
description = info.selectFirst(".description")?.html(),
|
|
||||||
largeCoverUrl = info.select("img").first()?.let { img ->
|
|
||||||
if (img.hasAttr("data-src")) img.attr("abs:data-src") else img.attr("abs:src")
|
|
||||||
},
|
|
||||||
author = info.selectFirst("p.fexi_header_para a.author_link")?.text(),
|
|
||||||
state = parseStatus(info.select("p.fexi_header_para:contains(status)").first()?.ownText()),
|
|
||||||
tags = manga.tags + info.select("div.col-xs-12.col-md-8.single-right-grid-right > p > a[href*=genres]")
|
|
||||||
.mapNotNull {
|
|
||||||
val a = it.selectFirst("a") ?: return@mapNotNull null
|
|
||||||
MangaTag(
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
key = a.attr("href"),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
},
|
|
||||||
chapters = table.select("div.table.table-chapter-list").select("li.list-group-item.chapter_list").asReversed().mapIndexed { i, li ->
|
|
||||||
val a = li.select("a")
|
|
||||||
val href = a.attr("data-href").ifEmpty {
|
|
||||||
parseFailed("Link is missing")
|
|
||||||
}
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(href),
|
|
||||||
name = a.select("label").text(),
|
|
||||||
number = i + 1,
|
|
||||||
url = "$href?tr=$tr&s=$s",
|
|
||||||
scanlator = null,
|
|
||||||
branch = null,
|
|
||||||
uploadDate = dateFormat.tryParse(li.selectFirst("small:last-of-type")?.text()),
|
|
||||||
source = MangaSource.MANGAOWL,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val fullUrl = chapter.url.withDomain()
|
|
||||||
val doc = loaderContext.httpGet(fullUrl).parseHtml()
|
|
||||||
val root = doc.body().select("div.item img.owl-lazy") ?: throw ParseException("Root not found")
|
|
||||||
return root.map { div ->
|
|
||||||
val url = div?.relUrl("data-src") ?: parseFailed("Page image not found")
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = url,
|
|
||||||
preview = null,
|
|
||||||
referer = url,
|
|
||||||
source = MangaSource.MANGAOWL,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseStatus(status: String?) = when {
|
|
||||||
status == null -> null
|
|
||||||
status.contains("Ongoing") -> MangaState.ONGOING
|
|
||||||
status.contains("Completed") -> MangaState.FINISHED
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val doc = loaderContext.httpGet("https://${getDomain()}/").parseHtml()
|
|
||||||
val root = doc.body().select("ul.dropdown-menu.multi-column.columns-3").select("li")
|
|
||||||
return root.mapToSet { p ->
|
|
||||||
val a = p.selectFirst("a") ?: parseFailed("a is null")
|
|
||||||
MangaTag(
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
key = a.attr("href"),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSortKey(sortOrder: SortOrder?) =
|
|
||||||
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {
|
|
||||||
SortOrder.POPULARITY -> "popular"
|
|
||||||
SortOrder.NEWEST -> "new_release"
|
|
||||||
SortOrder.UPDATED -> "lastest"
|
|
||||||
else -> "lastest"
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getAlternativeSortKey(sortOrder: SortOrder?) =
|
|
||||||
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {
|
|
||||||
SortOrder.POPULARITY -> "0"
|
|
||||||
SortOrder.NEWEST -> "2"
|
|
||||||
SortOrder.UPDATED -> "3"
|
|
||||||
else -> "3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,222 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.text.DateFormat
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class MangaTownRepository(loaderContext: MangaLoaderContext) :
|
|
||||||
RemoteMangaRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val source = MangaSource.MANGATOWN
|
|
||||||
|
|
||||||
override val defaultDomain = "www.mangatown.com"
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.ALPHABETICAL,
|
|
||||||
SortOrder.RATING,
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
SortOrder.UPDATED
|
|
||||||
)
|
|
||||||
|
|
||||||
private val regexTag = Regex("[^\\-]+-[^\\-]+-[^\\-]+-[^\\-]+-[^\\-]+-[^\\-]+")
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
val sortKey = when (sortOrder) {
|
|
||||||
SortOrder.ALPHABETICAL -> "?name.az"
|
|
||||||
SortOrder.RATING -> "?rating.za"
|
|
||||||
SortOrder.UPDATED -> "?last_chapter_time.za"
|
|
||||||
else -> ""
|
|
||||||
}
|
|
||||||
val page = (offset / 30) + 1
|
|
||||||
val url = when {
|
|
||||||
!query.isNullOrEmpty() -> {
|
|
||||||
if (offset != 0) {
|
|
||||||
return emptyList()
|
|
||||||
}
|
|
||||||
"/search?name=${query.urlEncoded()}".withDomain()
|
|
||||||
}
|
|
||||||
tags.isNullOrEmpty() -> "/directory/$page.htm$sortKey".withDomain()
|
|
||||||
tags.size == 1 -> "/directory/${tags.first().key}/$page.htm$sortKey".withDomain()
|
|
||||||
else -> tags.joinToString(
|
|
||||||
prefix = "/search?page=$page".withDomain()
|
|
||||||
) { tag ->
|
|
||||||
"&genres[${tag.key}]=1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val doc = loaderContext.httpGet(url).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("ul.manga_pic_list")
|
|
||||||
?: throw ParseException("Root not found")
|
|
||||||
return root.select("li").mapNotNull { li ->
|
|
||||||
val a = li.selectFirst("a.manga_cover")
|
|
||||||
val href = a?.relUrl("href")
|
|
||||||
?: return@mapNotNull null
|
|
||||||
val views = li.select("p.view")
|
|
||||||
val status = views.findOwnText { x -> x.startsWith("Status:") }
|
|
||||||
?.substringAfter(':')?.trim()?.lowercase(Locale.ROOT)
|
|
||||||
Manga(
|
|
||||||
id = generateUid(href),
|
|
||||||
title = a.attr("title"),
|
|
||||||
coverUrl = a.selectFirst("img")?.absUrl("src").orEmpty(),
|
|
||||||
source = MangaSource.MANGATOWN,
|
|
||||||
altTitle = null,
|
|
||||||
rating = li.selectFirst("p.score")?.selectFirst("b")
|
|
||||||
?.ownText()?.toFloatOrNull()?.div(5f) ?: Manga.NO_RATING,
|
|
||||||
author = views.findText { x -> x.startsWith("Author:") }?.substringAfter(':')
|
|
||||||
?.trim(),
|
|
||||||
state = when (status) {
|
|
||||||
"ongoing" -> MangaState.ONGOING
|
|
||||||
"completed" -> MangaState.FINISHED
|
|
||||||
else -> null
|
|
||||||
},
|
|
||||||
tags = li.selectFirst("p.keyWord")?.select("a")?.mapNotNullToSet tags@{ x ->
|
|
||||||
MangaTag(
|
|
||||||
title = x.attr("title").toTitleCase(),
|
|
||||||
key = x.attr("href").parseTagKey() ?: return@tags null,
|
|
||||||
source = MangaSource.MANGATOWN
|
|
||||||
)
|
|
||||||
}.orEmpty(),
|
|
||||||
url = href,
|
|
||||||
publicUrl = href.inContextOf(a)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val doc = loaderContext.httpGet(manga.url.withDomain()).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("section.main")
|
|
||||||
?.selectFirst("div.article_content") ?: throw ParseException("Cannot find root")
|
|
||||||
val info = root.selectFirst("div.detail_info")?.selectFirst("ul")
|
|
||||||
val chaptersList = root.selectFirst("div.chapter_content")
|
|
||||||
?.selectFirst("ul.chapter_list")?.select("li")?.asReversed()
|
|
||||||
val dateFormat = SimpleDateFormat("MMM dd,yyyy", Locale.US)
|
|
||||||
return manga.copy(
|
|
||||||
tags = manga.tags + info?.select("li")?.find { x ->
|
|
||||||
x.selectFirst("b")?.ownText() == "Genre(s):"
|
|
||||||
}?.select("a")?.mapNotNull { a ->
|
|
||||||
MangaTag(
|
|
||||||
title = a.attr("title").toTitleCase(),
|
|
||||||
key = a.attr("href").parseTagKey() ?: return@mapNotNull null,
|
|
||||||
source = MangaSource.MANGATOWN
|
|
||||||
)
|
|
||||||
}.orEmpty(),
|
|
||||||
description = info?.getElementById("show")?.ownText(),
|
|
||||||
chapters = chaptersList?.mapIndexedNotNull { i, li ->
|
|
||||||
val href = li.selectFirst("a")?.relUrl("href")
|
|
||||||
?: return@mapIndexedNotNull null
|
|
||||||
val name = li.select("span").filter { it.className().isEmpty() }
|
|
||||||
.joinToString(" - ") { it.text() }.trim()
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(href),
|
|
||||||
url = href,
|
|
||||||
source = MangaSource.MANGATOWN,
|
|
||||||
number = i + 1,
|
|
||||||
uploadDate = parseChapterDate(
|
|
||||||
dateFormat,
|
|
||||||
li.selectFirst("span.time")?.text()
|
|
||||||
),
|
|
||||||
name = name.ifEmpty { "${manga.title} - ${i + 1}" },
|
|
||||||
scanlator = null,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
} ?: bypassLicensedChapters(manga)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val fullUrl = chapter.url.withDomain()
|
|
||||||
val doc = loaderContext.httpGet(fullUrl).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("div.page_select")
|
|
||||||
?: throw ParseException("Cannot find root")
|
|
||||||
return root.selectFirst("select")?.select("option")?.mapNotNull {
|
|
||||||
val href = it.relUrl("value")
|
|
||||||
if (href.endsWith("featured.html")) {
|
|
||||||
return@mapNotNull null
|
|
||||||
}
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(href),
|
|
||||||
url = href,
|
|
||||||
preview = null,
|
|
||||||
referer = fullUrl,
|
|
||||||
source = MangaSource.MANGATOWN,
|
|
||||||
)
|
|
||||||
} ?: parseFailed("Pages list not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPageUrl(page: MangaPage): String {
|
|
||||||
val doc = loaderContext.httpGet(page.url.withDomain()).parseHtml()
|
|
||||||
return doc.getElementById("image")?.absUrl("src") ?: parseFailed("Image not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val doc = loaderContext.httpGet("/directory/".withDomain()).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("aside.right")
|
|
||||||
?.getElementsContainingOwnText("Genres")
|
|
||||||
?.first()
|
|
||||||
?.nextElementSibling() ?: parseFailed("Root not found")
|
|
||||||
return root.select("li").mapNotNullToSet { li ->
|
|
||||||
val a = li.selectFirst("a") ?: return@mapNotNullToSet null
|
|
||||||
val key = a.attr("href").parseTagKey()
|
|
||||||
if (key.isNullOrEmpty()) {
|
|
||||||
return@mapNotNullToSet null
|
|
||||||
}
|
|
||||||
MangaTag(
|
|
||||||
source = MangaSource.MANGATOWN,
|
|
||||||
key = key,
|
|
||||||
title = a.text().toTitleCase()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseChapterDate(dateFormat: DateFormat, date: String?): Long {
|
|
||||||
return when {
|
|
||||||
date.isNullOrEmpty() -> 0L
|
|
||||||
date.contains("Today") -> Calendar.getInstance().timeInMillis
|
|
||||||
date.contains("Yesterday") -> Calendar.getInstance().apply { add(Calendar.DAY_OF_MONTH, -1) }.timeInMillis
|
|
||||||
else -> dateFormat.tryParse(date)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreatePreferences(map: MutableMap<String, Any>) {
|
|
||||||
super.onCreatePreferences(map)
|
|
||||||
map[SourceSettings.KEY_USE_SSL] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun bypassLicensedChapters(manga: Manga): List<MangaChapter> {
|
|
||||||
val doc = loaderContext.httpGet(manga.url.withDomain("m")).parseHtml()
|
|
||||||
val list = doc.body().selectFirst("ul.detail-ch-list") ?: return emptyList()
|
|
||||||
val dateFormat = SimpleDateFormat("MMM dd,yyyy", Locale.US)
|
|
||||||
return list.select("li").asReversed().mapIndexedNotNull { i, li ->
|
|
||||||
val a = li.selectFirst("a") ?: return@mapIndexedNotNull null
|
|
||||||
val href = a.relUrl("href")
|
|
||||||
val name = a.selectFirst("span.vol")?.text().orEmpty().ifEmpty {
|
|
||||||
a.ownText()
|
|
||||||
}
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(href),
|
|
||||||
url = href,
|
|
||||||
source = MangaSource.MANGATOWN,
|
|
||||||
number = i + 1,
|
|
||||||
uploadDate = parseChapterDate(
|
|
||||||
dateFormat,
|
|
||||||
li.selectFirst("span.time")?.text()
|
|
||||||
),
|
|
||||||
name = name.ifEmpty { "${manga.title} - ${i + 1}" },
|
|
||||||
scanlator = null,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun String.parseTagKey() = split('/').findLast { regexTag matches it }
|
|
||||||
}
|
|
||||||
@ -1,242 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.WordSet
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.text.DateFormat
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
private const val PAGE_SIZE = 12
|
|
||||||
|
|
||||||
class MangareadRepository(
|
|
||||||
loaderContext: MangaLoaderContext
|
|
||||||
) : RemoteMangaRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val source = MangaSource.MANGAREAD
|
|
||||||
|
|
||||||
override val defaultDomain = "www.mangaread.org"
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.UPDATED,
|
|
||||||
SortOrder.POPULARITY
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
val tag = when {
|
|
||||||
tags.isNullOrEmpty() -> null
|
|
||||||
tags.size == 1 -> tags.first()
|
|
||||||
else -> throw NotImplementedError("Multiple genres are not supported by this source")
|
|
||||||
}
|
|
||||||
val payload = createRequestTemplate()
|
|
||||||
payload["page"] = (offset / PAGE_SIZE.toFloat()).toIntUp().toString()
|
|
||||||
payload["vars[meta_key]"] = when (sortOrder) {
|
|
||||||
SortOrder.POPULARITY -> "_wp_manga_views"
|
|
||||||
SortOrder.UPDATED -> "_latest_update"
|
|
||||||
else -> "_wp_manga_views"
|
|
||||||
}
|
|
||||||
payload["vars[wp-manga-genre]"] = tag?.key.orEmpty()
|
|
||||||
payload["vars[s]"] = query.orEmpty()
|
|
||||||
val doc = loaderContext.httpPost(
|
|
||||||
"https://${getDomain()}/wp-admin/admin-ajax.php",
|
|
||||||
payload
|
|
||||||
).parseHtml()
|
|
||||||
return doc.select("div.row.c-tabs-item__content").map { div ->
|
|
||||||
val href = div.selectFirst("a")?.relUrl("href")
|
|
||||||
?: parseFailed("Link not found")
|
|
||||||
val summary = div.selectFirst(".tab-summary")
|
|
||||||
Manga(
|
|
||||||
id = generateUid(href),
|
|
||||||
url = href,
|
|
||||||
publicUrl = href.inContextOf(div),
|
|
||||||
coverUrl = div.selectFirst("img")?.absUrl("data-src").orEmpty(),
|
|
||||||
title = summary?.selectFirst("h3")?.text().orEmpty(),
|
|
||||||
rating = div.selectFirst("span.total_votes")?.ownText()
|
|
||||||
?.toFloatOrNull()?.div(5f) ?: -1f,
|
|
||||||
tags = summary?.selectFirst(".mg_genres")?.select("a")?.mapToSet { a ->
|
|
||||||
MangaTag(
|
|
||||||
key = a.attr("href").removeSuffix("/").substringAfterLast('/'),
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
source = MangaSource.MANGAREAD
|
|
||||||
)
|
|
||||||
}.orEmpty(),
|
|
||||||
author = summary?.selectFirst(".mg_author")?.selectFirst("a")?.ownText(),
|
|
||||||
state = when (summary?.selectFirst(".mg_status")?.selectFirst(".summary-content")
|
|
||||||
?.ownText()?.trim()) {
|
|
||||||
"OnGoing" -> MangaState.ONGOING
|
|
||||||
"Completed" -> MangaState.FINISHED
|
|
||||||
else -> null
|
|
||||||
},
|
|
||||||
source = MangaSource.MANGAREAD
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val doc = loaderContext.httpGet("https://${getDomain()}/manga/").parseHtml()
|
|
||||||
val root = doc.body().selectFirst("header")
|
|
||||||
?.selectFirst("ul.second-menu") ?: parseFailed("Root not found")
|
|
||||||
return root.select("li").mapNotNullToSet { li ->
|
|
||||||
val a = li.selectFirst("a") ?: return@mapNotNullToSet null
|
|
||||||
val href = a.attr("href").removeSuffix("/")
|
|
||||||
.substringAfterLast("genres/", "")
|
|
||||||
if (href.isEmpty()) {
|
|
||||||
return@mapNotNullToSet null
|
|
||||||
}
|
|
||||||
MangaTag(
|
|
||||||
key = href,
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
source = MangaSource.MANGAREAD
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val fullUrl = manga.url.withDomain()
|
|
||||||
val doc = loaderContext.httpGet(fullUrl).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("div.profile-manga")
|
|
||||||
?.selectFirst("div.summary_content")
|
|
||||||
?.selectFirst("div.post-content")
|
|
||||||
?: throw ParseException("Root not found")
|
|
||||||
val root2 = doc.body().selectFirst("div.content-area")
|
|
||||||
?.selectFirst("div.c-page")
|
|
||||||
?: throw ParseException("Root2 not found")
|
|
||||||
val dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale.US)
|
|
||||||
return manga.copy(
|
|
||||||
tags = root.selectFirst("div.genres-content")?.select("a")
|
|
||||||
?.mapNotNullToSet { a ->
|
|
||||||
MangaTag(
|
|
||||||
key = a.attr("href").removeSuffix("/").substringAfterLast('/'),
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
source = MangaSource.MANGAREAD
|
|
||||||
)
|
|
||||||
} ?: manga.tags,
|
|
||||||
description = root2.selectFirst("div.description-summary")
|
|
||||||
?.selectFirst("div.summary__content")
|
|
||||||
?.select("p")
|
|
||||||
?.filterNot { it.ownText().startsWith("A brief description") }
|
|
||||||
?.joinToString { it.html() },
|
|
||||||
chapters = root2.select("li").asReversed().mapIndexed { i, li ->
|
|
||||||
val a = li.selectFirst("a")
|
|
||||||
val href = a?.relUrl("href").orEmpty().ifEmpty {
|
|
||||||
parseFailed("Link is missing")
|
|
||||||
}
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(href),
|
|
||||||
name = a!!.ownText(),
|
|
||||||
number = i + 1,
|
|
||||||
url = href,
|
|
||||||
uploadDate = parseChapterDate(
|
|
||||||
dateFormat,
|
|
||||||
li.selectFirst("span.chapter-release-date i")?.text()
|
|
||||||
),
|
|
||||||
source = MangaSource.MANGAREAD,
|
|
||||||
scanlator = null,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val fullUrl = chapter.url.withDomain()
|
|
||||||
val doc = loaderContext.httpGet(fullUrl).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("div.main-col-inner")
|
|
||||||
?.selectFirst("div.reading-content")
|
|
||||||
?: throw ParseException("Root not found")
|
|
||||||
return root.select("div.page-break").map { div ->
|
|
||||||
val img = div.selectFirst("img") ?: parseFailed("Page image not found")
|
|
||||||
val url = img.relUrl("data-src").ifEmpty {
|
|
||||||
img.relUrl("src")
|
|
||||||
}
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = url,
|
|
||||||
preview = null,
|
|
||||||
referer = fullUrl,
|
|
||||||
source = MangaSource.MANGAREAD,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseChapterDate(dateFormat: DateFormat, date: String?): Long {
|
|
||||||
|
|
||||||
date ?: return 0
|
|
||||||
return when {
|
|
||||||
date.endsWith(" ago", ignoreCase = true) -> {
|
|
||||||
parseRelativeDate(date)
|
|
||||||
}
|
|
||||||
// Handle translated 'ago' in Portuguese.
|
|
||||||
date.endsWith(" atrás", ignoreCase = true) -> {
|
|
||||||
parseRelativeDate(date)
|
|
||||||
}
|
|
||||||
// Handle translated 'ago' in Turkish.
|
|
||||||
date.endsWith(" önce", ignoreCase = true) -> {
|
|
||||||
parseRelativeDate(date)
|
|
||||||
}
|
|
||||||
// Handle 'yesterday' and 'today', using midnight
|
|
||||||
date.startsWith("year", ignoreCase = true) -> {
|
|
||||||
Calendar.getInstance().apply {
|
|
||||||
add(Calendar.DAY_OF_MONTH, -1) // yesterday
|
|
||||||
set(Calendar.HOUR_OF_DAY, 0)
|
|
||||||
set(Calendar.MINUTE, 0)
|
|
||||||
set(Calendar.SECOND, 0)
|
|
||||||
set(Calendar.MILLISECOND, 0)
|
|
||||||
}.timeInMillis
|
|
||||||
}
|
|
||||||
date.startsWith("today", ignoreCase = true) -> {
|
|
||||||
Calendar.getInstance().apply {
|
|
||||||
set(Calendar.HOUR_OF_DAY, 0)
|
|
||||||
set(Calendar.MINUTE, 0)
|
|
||||||
set(Calendar.SECOND, 0)
|
|
||||||
set(Calendar.MILLISECOND, 0)
|
|
||||||
}.timeInMillis
|
|
||||||
}
|
|
||||||
date.contains(Regex("""\d(st|nd|rd|th)""")) -> {
|
|
||||||
// Clean date (e.g. 5th December 2019 to 5 December 2019) before parsing it
|
|
||||||
date.split(" ").map {
|
|
||||||
if (it.contains(Regex("""\d\D\D"""))) {
|
|
||||||
it.replace(Regex("""\D"""), "")
|
|
||||||
} else {
|
|
||||||
it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.let { dateFormat.tryParse(it.joinToString(" ")) }
|
|
||||||
}
|
|
||||||
else -> dateFormat.tryParse(date)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parses dates in this form:
|
|
||||||
// 21 hours ago
|
|
||||||
private fun parseRelativeDate(date: String): Long {
|
|
||||||
val number = Regex("""(\d+)""").find(date)?.value?.toIntOrNull() ?: return 0
|
|
||||||
val cal = Calendar.getInstance()
|
|
||||||
|
|
||||||
return when {
|
|
||||||
WordSet("hari", "gün", "jour", "día", "dia", "day").anyWordIn(date) -> cal.apply { add(Calendar.DAY_OF_MONTH, -number) }.timeInMillis
|
|
||||||
WordSet("jam", "saat", "heure", "hora", "hour").anyWordIn(date) -> cal.apply { add(Calendar.HOUR, -number) }.timeInMillis
|
|
||||||
WordSet("menit", "dakika", "min", "minute", "minuto").anyWordIn(date) -> cal.apply { add(Calendar.MINUTE, -number) }.timeInMillis
|
|
||||||
WordSet("detik", "segundo", "second").anyWordIn(date) -> cal.apply { add(Calendar.SECOND, -number) }.timeInMillis
|
|
||||||
WordSet("month").anyWordIn(date) -> cal.apply { add(Calendar.MONTH, -number) }.timeInMillis
|
|
||||||
WordSet("year").anyWordIn(date) -> cal.apply { add(Calendar.YEAR, -number) }.timeInMillis
|
|
||||||
else -> 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createRequestTemplate() =
|
|
||||||
"action=madara_load_more&page=1&template=madara-core%2Fcontent%2Fcontent-search&vars%5Bs%5D=&vars%5Borderby%5D=meta_value_num&vars%5Bpaged%5D=1&vars%5Btemplate%5D=search&vars%5Bmeta_query%5D%5B0%5D%5Brelation%5D=AND&vars%5Bmeta_query%5D%5Brelation%5D=OR&vars%5Bpost_type%5D=wp-manga&vars%5Bpost_status%5D=publish&vars%5Bmeta_key%5D=_latest_update&vars%5Border%5D=desc&vars%5Bmanga_archives_item_layout%5D=default"
|
|
||||||
.split('&')
|
|
||||||
.map {
|
|
||||||
val pos = it.indexOf('=')
|
|
||||||
it.substring(0, pos) to it.substring(pos + 1)
|
|
||||||
}.toMutableMap()
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
|
|
||||||
class MintMangaRepository(loaderContext: MangaLoaderContext) : GroupleRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val source = MangaSource.MINTMANGA
|
|
||||||
override val defaultDomain: String = "mintmanga.live"
|
|
||||||
}
|
|
||||||
@ -1,251 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import okhttp3.Headers
|
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
private const val PAGE_SIZE = 26
|
|
||||||
|
|
||||||
abstract class NineMangaRepository(
|
|
||||||
loaderContext: MangaLoaderContext,
|
|
||||||
override val source: MangaSource,
|
|
||||||
override val defaultDomain: String,
|
|
||||||
) : RemoteMangaRepository(loaderContext) {
|
|
||||||
|
|
||||||
init {
|
|
||||||
loaderContext.cookieJar.insertCookies(getDomain(), "ninemanga_template_desk=yes")
|
|
||||||
}
|
|
||||||
|
|
||||||
private val headers = Headers.Builder()
|
|
||||||
.add("Accept-Language", "en-US;q=0.7,en;q=0.3")
|
|
||||||
.build()
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
val page = (offset / PAGE_SIZE.toFloat()).toIntUp() + 1
|
|
||||||
val url = buildString {
|
|
||||||
append("https://")
|
|
||||||
append(getDomain())
|
|
||||||
when {
|
|
||||||
!query.isNullOrEmpty() -> {
|
|
||||||
append("/search/?name_sel=&wd=")
|
|
||||||
append(query.urlEncoded())
|
|
||||||
append("&page=")
|
|
||||||
}
|
|
||||||
!tags.isNullOrEmpty() -> {
|
|
||||||
append("/search/?category_id=")
|
|
||||||
for (tag in tags) {
|
|
||||||
append(tag.key)
|
|
||||||
append(',')
|
|
||||||
}
|
|
||||||
append("&page=")
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
append("/category/index_")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
append(page)
|
|
||||||
append(".html")
|
|
||||||
}
|
|
||||||
val doc = loaderContext.httpGet(url, headers).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("ul.direlist")
|
|
||||||
?: throw ParseException("Cannot find root")
|
|
||||||
val baseHost = root.baseUri().toHttpUrl().host
|
|
||||||
return root.select("li").map { node ->
|
|
||||||
val href = node.selectFirst("a")?.absUrl("href")
|
|
||||||
?: parseFailed("Link not found")
|
|
||||||
val relUrl = href.toRelativeUrl(baseHost)
|
|
||||||
val dd = node.selectFirst("dd")
|
|
||||||
Manga(
|
|
||||||
id = generateUid(relUrl),
|
|
||||||
url = relUrl,
|
|
||||||
publicUrl = href,
|
|
||||||
title = dd?.selectFirst("a.bookname")?.text()?.toCamelCase().orEmpty(),
|
|
||||||
altTitle = null,
|
|
||||||
coverUrl = node.selectFirst("img")?.absUrl("src").orEmpty(),
|
|
||||||
rating = Manga.NO_RATING,
|
|
||||||
author = null,
|
|
||||||
tags = emptySet(),
|
|
||||||
state = null,
|
|
||||||
source = source,
|
|
||||||
description = dd?.selectFirst("p")?.html(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val doc = loaderContext.httpGet(
|
|
||||||
manga.url.withDomain() + "?waring=1",
|
|
||||||
headers
|
|
||||||
).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("div.manga")
|
|
||||||
?: throw ParseException("Cannot find root")
|
|
||||||
val infoRoot = root.selectFirst("div.bookintro")
|
|
||||||
?: throw ParseException("Cannot find info")
|
|
||||||
return manga.copy(
|
|
||||||
tags = infoRoot.getElementsByAttributeValue("itemprop", "genre").first()
|
|
||||||
?.select("a")?.mapToSet { a ->
|
|
||||||
MangaTag(
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
key = a.attr("href").substringBetween("/", "."),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}.orEmpty(),
|
|
||||||
author = infoRoot.getElementsByAttributeValue("itemprop", "author").first()?.text(),
|
|
||||||
state = parseStatus(infoRoot.select("li a.red").text()),
|
|
||||||
description = infoRoot.getElementsByAttributeValue("itemprop", "description").first()
|
|
||||||
?.html()?.substringAfter("</b>"),
|
|
||||||
chapters = root.selectFirst("div.chapterbox")?.select("ul.sub_vol_ul > li")
|
|
||||||
?.asReversed()?.mapIndexed { i, li ->
|
|
||||||
val a = li.selectFirst("a.chapter_list_a")
|
|
||||||
val href = a?.relUrl("href")?.replace("%20", " ") ?: parseFailed("Link not found")
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(href),
|
|
||||||
name = a.text(),
|
|
||||||
number = i + 1,
|
|
||||||
url = href,
|
|
||||||
uploadDate = parseChapterDateByLang(li.selectFirst("span")?.text().orEmpty()),
|
|
||||||
source = source,
|
|
||||||
scanlator = null,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val doc = loaderContext.httpGet(chapter.url.withDomain(), headers).parseHtml()
|
|
||||||
return doc.body().getElementById("page")?.select("option")?.map { option ->
|
|
||||||
val url = option.attr("value")
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = url,
|
|
||||||
referer = chapter.url.withDomain(),
|
|
||||||
preview = null,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
} ?: throw ParseException("Pages list not found at ${chapter.url}")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPageUrl(page: MangaPage): String {
|
|
||||||
val doc = loaderContext.httpGet(page.url.withDomain(), headers).parseHtml()
|
|
||||||
val root = doc.body()
|
|
||||||
return root.selectFirst("a.pic_download")?.absUrl("href")
|
|
||||||
?: throw ParseException("Page image not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val doc = loaderContext.httpGet("https://${getDomain()}/search/?type=high", headers)
|
|
||||||
.parseHtml()
|
|
||||||
val root = doc.body().getElementById("search_form")
|
|
||||||
return root?.select("li.cate_list")?.mapNotNullToSet { li ->
|
|
||||||
val cateId = li.attr("cate_id") ?: return@mapNotNullToSet null
|
|
||||||
val a = li.selectFirst("a") ?: return@mapNotNullToSet null
|
|
||||||
MangaTag(
|
|
||||||
title = a.text().toTitleCase(),
|
|
||||||
key = cateId,
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
} ?: parseFailed("Root not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseStatus(status: String) = when {
|
|
||||||
status.contains("Ongoing") -> MangaState.ONGOING
|
|
||||||
status.contains("Completed") -> MangaState.FINISHED
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseChapterDateByLang(date: String): Long {
|
|
||||||
val dateWords = date.split(" ")
|
|
||||||
|
|
||||||
if (dateWords.size == 3) {
|
|
||||||
if (dateWords[1].contains(",")) {
|
|
||||||
SimpleDateFormat("MMM d, yyyy", Locale.ENGLISH).tryParse(date)
|
|
||||||
} else {
|
|
||||||
val timeAgo = Integer.parseInt(dateWords[0])
|
|
||||||
return Calendar.getInstance().apply {
|
|
||||||
when (dateWords[1]) {
|
|
||||||
"minutes" -> Calendar.MINUTE // EN-FR
|
|
||||||
"hours" -> Calendar.HOUR // EN
|
|
||||||
|
|
||||||
"minutos" -> Calendar.MINUTE // ES
|
|
||||||
"horas" -> Calendar.HOUR
|
|
||||||
|
|
||||||
// "minutos" -> Calendar.MINUTE // BR
|
|
||||||
"hora" -> Calendar.HOUR
|
|
||||||
|
|
||||||
"минут" -> Calendar.MINUTE // RU
|
|
||||||
"часа" -> Calendar.HOUR
|
|
||||||
|
|
||||||
"Stunden" -> Calendar.HOUR // DE
|
|
||||||
|
|
||||||
"minuti" -> Calendar.MINUTE // IT
|
|
||||||
"ore" -> Calendar.HOUR
|
|
||||||
|
|
||||||
"heures" -> Calendar.HOUR // FR ("minutes" also French word)
|
|
||||||
else -> null
|
|
||||||
}?.let {
|
|
||||||
add(it, -timeAgo)
|
|
||||||
}
|
|
||||||
}.timeInMillis
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0L
|
|
||||||
}
|
|
||||||
|
|
||||||
class English(loaderContext: MangaLoaderContext) : NineMangaRepository(
|
|
||||||
loaderContext,
|
|
||||||
MangaSource.NINEMANGA_EN,
|
|
||||||
"www.ninemanga.com",
|
|
||||||
)
|
|
||||||
|
|
||||||
class Spanish(loaderContext: MangaLoaderContext) : NineMangaRepository(
|
|
||||||
loaderContext,
|
|
||||||
MangaSource.NINEMANGA_ES,
|
|
||||||
"es.ninemanga.com",
|
|
||||||
)
|
|
||||||
|
|
||||||
class Russian(loaderContext: MangaLoaderContext) : NineMangaRepository(
|
|
||||||
loaderContext,
|
|
||||||
MangaSource.NINEMANGA_RU,
|
|
||||||
"ru.ninemanga.com",
|
|
||||||
)
|
|
||||||
|
|
||||||
class Deutsch(loaderContext: MangaLoaderContext) : NineMangaRepository(
|
|
||||||
loaderContext,
|
|
||||||
MangaSource.NINEMANGA_DE,
|
|
||||||
"de.ninemanga.com",
|
|
||||||
)
|
|
||||||
|
|
||||||
class Brazil(loaderContext: MangaLoaderContext) : NineMangaRepository(
|
|
||||||
loaderContext,
|
|
||||||
MangaSource.NINEMANGA_BR,
|
|
||||||
"br.ninemanga.com",
|
|
||||||
)
|
|
||||||
|
|
||||||
class Italiano(loaderContext: MangaLoaderContext) : NineMangaRepository(
|
|
||||||
loaderContext,
|
|
||||||
MangaSource.NINEMANGA_IT,
|
|
||||||
"it.ninemanga.com",
|
|
||||||
)
|
|
||||||
|
|
||||||
class Francais(loaderContext: MangaLoaderContext) : NineMangaRepository(
|
|
||||||
loaderContext,
|
|
||||||
MangaSource.NINEMANGA_FR,
|
|
||||||
"fr.ninemanga.com",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,225 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import android.util.SparseArray
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.AuthRequiredException
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepositoryAuthProvider
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
import java.util.regex.Pattern
|
|
||||||
|
|
||||||
class NudeMoonRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(loaderContext),
|
|
||||||
MangaRepositoryAuthProvider {
|
|
||||||
|
|
||||||
override val source = MangaSource.NUDEMOON
|
|
||||||
override val defaultDomain = "nude-moon.net"
|
|
||||||
override val authUrl: String
|
|
||||||
get() = "https://${getDomain()}/index.php"
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.NEWEST,
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
SortOrder.RATING
|
|
||||||
)
|
|
||||||
|
|
||||||
private val pageUrlPatter = Pattern.compile(".*\\?page=[0-9]+$")
|
|
||||||
|
|
||||||
init {
|
|
||||||
loaderContext.cookieJar.insertCookies(
|
|
||||||
getDomain(),
|
|
||||||
"NMfYa=1;",
|
|
||||||
"nm_mobile=0;"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?
|
|
||||||
): List<Manga> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val url = when {
|
|
||||||
!query.isNullOrEmpty() -> "https://$domain/search?stext=${query.urlEncoded()}&rowstart=$offset"
|
|
||||||
!tags.isNullOrEmpty() -> tags.joinToString(
|
|
||||||
separator = "_",
|
|
||||||
prefix = "https://$domain/tags/",
|
|
||||||
postfix = "&rowstart=$offset",
|
|
||||||
transform = { it.key.urlEncoded() }
|
|
||||||
)
|
|
||||||
else -> "https://$domain/all_manga?${getSortKey(sortOrder)}&rowstart=$offset"
|
|
||||||
}
|
|
||||||
val doc = loaderContext.httpGet(url).parseHtml()
|
|
||||||
val root = doc.body().run {
|
|
||||||
selectFirst("td.main-bg") ?: selectFirst("td.main-body")
|
|
||||||
} ?: parseFailed("Cannot find root")
|
|
||||||
return root.select("table.news_pic2").mapNotNull { row ->
|
|
||||||
val a = row.selectFirst("td.bg_style1")?.selectFirst("a")
|
|
||||||
?: return@mapNotNull null
|
|
||||||
val href = a.relUrl("href")
|
|
||||||
val title = a.selectFirst("h2")?.text().orEmpty()
|
|
||||||
val info = row.selectFirst("td[width=100%]") ?: return@mapNotNull null
|
|
||||||
Manga(
|
|
||||||
id = generateUid(href),
|
|
||||||
url = href,
|
|
||||||
title = title.substringAfter(" / "),
|
|
||||||
altTitle = title.substringBefore(" / ", "")
|
|
||||||
.takeUnless { it.isBlank() },
|
|
||||||
author = info.getElementsContainingOwnText("Автор:").firstOrNull()
|
|
||||||
?.nextElementSibling()?.ownText(),
|
|
||||||
coverUrl = row.selectFirst("img.news_pic2")?.absUrl("data-src")
|
|
||||||
.orEmpty(),
|
|
||||||
tags = row.selectFirst("span.tag-links")?.select("a")
|
|
||||||
?.mapToSet {
|
|
||||||
MangaTag(
|
|
||||||
title = it.text().toTitleCase(),
|
|
||||||
key = it.attr("href").substringAfterLast('/'),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}.orEmpty(),
|
|
||||||
source = source,
|
|
||||||
publicUrl = a.absUrl("href"),
|
|
||||||
rating = Manga.NO_RATING,
|
|
||||||
isNsfw = true,
|
|
||||||
description = row.selectFirst("div.description")?.html(),
|
|
||||||
state = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val body = loaderContext.httpGet(manga.url.withDomain()).parseHtml().body()
|
|
||||||
val root = body.selectFirst("table.shoutbox")
|
|
||||||
?: parseFailed("Cannot find root")
|
|
||||||
val info = root.select("div.tbl2")
|
|
||||||
val lastInfo = info.last()
|
|
||||||
return manga.copy(
|
|
||||||
largeCoverUrl = body.selectFirst("img.news_pic2")?.absUrl("src"),
|
|
||||||
description = info.select("div.blockquote").lastOrNull()?.html() ?: manga.description,
|
|
||||||
tags = info.select("span.tag-links").firstOrNull()?.select("a")?.mapToSet {
|
|
||||||
MangaTag(
|
|
||||||
title = it.text().toTitleCase(),
|
|
||||||
key = it.attr("href").substringAfterLast('/'),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}?.plus(manga.tags) ?: manga.tags,
|
|
||||||
author = lastInfo?.getElementsByAttributeValueContaining("href", "mangaka/")?.text()
|
|
||||||
?: manga.author,
|
|
||||||
chapters = listOf(
|
|
||||||
MangaChapter(
|
|
||||||
id = manga.id,
|
|
||||||
url = manga.url,
|
|
||||||
source = source,
|
|
||||||
number = 1,
|
|
||||||
name = manga.title,
|
|
||||||
scanlator = lastInfo?.getElementsByAttributeValueContaining("href", "perevod/")?.text(),
|
|
||||||
uploadDate = lastInfo?.getElementsContainingOwnText("Дата:")
|
|
||||||
?.firstOrNull()
|
|
||||||
?.html()
|
|
||||||
?.parseDate() ?: 0L,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val fullUrl = chapter.url.withDomain()
|
|
||||||
val doc = loaderContext.httpGet(fullUrl).parseHtml()
|
|
||||||
val root = doc.body().selectFirst("td.main-body")
|
|
||||||
?: parseFailed("Cannot find root")
|
|
||||||
val readlink = root.selectFirst("table.shoutbox")?.selectFirst("a")?.absUrl("href")
|
|
||||||
?: parseFailed("Cannot obtain read link")
|
|
||||||
val fullPages = getFullPages(readlink)
|
|
||||||
return root.getElementsByAttributeValueMatching("href", pageUrlPatter).mapIndexedNotNull { i, a ->
|
|
||||||
val url = a.relUrl("href")
|
|
||||||
MangaPage(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = fullPages[i] ?: return@mapIndexedNotNull null,
|
|
||||||
referer = fullUrl,
|
|
||||||
preview = a.selectFirst("img")?.absUrl("src"),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val doc = loaderContext.httpGet("https://$domain/all_manga").parseHtml()
|
|
||||||
val root = doc.body().getElementsContainingOwnText("Поиск манги по тегам")
|
|
||||||
.firstOrNull()?.parents()?.find { it.tag().normalName() == "tbody" }
|
|
||||||
?.selectFirst("td.textbox")?.selectFirst("td.small")
|
|
||||||
?: parseFailed("Tags root not found")
|
|
||||||
return root.select("a").mapToSet {
|
|
||||||
MangaTag(
|
|
||||||
title = it.text().toTitleCase(),
|
|
||||||
key = it.attr("href").substringAfterLast('/')
|
|
||||||
.removeSuffix("+"),
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isAuthorized(): Boolean {
|
|
||||||
return loaderContext.cookieJar.getCookies(getDomain()).any {
|
|
||||||
it.name == "fusion_user"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getUsername(): String {
|
|
||||||
val body = loaderContext.httpGet("https://${getDomain()}/").parseHtml()
|
|
||||||
.body()
|
|
||||||
return body
|
|
||||||
.getElementsContainingOwnText("Профиль")
|
|
||||||
.firstOrNull()
|
|
||||||
?.attr("href")
|
|
||||||
?.substringAfterLast('/')
|
|
||||||
?: run {
|
|
||||||
throw if (body.selectFirst("form[name=\"loginform\"]") != null) {
|
|
||||||
AuthRequiredException(source)
|
|
||||||
} else {
|
|
||||||
ParseException("Cannot find username")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun getFullPages(url: String): SparseArray<String> {
|
|
||||||
val scripts = loaderContext.httpGet(url).parseHtml().select("script")
|
|
||||||
val regex = "images\\[(\\d+)].src = '([^']+)'".toRegex()
|
|
||||||
for (script in scripts) {
|
|
||||||
val src = script.html()
|
|
||||||
if (src.isEmpty()) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val matches = regex.findAll(src).toList()
|
|
||||||
if (matches.isEmpty()) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val result = SparseArray<String>(matches.size)
|
|
||||||
matches.forEach { match ->
|
|
||||||
val (index, link) = match.destructured
|
|
||||||
result.append(index.toInt(), link)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
parseFailed("Cannot find pages list")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSortKey(sortOrder: SortOrder?) =
|
|
||||||
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {
|
|
||||||
SortOrder.POPULARITY -> "views"
|
|
||||||
SortOrder.NEWEST -> "date"
|
|
||||||
SortOrder.RATING -> "like"
|
|
||||||
else -> "like"
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun String.parseDate(): Long {
|
|
||||||
val dateString = substringBetweenFirst("Дата:", "<")?.trim() ?: return 0
|
|
||||||
val dateFormat = SimpleDateFormat("d MMMM yyyy", Locale("ru"))
|
|
||||||
return dateFormat.tryParse(dateString)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
|
|
||||||
class ReadmangaRepository(loaderContext: MangaLoaderContext) : GroupleRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val defaultDomain = "readmanga.io"
|
|
||||||
override val source = MangaSource.READMANGA_RU
|
|
||||||
}
|
|
||||||
@ -1,258 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import okhttp3.Headers
|
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONException
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.*
|
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepositoryAuthProvider
|
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
|
||||||
import java.net.URLDecoder
|
|
||||||
import java.text.DateFormat
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
private const val PAGE_SIZE = 30
|
|
||||||
private const val STATUS_ONGOING = 1
|
|
||||||
private const val STATUS_FINISHED = 0
|
|
||||||
|
|
||||||
class RemangaRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(loaderContext),
|
|
||||||
MangaRepositoryAuthProvider {
|
|
||||||
|
|
||||||
override val source = MangaSource.REMANGA
|
|
||||||
|
|
||||||
override val defaultDomain = "remanga.org"
|
|
||||||
override val authUrl: String
|
|
||||||
get() = "https://${getDomain()}/user/login"
|
|
||||||
|
|
||||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
|
||||||
SortOrder.UPDATED,
|
|
||||||
SortOrder.POPULARITY,
|
|
||||||
SortOrder.RATING,
|
|
||||||
SortOrder.NEWEST
|
|
||||||
)
|
|
||||||
|
|
||||||
private val regexLastUrlPath = Regex("/[^/]+/?$")
|
|
||||||
|
|
||||||
override suspend fun getList2(
|
|
||||||
offset: Int,
|
|
||||||
query: String?,
|
|
||||||
tags: Set<MangaTag>?,
|
|
||||||
sortOrder: SortOrder?,
|
|
||||||
): List<Manga> {
|
|
||||||
copyCookies()
|
|
||||||
val domain = getDomain()
|
|
||||||
val urlBuilder = StringBuilder()
|
|
||||||
.append("https://api.")
|
|
||||||
.append(domain)
|
|
||||||
if (query != null) {
|
|
||||||
urlBuilder.append("/api/search/?query=")
|
|
||||||
.append(query.urlEncoded())
|
|
||||||
} else {
|
|
||||||
urlBuilder.append("/api/search/catalog/?ordering=")
|
|
||||||
.append(getSortKey(sortOrder))
|
|
||||||
tags?.forEach { tag ->
|
|
||||||
urlBuilder.append("&genres=")
|
|
||||||
urlBuilder.append(tag.key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
urlBuilder
|
|
||||||
.append("&page=")
|
|
||||||
.append((offset / PAGE_SIZE) + 1)
|
|
||||||
.append("&count=")
|
|
||||||
.append(PAGE_SIZE)
|
|
||||||
val content = loaderContext.httpGet(urlBuilder.toString(), getApiHeaders()).parseJson()
|
|
||||||
.getJSONArray("content")
|
|
||||||
return content.map { jo ->
|
|
||||||
val url = "/manga/${jo.getString("dir")}"
|
|
||||||
val img = jo.getJSONObject("img")
|
|
||||||
Manga(
|
|
||||||
id = generateUid(url),
|
|
||||||
url = url,
|
|
||||||
publicUrl = "https://$domain$url",
|
|
||||||
title = jo.getString("rus_name"),
|
|
||||||
altTitle = jo.getString("en_name"),
|
|
||||||
rating = jo.getString("avg_rating").toFloatOrNull()?.div(10f) ?: Manga.NO_RATING,
|
|
||||||
coverUrl = "https://api.$domain${img.getString("mid")}",
|
|
||||||
largeCoverUrl = "https://api.$domain${img.getString("high")}",
|
|
||||||
author = null,
|
|
||||||
tags = jo.optJSONArray("genres")?.mapToSet { g ->
|
|
||||||
MangaTag(
|
|
||||||
title = g.getString("name").toTitleCase(),
|
|
||||||
key = g.getInt("id").toString(),
|
|
||||||
source = MangaSource.REMANGA
|
|
||||||
)
|
|
||||||
}.orEmpty(),
|
|
||||||
source = MangaSource.REMANGA
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
copyCookies()
|
|
||||||
val domain = getDomain()
|
|
||||||
val slug = manga.url.find(regexLastUrlPath)
|
|
||||||
?: throw ParseException("Cannot obtain slug from ${manga.url}")
|
|
||||||
val data = loaderContext.httpGet(
|
|
||||||
url = "https://api.$domain/api/titles/$slug/",
|
|
||||||
headers = getApiHeaders(),
|
|
||||||
).parseJson()
|
|
||||||
val content = try {
|
|
||||||
data.getJSONObject("content")
|
|
||||||
} catch (e: JSONException) {
|
|
||||||
throw ParseException(data.optString("msg"), e)
|
|
||||||
}
|
|
||||||
val branchId = content.getJSONArray("branches").optJSONObject(0)
|
|
||||||
?.getLong("id") ?: throw ParseException("No branches found")
|
|
||||||
val chapters = grabChapters(domain, branchId)
|
|
||||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US)
|
|
||||||
return manga.copy(
|
|
||||||
description = content.getString("description"),
|
|
||||||
state = when (content.optJSONObject("status")?.getInt("id")) {
|
|
||||||
STATUS_ONGOING -> MangaState.ONGOING
|
|
||||||
STATUS_FINISHED -> MangaState.FINISHED
|
|
||||||
else -> null
|
|
||||||
},
|
|
||||||
tags = content.getJSONArray("genres").mapToSet { g ->
|
|
||||||
MangaTag(
|
|
||||||
title = g.getString("name").toTitleCase(),
|
|
||||||
key = g.getInt("id").toString(),
|
|
||||||
source = MangaSource.REMANGA
|
|
||||||
)
|
|
||||||
},
|
|
||||||
chapters = chapters.mapIndexed { i, jo ->
|
|
||||||
val id = jo.getLong("id")
|
|
||||||
val name = jo.getString("name").toTitleCase(Locale.ROOT)
|
|
||||||
val publishers = jo.optJSONArray("publishers")
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(id),
|
|
||||||
url = "/api/titles/chapters/$id/",
|
|
||||||
number = chapters.size - i,
|
|
||||||
name = buildString {
|
|
||||||
append("Том ")
|
|
||||||
append(jo.optString("tome", "0"))
|
|
||||||
append(". ")
|
|
||||||
append("Глава ")
|
|
||||||
append(jo.optString("chapter", "0"))
|
|
||||||
if (name.isNotEmpty()) {
|
|
||||||
append(" - ")
|
|
||||||
append(name)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
uploadDate = dateFormat.tryParse(jo.getString("upload_date")),
|
|
||||||
scanlator = publishers?.optJSONObject(0)?.getStringOrNull("name"),
|
|
||||||
source = MangaSource.REMANGA,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
}.asReversed()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
||||||
val referer = "https://${getDomain()}/"
|
|
||||||
val content = loaderContext.httpGet(chapter.url.withDomain(subdomain = "api"), getApiHeaders()).parseJson()
|
|
||||||
.getJSONObject("content")
|
|
||||||
val pages = content.optJSONArray("pages")
|
|
||||||
if (pages == null) {
|
|
||||||
val pubDate = content.getStringOrNull("pub_date")?.let {
|
|
||||||
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US).tryParse(it)
|
|
||||||
}
|
|
||||||
if (pubDate != null && pubDate > System.currentTimeMillis()) {
|
|
||||||
val at = SimpleDateFormat.getDateInstance(DateFormat.LONG).format(Date(pubDate))
|
|
||||||
parseFailed("Глава станет доступной $at")
|
|
||||||
} else {
|
|
||||||
parseFailed("Глава недоступна")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val result = ArrayList<MangaPage>(pages.length())
|
|
||||||
for (i in 0 until pages.length()) {
|
|
||||||
when (val item = pages.get(i)) {
|
|
||||||
is JSONObject -> result += parsePage(item, referer)
|
|
||||||
is JSONArray -> item.mapTo(result) { parsePage(it, referer) }
|
|
||||||
else -> throw ParseException("Unknown json item $item")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getTags(): Set<MangaTag> {
|
|
||||||
val domain = getDomain()
|
|
||||||
val content = loaderContext.httpGet("https://api.$domain/api/forms/titles/?get=genres", getApiHeaders())
|
|
||||||
.parseJson().getJSONObject("content").getJSONArray("genres")
|
|
||||||
return content.mapToSet { jo ->
|
|
||||||
MangaTag(
|
|
||||||
title = jo.getString("name").toTitleCase(),
|
|
||||||
key = jo.getInt("id").toString(),
|
|
||||||
source = source
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isAuthorized(): Boolean {
|
|
||||||
return loaderContext.cookieJar.getCookies(getDomain()).any {
|
|
||||||
it.name == "user"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getUsername(): String {
|
|
||||||
val jo = loaderContext.httpGet(
|
|
||||||
url = "https://api.${getDomain()}/api/users/current/",
|
|
||||||
headers = getApiHeaders(),
|
|
||||||
).parseJson()
|
|
||||||
return jo.getJSONObject("content").getString("username")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getApiHeaders(): Headers? {
|
|
||||||
val userCookie = loaderContext.cookieJar.getCookies(getDomain()).find {
|
|
||||||
it.name == "user"
|
|
||||||
} ?: return null
|
|
||||||
val jo = JSONObject(URLDecoder.decode(userCookie.value, Charsets.UTF_8.name()))
|
|
||||||
val accessToken = jo.getStringOrNull("access_token") ?: return null
|
|
||||||
return Headers.headersOf("authorization", "bearer $accessToken")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun copyCookies() {
|
|
||||||
val domain = getDomain()
|
|
||||||
loaderContext.cookieJar.copyCookies(domain, "api.$domain")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSortKey(order: SortOrder?) = when (order) {
|
|
||||||
SortOrder.UPDATED -> "-chapter_date"
|
|
||||||
SortOrder.POPULARITY -> "-rating"
|
|
||||||
SortOrder.RATING -> "-votes"
|
|
||||||
SortOrder.NEWEST -> "-id"
|
|
||||||
else -> "-chapter_date"
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parsePage(jo: JSONObject, referer: String) = MangaPage(
|
|
||||||
id = generateUid(jo.getLong("id")),
|
|
||||||
url = jo.getString("link"),
|
|
||||||
preview = null,
|
|
||||||
referer = referer,
|
|
||||||
source = source,
|
|
||||||
)
|
|
||||||
|
|
||||||
private suspend fun grabChapters(domain: String, branchId: Long): List<JSONObject> {
|
|
||||||
val result = ArrayList<JSONObject>(100)
|
|
||||||
var page = 1
|
|
||||||
while (true) {
|
|
||||||
val content = loaderContext.httpGet(
|
|
||||||
url = "https://api.$domain/api/titles/chapters/?branch_id=$branchId&page=$page&count=100",
|
|
||||||
headers = getApiHeaders(),
|
|
||||||
).parseJson().getJSONArray("content")
|
|
||||||
val len = content.length()
|
|
||||||
if (len == 0) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
result.ensureCapacity(result.size + len)
|
|
||||||
for (i in 0 until len) {
|
|
||||||
result.add(content.getJSONObject(i))
|
|
||||||
}
|
|
||||||
page++
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
|
|
||||||
class SelfMangaRepository(loaderContext: MangaLoaderContext) : GroupleRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val defaultDomain = "selfmanga.live"
|
|
||||||
override val source = MangaSource.SELFMANGA
|
|
||||||
}
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
|
||||||
import org.koitharu.kotatsu.core.model.Manga
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaChapter
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
import org.koitharu.kotatsu.utils.ext.parseHtml
|
|
||||||
import org.koitharu.kotatsu.utils.ext.relUrl
|
|
||||||
|
|
||||||
class YaoiChanRepository(loaderContext: MangaLoaderContext) : ChanRepository(loaderContext) {
|
|
||||||
|
|
||||||
override val source = MangaSource.YAOICHAN
|
|
||||||
override val defaultDomain = "yaoi-chan.me"
|
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
|
||||||
val doc = loaderContext.httpGet(manga.url.withDomain()).parseHtml()
|
|
||||||
val root =
|
|
||||||
doc.body().getElementById("dle-content") ?: throw ParseException("Cannot find root")
|
|
||||||
return manga.copy(
|
|
||||||
description = root.getElementById("description")?.html()?.substringBeforeLast("<div"),
|
|
||||||
largeCoverUrl = root.getElementById("cover")?.absUrl("src"),
|
|
||||||
chapters = root.select("table.table_cha").flatMap { table ->
|
|
||||||
table.select("div.manga")
|
|
||||||
}.mapNotNull { it.selectFirst("a") }.reversed().mapIndexed { i, a ->
|
|
||||||
val href = a.relUrl("href")
|
|
||||||
MangaChapter(
|
|
||||||
id = generateUid(href),
|
|
||||||
name = a.text().trim(),
|
|
||||||
number = i + 1,
|
|
||||||
url = href,
|
|
||||||
uploadDate = 0L,
|
|
||||||
source = source,
|
|
||||||
scanlator = null,
|
|
||||||
branch = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,32 +1,29 @@
|
|||||||
package org.koitharu.kotatsu.core.prefs
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import androidx.core.content.edit
|
||||||
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||||
interface SourceSettings {
|
import org.koitharu.kotatsu.parsers.config.MangaSourceConfig
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
fun getDomain(defaultValue: String): String
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getEnumValue
|
||||||
fun isUseSsl(defaultValue: Boolean): Boolean
|
import org.koitharu.kotatsu.utils.ext.ifNullOrEmpty
|
||||||
|
import org.koitharu.kotatsu.utils.ext.putEnumValue
|
||||||
private class PrefSourceSettings(context: Context, source: MangaSource) : SourceSettings {
|
|
||||||
|
private const val KEY_SORT_ORDER = "sort_order"
|
||||||
private val prefs = context.getSharedPreferences(source.name, Context.MODE_PRIVATE)
|
|
||||||
|
class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig {
|
||||||
override fun getDomain(defaultValue: String) = prefs.getString(KEY_DOMAIN, defaultValue)
|
|
||||||
?.takeUnless(String::isBlank)
|
private val prefs = context.getSharedPreferences(source.name, Context.MODE_PRIVATE)
|
||||||
?: defaultValue
|
|
||||||
|
var defaultSortOrder: SortOrder?
|
||||||
override fun isUseSsl(defaultValue: Boolean) = prefs.getBoolean(KEY_USE_SSL, defaultValue)
|
get() = prefs.getEnumValue(KEY_SORT_ORDER, SortOrder::class.java)
|
||||||
}
|
set(value) = prefs.edit { putEnumValue(KEY_SORT_ORDER, value) }
|
||||||
|
|
||||||
companion object {
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
override fun <T> get(key: ConfigKey<T>): T {
|
||||||
operator fun invoke(context: Context, source: MangaSource): SourceSettings =
|
return when (key) {
|
||||||
PrefSourceSettings(context, source)
|
is ConfigKey.Domain -> prefs.getString(key.key, key.defaultValue).ifNullOrEmpty { key.defaultValue }
|
||||||
|
} as T
|
||||||
const val KEY_DOMAIN = "domain"
|
|
||||||
const val KEY_USE_SSL = "ssl"
|
|
||||||
const val KEY_AUTH = "auth"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue