Replace usage of Gson in MMRCMSJsonGen and update Zahard URL (#10084)
This commit is contained in:
parent
6a1b3ae515
commit
ca096808f3
@ -10,7 +10,6 @@ dependencies {
|
|||||||
compileOnly 'com.squareup.okhttp3:okhttp:4.9.1'
|
compileOnly 'com.squareup.okhttp3:okhttp:4.9.1'
|
||||||
compileOnly 'io.reactivex:rxjava:1.3.8'
|
compileOnly 'io.reactivex:rxjava:1.3.8'
|
||||||
compileOnly 'org.jsoup:jsoup:1.13.1'
|
compileOnly 'org.jsoup:jsoup:1.13.1'
|
||||||
compileOnly 'com.google.code.gson:gson:2.8.6'
|
|
||||||
compileOnly 'org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.2.0'
|
compileOnly 'org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.2.0'
|
||||||
compileOnly 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.0'
|
compileOnly 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.0'
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import java.io.InputStreamReader
|
|||||||
plugins {
|
plugins {
|
||||||
id("com.android.library")
|
id("com.android.library")
|
||||||
kotlin("android")
|
kotlin("android")
|
||||||
|
id("kotlinx-serialization")
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
|
@ -79,11 +79,7 @@ abstract class MMRCMS(
|
|||||||
override val supportsLatest = jsonObject["supports_latest"]!!.jsonPrimitive.boolean
|
override val supportsLatest = jsonObject["supports_latest"]!!.jsonPrimitive.boolean
|
||||||
open val itemUrl = jsonObject["item_url"]!!.jsonPrimitive.content
|
open val itemUrl = jsonObject["item_url"]!!.jsonPrimitive.content
|
||||||
open val categoryMappings = mapToPairs(jsonObject["categories"]!!.jsonArray)
|
open val categoryMappings = mapToPairs(jsonObject["categories"]!!.jsonArray)
|
||||||
open var tagMappings = if (jsonObject["tags"] is JsonArray) {
|
open var tagMappings = jsonObject["tags"]?.jsonArray?.let { mapToPairs(it) } ?: emptyList()
|
||||||
mapToPairs(jsonObject["tags"]!!.jsonArray)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map an array of JSON objects to pairs. Each JSON object must have
|
* Map an array of JSON objects to pairs. Each JSON object must have
|
||||||
|
@ -3,8 +3,10 @@ package eu.kanade.tachiyomi.multisrc.mmrcms
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import com.google.gson.Gson
|
|
||||||
import eu.kanade.tachiyomi.multisrc.mmrcms.MMRCMSSources.Companion.sourceList
|
import eu.kanade.tachiyomi.multisrc.mmrcms.MMRCMSSources.Companion.sourceList
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
@ -24,7 +26,6 @@ import javax.net.ssl.X509TrustManager
|
|||||||
*
|
*
|
||||||
* CMS: https://getcyberworks.com/product/manga-reader-cms/
|
* CMS: https://getcyberworks.com/product/manga-reader-cms/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class MMRCMSJsonGen {
|
class MMRCMSJsonGen {
|
||||||
// private var preRunTotal: String
|
// private var preRunTotal: String
|
||||||
|
|
||||||
@ -40,18 +41,12 @@ class MMRCMSJsonGen {
|
|||||||
val formattedDate = dateTime.format(DateTimeFormatter.RFC_1123_DATE_TIME)
|
val formattedDate = dateTime.format(DateTimeFormatter.RFC_1123_DATE_TIME)
|
||||||
buffer.append("package eu.kanade.tachiyomi.multisrc.mmrcms")
|
buffer.append("package eu.kanade.tachiyomi.multisrc.mmrcms")
|
||||||
buffer.append("\n\n// GENERATED FILE, DO NOT MODIFY!\n// Generated $formattedDate\n\n")
|
buffer.append("\n\n// GENERATED FILE, DO NOT MODIFY!\n// Generated $formattedDate\n\n")
|
||||||
buffer.append("class SourceData() {\n")
|
buffer.append("object SourceData {\n")
|
||||||
buffer.append(" companion object {\n")
|
buffer.append(" fun giveMetaData(url: String) = when (url) {\n")
|
||||||
buffer.append(" fun giveMetaData(url:String): String{\n")
|
|
||||||
buffer.append(" return when (url) {\n")
|
|
||||||
var number = 1
|
var number = 1
|
||||||
sources.forEach {
|
sources.forEach {
|
||||||
|
println("Generating ${it.name}")
|
||||||
try {
|
try {
|
||||||
val map = mutableMapOf<String, Any>()
|
|
||||||
map["name"] = it.name
|
|
||||||
map["base_url"] = it.baseUrl
|
|
||||||
map["supports_latest"] = supportsLatest(it.baseUrl)
|
|
||||||
|
|
||||||
val advancedSearchDocument = getDocument("${it.baseUrl}/advanced-search", false)
|
val advancedSearchDocument = getDocument("${it.baseUrl}/advanced-search", false)
|
||||||
|
|
||||||
var parseCategories = mutableListOf<Map<String, String>>()
|
var parseCategories = mutableListOf<Map<String, String>>()
|
||||||
@ -76,35 +71,35 @@ class MMRCMSJsonGen {
|
|||||||
if (parseCategories.isEmpty()) {
|
if (parseCategories.isEmpty()) {
|
||||||
parseCategories = parseCategories(mangaListDocument)
|
parseCategories = parseCategories(mangaListDocument)
|
||||||
}
|
}
|
||||||
map["item_url"] = "$itemUrl/"
|
|
||||||
map["categories"] = parseCategories
|
|
||||||
val tags = parseTags(mangaListDocument)
|
val tags = parseTags(mangaListDocument)
|
||||||
map["tags"] = "null"
|
|
||||||
if (tags.size in 1..49) {
|
val source = SourceDataModel(
|
||||||
map["tags"] = tags
|
name = it.name,
|
||||||
}
|
base_url = it.baseUrl,
|
||||||
|
supports_latest = supportsLatest(it.baseUrl),
|
||||||
|
item_url = "$itemUrl/",
|
||||||
|
categories = parseCategories,
|
||||||
|
tags = if (tags.size in 1..49) tags else null,
|
||||||
|
)
|
||||||
|
|
||||||
if (!itemUrl.startsWith(it.baseUrl)) println("**Note: ${it.name} URL does not match! Check for changes: \n ${it.baseUrl} vs $itemUrl")
|
if (!itemUrl.startsWith(it.baseUrl)) println("**Note: ${it.name} URL does not match! Check for changes: \n ${it.baseUrl} vs $itemUrl")
|
||||||
|
|
||||||
val toJson = Gson().toJson(map)
|
buffer.append(" \"${it.baseUrl}\" -> \"\"\"${Json.encodeToString(source)}\"\"\"\n")
|
||||||
|
|
||||||
buffer.append(" \"${it.baseUrl}\" -> \"\"\"$toJson\"\"\"\n")
|
|
||||||
number++
|
number++
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
println("error generating source ${it.name} ${e.printStackTrace()}")
|
println("error generating source ${it.name} ${e.printStackTrace()}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.append(" else -> \"\"\n")
|
buffer.append(" else -> \"\"\n")
|
||||||
buffer.append(" }\n")
|
|
||||||
buffer.append(" }\n")
|
|
||||||
buffer.append(" }\n")
|
buffer.append(" }\n")
|
||||||
buffer.append("}\n")
|
buffer.append("}\n")
|
||||||
// println("Pre-run sources: $preRunTotal")
|
// println("Pre-run sources: $preRunTotal")
|
||||||
println("Post-run sources: ${number - 1}")
|
println("Post-run sources: ${number - 1}")
|
||||||
val writer = PrintWriter(relativePath)
|
PrintWriter(relativePath).use {
|
||||||
writer.write(buffer.toString())
|
it.write(buffer.toString())
|
||||||
writer.close()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDocument(url: String, printStackTrace: Boolean = true): Document? {
|
private fun getDocument(url: String, printStackTrace: Boolean = true): Document? {
|
||||||
@ -139,20 +134,14 @@ class MMRCMSJsonGen {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseTags(mangaListDocument: Document): MutableList<Map<String, String>> {
|
private fun parseTags(mangaListDocument: Document): List<Map<String, String>> {
|
||||||
val elements = mangaListDocument.select("div.tag-links a")
|
val elements = mangaListDocument.select("div.tag-links a")
|
||||||
|
return elements.map {
|
||||||
if (elements.isEmpty()) {
|
mapOf(
|
||||||
return mutableListOf()
|
"id" to it.attr("href").substringAfterLast("/"),
|
||||||
|
"name" to it.text(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
val array = mutableListOf<Map<String, String>>()
|
|
||||||
elements.forEach {
|
|
||||||
val map = mutableMapOf<String, String>()
|
|
||||||
map["id"] = it.attr("href").substringAfterLast("/")
|
|
||||||
map["name"] = it.text()
|
|
||||||
array.add(map)
|
|
||||||
}
|
|
||||||
return array
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getItemUrl(document: Document?, url: String): String {
|
private fun getItemUrl(document: Document?, url: String): String {
|
||||||
@ -169,24 +158,18 @@ class MMRCMSJsonGen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun parseCategories(document: Document): MutableList<Map<String, String>> {
|
private fun parseCategories(document: Document): MutableList<Map<String, String>> {
|
||||||
val array = mutableListOf<Map<String, String>>()
|
|
||||||
val elements = document.select("select[name^=categories] option, a.category")
|
val elements = document.select("select[name^=categories] option, a.category")
|
||||||
if (elements.size == 0) {
|
return elements.mapIndexed { index, element ->
|
||||||
return mutableListOf()
|
mapOf(
|
||||||
}
|
"id" to (index + 1).toString(),
|
||||||
var id = 1
|
"name" to element.text(),
|
||||||
elements.forEach {
|
)
|
||||||
val map = mutableMapOf<String, String>()
|
}.toMutableList()
|
||||||
map["id"] = id.toString()
|
|
||||||
map["name"] = it.text()
|
|
||||||
array.add(map)
|
|
||||||
id++
|
|
||||||
}
|
|
||||||
return array
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
private fun getOkHttpClient(): OkHttpClient {
|
private fun getOkHttpClient(): OkHttpClient {
|
||||||
|
// Create all-trusting host name verifier
|
||||||
val trustAllCerts = arrayOf<TrustManager>(
|
val trustAllCerts = arrayOf<TrustManager>(
|
||||||
object : X509TrustManager {
|
object : X509TrustManager {
|
||||||
@SuppressLint("TrustAllX509TrustManager")
|
@SuppressLint("TrustAllX509TrustManager")
|
||||||
@ -206,14 +189,11 @@ class MMRCMSJsonGen {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Install the all-trusting trust manager
|
// Install the all-trusting trust manager
|
||||||
|
val sc = SSLContext.getInstance("SSL").apply {
|
||||||
val sc = SSLContext.getInstance("SSL")
|
init(null, trustAllCerts, java.security.SecureRandom())
|
||||||
sc.init(null, trustAllCerts, java.security.SecureRandom())
|
}
|
||||||
val sslSocketFactory = sc.socketFactory
|
val sslSocketFactory = sc.socketFactory
|
||||||
|
|
||||||
// Create all-trusting host name verifier
|
|
||||||
// Install the all-trusting host verifier
|
|
||||||
|
|
||||||
return OkHttpClient.Builder()
|
return OkHttpClient.Builder()
|
||||||
.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
||||||
.hostnameVerifier { _, _ -> true }
|
.hostnameVerifier { _, _ -> true }
|
||||||
@ -223,6 +203,16 @@ class MMRCMSJsonGen {
|
|||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
private data class SourceDataModel(
|
||||||
|
val name: String,
|
||||||
|
val base_url: String,
|
||||||
|
val supports_latest: Boolean,
|
||||||
|
val item_url: String,
|
||||||
|
val categories: List<Map<String, String>>,
|
||||||
|
val tags: List<Map<String, String>>? = null,
|
||||||
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val sources = sourceList
|
val sources = sourceList
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class MMRCMSSources {
|
|||||||
SourceData.Single("مانجا اون لاين", "https://onma.me", "ar", className = "onma"),
|
SourceData.Single("مانجا اون لاين", "https://onma.me", "ar", className = "onma"),
|
||||||
SourceData.Single("Read Comics Online", "https://readcomicsonline.ru", "en"),
|
SourceData.Single("Read Comics Online", "https://readcomicsonline.ru", "en"),
|
||||||
SourceData.Single("Fallen Angels", "https://manga.fascans.com", "en", overrideVersionCode = 2),
|
SourceData.Single("Fallen Angels", "https://manga.fascans.com", "en", overrideVersionCode = 2),
|
||||||
SourceData.Single("Zahard", "https://zahard.top", "en", overrideVersionCode = 1),
|
SourceData.Single("Zahard", "https://zahard.xyz", "en", overrideVersionCode = 2),
|
||||||
SourceData.Single("Manhwas Men", "https://manhwas.men", "en", isNsfw = true, overrideVersionCode = 1),
|
SourceData.Single("Manhwas Men", "https://manhwas.men", "en", isNsfw = true, overrideVersionCode = 1),
|
||||||
SourceData.Single("Scan FR", "https://www.scan-fr.cc", "fr"),
|
SourceData.Single("Scan FR", "https://www.scan-fr.cc", "fr"),
|
||||||
SourceData.Single("Scan VF", "https://www.scan-vf.net", "fr"),
|
SourceData.Single("Scan VF", "https://www.scan-vf.net", "fr"),
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user