Skip to content

Commit

Permalink
[feature]支持DoH;此版本不再内置默认数据源,使用此APP需手动选择自定义数据源
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Dec 5, 2021
1 parent e3af1c8 commit 712fdfe
Show file tree
Hide file tree
Showing 82 changed files with 1,683 additions and 1,037 deletions.
13 changes: 13 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

----

## [>>自定义数据源<<](doc/customdatasource/README.md)

## [>>必看安全说明<<](#安全说明)

## [>>关于http网站或数据源的安全问题<<](doc/about_http_security.md)
Expand Down
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ android.defaultConfig {
secret.shieldTextList.forEach({ k, v ->
buildConfigField("String[]", k, v)
})
secret.dataSource.forEach({ k, v ->
buildConfigField("String", k, "\"${v}\"")
})
}

android {
Expand Down Expand Up @@ -147,6 +150,7 @@ dependencies {
implementation deps.kotlinx.kotlinx_coroutines_android
implementation deps.material_dialogs.core
implementation deps.material_dialogs.input
implementation deps.material_dialogs.files
implementation deps.room.room_runtime
implementation deps.room.room_ktx
kapt deps.room.room_compiler
Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/com/skyd/imomoe/bean/DoHJsonBean.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.skyd.imomoe.bean

import com.google.gson.annotations.SerializedName
import java.io.Serializable

class DoHJsonBean(
override var type: String = "",
override var actionUrl: String = "",
@SerializedName("Status")
var status: Int,
@SerializedName("TC")
var tc: Boolean,
@SerializedName("RD")
var rd: Boolean,
@SerializedName("RA")
var ra: Boolean,
@SerializedName("AD")
var ad: Boolean,
@SerializedName("CD")
var cd: Boolean,
@SerializedName("Question")
var question: List<Question>,
@SerializedName("Answer")
var answer: List<Answer>?,
@SerializedName("Comment")
var comment: String?,
@SerializedName("edns_client_subnet")
var eDNSClientSubnet: String?
) : BaseBean {
class Question(
@SerializedName("name")
var name: String,
@SerializedName("type")
var type: Int
) : Serializable

class Answer(
@SerializedName("name")
var name: String,
@SerializedName("type")
var type: Int,
@SerializedName("TTL")
var ttl: Int,
@SerializedName("data")
var data: String
) : Serializable
}
19 changes: 6 additions & 13 deletions app/src/main/java/com/skyd/imomoe/config/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ import com.skyd.imomoe.model.DataSourceManager

interface Api {
companion object {
const val DEFAULT_MAIN_URL = "http://www.yhdm.io"
var MAIN_URL = DEFAULT_MAIN_URL
get() = (DataSourceManager.getConst() ?: com.skyd.imomoe.model.impls.Const())
.MAIN_URL()
// return App.context.sharedPreferences("url")
// .getString("mainUrl", DEFAULT_MAIN_URL) ?: DEFAULT_MAIN_URL
private set/*(value) {
App.context.sharedPreferences("url").editor {
putString("mainUrl", value)
}
}*/
val MAIN_URL
get() = (DataSourceManager.getConst() ?: com.skyd.imomoe.model.impls.Const()).MAIN_URL()

//github
// github
const val CHECK_UPDATE_URL = "https://api.github.com/repos/SkyD666/Imomoe/releases/latest"

//弹幕url
// 弹幕url
const val DANMU_URL = "https://yuan.cuan.la/barrage/api"

// DoH
const val DOH_URL = "https://1.0.0.1/dns-query"
}
}
1 change: 1 addition & 0 deletions app/src/main/java/com/skyd/imomoe/config/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Const {
const val GITHUB_URL = "https://github.com/SkyD666/Imomoe"
const val GITHUB_NEW_ISSUE_URL = "https://github.com/SkyD666/Imomoe/issues/new"
const val USER_NOTICE_VERSION = 1
const val DNS_OVER_HTTPS = "https://1.0.0.1/dns-query"
}
}

Expand Down
33 changes: 25 additions & 8 deletions app/src/main/java/com/skyd/imomoe/model/DataSourceManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,46 @@ import com.skyd.imomoe.BuildConfig
import com.skyd.imomoe.model.interfaces.IConst
import com.skyd.imomoe.model.interfaces.IRouteProcessor
import com.skyd.imomoe.model.interfaces.IUtil
import com.skyd.imomoe.util.Util.showToast
import com.skyd.imomoe.util.editor
import com.skyd.imomoe.util.sharedPreferences
import dalvik.system.DexClassLoader
import java.io.File


object DataSourceManager {
var useCustomDataSource: Boolean
// var useCustomDataSource: Boolean
// get() {
// return App.context.sharedPreferences().getBoolean("useCustomDataSource", false)
// }
// set(value) {
// App.context.sharedPreferences().editor { putBoolean("useCustomDataSource", value) }
// }

const val DEFAULT_DATA_SOURCE = ""

var dataSourceName: String =
App.context.sharedPreferences().getString("dataSourceName", DEFAULT_DATA_SOURCE)
?: DEFAULT_DATA_SOURCE
get() {
return App.context.sharedPreferences().getBoolean("customDataSource", false)
return if (field.isBlank() && App.context.sharedPreferences()
.getBoolean("customDataSource", false)
) "CustomDataSource.jar" else field
}
set(value) {
App.context.sharedPreferences().editor { putBoolean("customDataSource", value) }
field = value
App.context.sharedPreferences().editor { putString("dataSourceName", value) }
}

// 第一个是传入的接口,第二个是实现类
private val cache: LruCache<Class<*>, Class<*>> = LruCache(10)
private val singletonCache: LruCache<Class<*>, Any> = LruCache(5)

fun getJarPath(): String {
// return "${Environment.getExternalStorageDirectory()}/Download/DataSourceJar/CustomDataSource.jar"
return App.context.getExternalFilesDir(null)
.toString() + "/DataSourceJar/CustomDataSource.jar"
fun getJarPath(): String =
"${getJarDirectory()}/${dataSourceName}"

fun getJarDirectory(): String {
return "${App.context.getExternalFilesDir(null).toString()}/DataSourceJar"
}

fun <T> getBinaryName(clazz: Class<T>): String {
Expand Down Expand Up @@ -77,7 +94,7 @@ object DataSourceManager {
@Suppress("UNCHECKED_CAST")
fun <T> create(clazz: Class<T>): T? {
// 如果不使用自定义数据,直接返回null
if (!useCustomDataSource) return null
if (dataSourceName == DEFAULT_DATA_SOURCE) return null
cache[clazz]?.let {
return it.newInstance() as T
}
Expand Down
163 changes: 1 addition & 162 deletions app/src/main/java/com/skyd/imomoe/model/impls/AnimeDetailModel.kt
Original file line number Diff line number Diff line change
@@ -1,173 +1,12 @@
package com.skyd.imomoe.model.impls

import com.skyd.imomoe.bean.*
import com.skyd.imomoe.config.Api
import com.skyd.imomoe.config.Const
import com.skyd.imomoe.model.util.JsoupUtil
import com.skyd.imomoe.model.util.ParseHtmlUtil
import com.skyd.imomoe.model.util.ParseHtmlUtil.parseBotit
import com.skyd.imomoe.model.interfaces.IAnimeDetailModel
import org.jsoup.select.Elements

class AnimeDetailModel : IAnimeDetailModel {
override suspend fun getAnimeDetailData(
partUrl: String
): Triple<ImageBean, String, ArrayList<IAnimeDetailBean>> {
val animeDetailList: ArrayList<IAnimeDetailBean> = ArrayList()
val cover = ImageBean("", "", "", "")
var title = ""
val url = Api.MAIN_URL + partUrl
val document = JsoupUtil.getDocument(url)
//番剧头部信息
val area: Elements = document.getElementsByClass("area")
for (i in area.indices) {
val areaChildren = area[i].children()
for (j in areaChildren.indices) {
when (areaChildren[j].className()) {
"fire l" -> {
var alias = ""
var info = ""
var year = ""
var index = ""
var animeArea = ""
val animeType: MutableList<AnimeTypeBean> = ArrayList()
val tag: MutableList<AnimeTypeBean> = ArrayList()

val fireLChildren =
areaChildren[j].select("[class=fire l]")[0].children()
for (k in fireLChildren.indices) {
when (fireLChildren[k].className()) {
"thumb l" -> {
cover.url = fireLChildren[k]
.select("img").attr("src")
cover.referer = url
}
"rate r" -> {
val rateR = fireLChildren[k]
title = rateR.select("h1").text()
val sinfo: Elements = rateR.select("[class=sinfo]")
val span: Elements = sinfo.select("span")
val p: Elements = sinfo.select("p")
if (p.size == 1) {
alias = p[0].text()
} else if (p.size == 2) {
alias = p[0].text()
info = p[1].text()
}
year = span[0].text()
animeArea = span[1].select("a").text()
index = span[3].select("a").text()
val typeElements: Elements = span[2].select("a")
for (l in typeElements.indices) {
animeType.add(
AnimeTypeBean(
"",
typeElements[l].attr("href"),
Api.MAIN_URL + typeElements[l].attr("href"),
typeElements[l].text()
)
)
}
val tagElements: Elements = span[4].select("a")
for (l in tagElements.indices) {
tag.add(
AnimeTypeBean(
"",
tagElements[l].attr("href"),
Api.MAIN_URL + tagElements[l].attr("href"),
tagElements[l].text()
)
)
}
}
"tabs", "tabs noshow" -> { //播放列表+header
animeDetailList.add(
AnimeDetailBean(
Const.ViewHolderTypeString.HEADER_1, "",
fireLChildren[k].select("[class=menu0]")
.select("li").text(),
"",
null
)
)

animeDetailList.add(
AnimeDetailBean(
Const.ViewHolderTypeString.HORIZONTAL_RECYCLER_VIEW_1,
"",
"",
"",
ParseHtmlUtil.parseMovurls(
fireLChildren[k].select("[class=main0]")
.select("[class=movurl]")[0]
)
)
)
}
"botit" -> { //其它header
animeDetailList.add(
AnimeDetailBean(
Const.ViewHolderTypeString.HEADER_1, "",
parseBotit(fireLChildren[k]),
"",
null
)
)
}
"dtit" -> { //其它header
animeDetailList.add(
AnimeDetailBean(
Const.ViewHolderTypeString.HEADER_1, "",
ParseHtmlUtil.parseDtit(fireLChildren[k]),
"",
null
)
)
}
"info" -> { //动漫介绍
animeDetailList.add(
AnimeDetailBean(
Const.ViewHolderTypeString.ANIME_DESCRIBE_1, "",
"",
fireLChildren[k]
.select("[class=info]").text(),
null
)
)
}
"img" -> { //系列动漫推荐
animeDetailList.addAll(
ParseHtmlUtil.parseImg(fireLChildren[k], url)
)
}
}
}
val animeInfoBean = AnimeInfoBean(
"",
"",
title,
ImageBean("", "", cover.url, url),
alias,
animeArea,
year,
index,
animeType,
tag,
info
)
animeDetailList.add(
0,
AnimeDetailBean(
Const.ViewHolderTypeString.ANIME_INFO_1, "",
"",
"",
headerInfo = animeInfoBean
)
)
}
}
}
}
return Triple(cover, title, animeDetailList)
return Triple(ImageBean("", "", "", ""), "", ArrayList())
}
}
Loading

0 comments on commit 712fdfe

Please sign in to comment.