feat: 添加 SourceRegistry 注册中心

This commit is contained in:
xiaji
2026-06-09 19:53:05 +08:00
parent dea2700da1
commit b199b12a83

View File

@@ -0,0 +1,56 @@
package com.videoapp.tv.engine
import android.content.Context
import com.videoapp.tv.data.ConfigRepository
import com.videoapp.tv.data.SiteConfig
import com.videoapp.tv.engine.tvcat.TvcatHandler
import com.videoapp.tv.engine.xb6v.Xb6vHandler
object SourceRegistry {
private val handlers = mutableMapOf<String, SourceHandler>()
fun register(handler: SourceHandler) {
handlers[handler.id] = handler
}
fun get(id: String): SourceHandler = handlers[id]
?: throw IllegalArgumentException("Unknown source: $id")
fun getOrDefault(id: String): SourceHandler? = handlers[id]
fun getAll(): List<SourceHandler> = handlers.values.toList()
fun init(context: Context) {
val configRepo = ConfigRepository(context)
val savedConfig = configRepo.getConfig()
val xb6vConfig = xb6vConfig()
register(Xb6vHandler(xb6vConfig))
register(TvcatHandler())
}
private fun xb6vConfig() = SiteConfig(
baseUrl = "https://www.xb6v.com",
searchPath = "/e/search/11index.php",
searchMethod = "POST",
keywordParam = "keyboard",
extraParams = mapOf(
"show" to "title",
"tempid" to "1",
"tbname" to "article",
"mid" to "1",
"dopost" to "search"
),
resultSelector = "li.post",
titleSelector = "h2 a",
coverSelector = ".thumbnail img",
linkSelector = ".thumbnail a",
categorySelector = ".info_category a",
dateSelector = ".info_date",
episodeSelector = "a.lBtn",
sourceSelector = ".playfrom a, .play_source a, .source-list a",
sourceEpisodeGroupSelector = ".playlist > ul, .play_list > ul, .episode-list",
iframeSelector = ".video iframe",
videoSelector = "video source, video[src]"
)
}