From b199b12a83025cc700a7405b1bc7c833efb15d0d Mon Sep 17 00:00:00 2001 From: xiaji Date: Tue, 9 Jun 2026 19:53:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20SourceRegistry=20?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/videoapp/tv/engine/SourceRegistry.kt | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 app/src/main/java/com/videoapp/tv/engine/SourceRegistry.kt diff --git a/app/src/main/java/com/videoapp/tv/engine/SourceRegistry.kt b/app/src/main/java/com/videoapp/tv/engine/SourceRegistry.kt new file mode 100644 index 0000000..d6c7390 --- /dev/null +++ b/app/src/main/java/com/videoapp/tv/engine/SourceRegistry.kt @@ -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() + + 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 = 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]" + ) +}