From b7110681dbfc62c5f9f04fd9af37947f56fe1808 Mon Sep 17 00:00:00 2001 From: ShadesOfRay Date: Tue, 4 May 2021 22:16:13 -0400 Subject: [PATCH] Added Url intents for DynastyScans and Kuaikanmanhua (#6822) * Added Url intents for KKMH * Added Url intents for Dynasty Scans --- src/en/dynasty/AndroidManifest.xml | 39 ++++++++++++++++++- src/en/dynasty/build.gradle | 2 +- .../en/dynasty/DynastyAnthologies.kt | 2 + .../extension/en/dynasty/DynastyChapters.kt | 1 + .../extension/en/dynasty/DynastyDoujins.kt | 2 + .../extension/en/dynasty/DynastyIssues.kt | 2 + .../extension/en/dynasty/DynastyScans.kt | 23 +++++++++++ .../extension/en/dynasty/DynastySeries.kt | 2 + .../en/dynasty/DynastyUrlActivity.kt | 34 ++++++++++++++++ src/zh/kuaikanmanhua/AndroidManifest.xml | 27 ++++++++++++- src/zh/kuaikanmanhua/build.gradle | 2 +- .../zh/kuaikanmanhua/Kuaikanmanhua.kt | 21 ++++++++++ .../kuaikanmanhua/KuaikanmanhuaUrlActivity.kt | 38 ++++++++++++++++++ 13 files changed, 191 insertions(+), 4 deletions(-) create mode 100644 src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyUrlActivity.kt create mode 100644 src/zh/kuaikanmanhua/src/eu/kanade/tachiyomi/extension/zh/kuaikanmanhua/KuaikanmanhuaUrlActivity.kt diff --git a/src/en/dynasty/AndroidManifest.xml b/src/en/dynasty/AndroidManifest.xml index 30deb7f79..3f781b205 100644 --- a/src/en/dynasty/AndroidManifest.xml +++ b/src/en/dynasty/AndroidManifest.xml @@ -1,2 +1,39 @@ - + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/en/dynasty/build.gradle b/src/en/dynasty/build.gradle index b75b8eb58..b293610ee 100644 --- a/src/en/dynasty/build.gradle +++ b/src/en/dynasty/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Dynasty' pkgNameSuffix = 'en.dynasty' extClass = '.DynastyFactory' - extVersionCode = 12 + extVersionCode = 13 libVersion = '1.2' } diff --git a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyAnthologies.kt b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyAnthologies.kt index 6635cb30f..33fa33c21 100644 --- a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyAnthologies.kt +++ b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyAnthologies.kt @@ -10,6 +10,8 @@ class DynastyAnthologies : DynastyScans() { override val name = "Dynasty-Anthologies" + override val searchPrefix = "anthologies" + override fun popularMangaInitialUrl() = "$baseUrl/anthologies?view=cover" override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { diff --git a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyChapters.kt b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyChapters.kt index 1ac7c34ed..c76f2219e 100644 --- a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyChapters.kt +++ b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyChapters.kt @@ -12,6 +12,7 @@ import org.jsoup.nodes.Element class DynastyChapters : DynastyScans() { override val name = "Dynasty-Chapters" + override val searchPrefix = "chapters" override fun popularMangaInitialUrl() = "" private fun popularMangaInitialUrl(page: Int) = "$baseUrl/search?q=&classes%5B%5D=Chapter&page=$page=$&sort=" diff --git a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyDoujins.kt b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyDoujins.kt index bef273b6b..c27403223 100644 --- a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyDoujins.kt +++ b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyDoujins.kt @@ -15,6 +15,8 @@ class DynastyDoujins : DynastyScans() { override val name = "Dynasty-Doujins" + override val searchPrefix = "doujins" + override fun popularMangaInitialUrl() = "$baseUrl/doujins?view=cover" override fun popularMangaFromElement(element: Element): SManga { diff --git a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyIssues.kt b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyIssues.kt index cc74fe275..c91c6af84 100644 --- a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyIssues.kt +++ b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyIssues.kt @@ -10,6 +10,8 @@ class DynastyIssues : DynastyScans() { override val name = "Dynasty-Issues" + override val searchPrefix = "issues" + override fun popularMangaInitialUrl() = "$baseUrl/issues?view=cover" override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { diff --git a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyScans.kt b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyScans.kt index 469007f46..088ed42f9 100644 --- a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyScans.kt +++ b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyScans.kt @@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.extension.en.dynasty import android.net.Uri import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.network.asObservableSuccess +import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter @@ -16,6 +18,7 @@ import org.jsoup.nodes.Element import org.jsoup.nodes.Node import org.jsoup.nodes.TextNode import org.jsoup.select.Elements +import rx.Observable import java.text.SimpleDateFormat import java.util.ArrayList import java.util.Locale @@ -30,6 +33,8 @@ abstract class DynastyScans : ParsedHttpSource() { override val supportsLatest = false + open val searchPrefix = "" + private var parent: List = ArrayList() private var list = InternalList(ArrayList(), "") @@ -58,6 +63,24 @@ abstract class DynastyScans : ParsedHttpSource() { return MangasPage(mangas, false) } + override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { + if (query.startsWith("manga:")) { + return if (query.startsWith("manga:$searchPrefix:")) { + val newQuery = query.removePrefix("manga:$searchPrefix:") + client.newCall(GET("$baseUrl/$searchPrefix/$newQuery")) + .asObservableSuccess() + .map { response -> + val details = mangaDetailsParse(response) + details.url = "/$searchPrefix/$newQuery" + MangasPage(listOf(details), false) + } + } else { + return Observable.just(MangasPage(ArrayList(0), false)) + } + } + return super.fetchSearchManga(page, query, filters) + } + override fun searchMangaSelector() = "a.name" override fun searchMangaFromElement(element: Element): SManga { diff --git a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastySeries.kt b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastySeries.kt index 6bdbe15a7..a5661ff3b 100644 --- a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastySeries.kt +++ b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastySeries.kt @@ -10,6 +10,8 @@ class DynastySeries : DynastyScans() { override val name = "Dynasty-Series" + override val searchPrefix = "series" + override fun popularMangaInitialUrl() = "$baseUrl/series?view=cover" override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { diff --git a/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyUrlActivity.kt b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyUrlActivity.kt new file mode 100644 index 000000000..c05c54675 --- /dev/null +++ b/src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyUrlActivity.kt @@ -0,0 +1,34 @@ +package eu.kanade.tachiyomi.extension.en.dynasty + +import android.app.Activity +import android.content.ActivityNotFoundException +import android.content.Intent +import android.os.Bundle +import android.util.Log +import kotlin.system.exitProcess + +class DynastyUrlActivity : Activity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val pathSegments = intent?.data?.pathSegments + if (pathSegments != null && pathSegments.size > 1) { + val id = pathSegments[1] + val mainIntent = Intent().apply { + action = "eu.kanade.tachiyomi.SEARCH" + putExtra("query", "manga:${pathSegments[0]}:$id") + putExtra("filter", packageName) + } + + try { + startActivity(mainIntent) + } catch (e: ActivityNotFoundException) { + Log.e("DynastyUrlActivity", e.toString()) + } + } else { + Log.e("DynastyUrlActivity", "could not parse uri from intent $intent") + } + + finish() + exitProcess(0) + } +} diff --git a/src/zh/kuaikanmanhua/AndroidManifest.xml b/src/zh/kuaikanmanhua/AndroidManifest.xml index 30deb7f79..8ec5a7ad2 100644 --- a/src/zh/kuaikanmanhua/AndroidManifest.xml +++ b/src/zh/kuaikanmanhua/AndroidManifest.xml @@ -1,2 +1,27 @@ - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/zh/kuaikanmanhua/build.gradle b/src/zh/kuaikanmanhua/build.gradle index 67d62985d..9109984bf 100644 --- a/src/zh/kuaikanmanhua/build.gradle +++ b/src/zh/kuaikanmanhua/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Kuaikanmanhua' pkgNameSuffix = 'zh.kuaikanmanhua' extClass = '.Kuaikanmanhua' - extVersionCode = 3 + extVersionCode = 4 libVersion = '1.2' } diff --git a/src/zh/kuaikanmanhua/src/eu/kanade/tachiyomi/extension/zh/kuaikanmanhua/Kuaikanmanhua.kt b/src/zh/kuaikanmanhua/src/eu/kanade/tachiyomi/extension/zh/kuaikanmanhua/Kuaikanmanhua.kt index 3fa8899bf..322e83fd0 100644 --- a/src/zh/kuaikanmanhua/src/eu/kanade/tachiyomi/extension/zh/kuaikanmanhua/Kuaikanmanhua.kt +++ b/src/zh/kuaikanmanhua/src/eu/kanade/tachiyomi/extension/zh/kuaikanmanhua/Kuaikanmanhua.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.extension.zh.kuaikanmanhua import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage @@ -68,8 +69,23 @@ class Kuaikanmanhua : HttpSource() { // Search + override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { + if (query.startsWith(TOPIC_ID_SEARCH_PREFIX)) { + val new_query = query.removePrefix(TOPIC_ID_SEARCH_PREFIX) + return client.newCall(GET("$apiUrl/v1/topics/$new_query")) + .asObservableSuccess() + .map { response -> + val details = mangaDetailsParse(response) + details.url = "/web/topic/$new_query" + MangasPage(listOf(details), false) + } + } + return super.fetchSearchManga(page, query, filters) + } + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { return if (query.isNotEmpty()) { + GET("$apiUrl/v1/search/topic?q=$query&size=18", headers) } else { lateinit var genre: String @@ -112,6 +128,7 @@ class Kuaikanmanhua : HttpSource() { val data = JSONObject(response.body!!.string()).getJSONObject("data") val manga = SManga.create() manga.title = data.getString("title") + manga.thumbnail_url = data.getString("vertical_image_url") manga.author = data.getJSONObject("user").getString("nickname") manga.description = data.getString("description") manga.status = data.getInt("update_status_code") @@ -227,4 +244,8 @@ class Kuaikanmanhua : HttpSource() { Filter.Select(displayName, vals.map { it.first }.toTypedArray()) { fun toUriPart() = vals[state].second } + + companion object { + const val TOPIC_ID_SEARCH_PREFIX = "topic:" + } } diff --git a/src/zh/kuaikanmanhua/src/eu/kanade/tachiyomi/extension/zh/kuaikanmanhua/KuaikanmanhuaUrlActivity.kt b/src/zh/kuaikanmanhua/src/eu/kanade/tachiyomi/extension/zh/kuaikanmanhua/KuaikanmanhuaUrlActivity.kt new file mode 100644 index 000000000..42d56f8e8 --- /dev/null +++ b/src/zh/kuaikanmanhua/src/eu/kanade/tachiyomi/extension/zh/kuaikanmanhua/KuaikanmanhuaUrlActivity.kt @@ -0,0 +1,38 @@ +package eu.kanade.tachiyomi.extension.zh.kuaikanmanhua + +import android.app.Activity +import android.content.ActivityNotFoundException +import android.content.Intent +import android.os.Bundle +import android.util.Log +import kotlin.system.exitProcess + +class KuaikanmanhuaUrlActivity : Activity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val host = intent?.data?.host + val pathSegments = intent?.data?.pathSegments + if (pathSegments != null && pathSegments.size > 1) { + val id = when (host) { + "m.kuaikanmanhua.com" -> pathSegments[1] + else -> pathSegments[2] + } + val mainIntent = Intent().apply { + action = "eu.kanade.tachiyomi.SEARCH" + putExtra("query", "${Kuaikanmanhua.TOPIC_ID_SEARCH_PREFIX}$id") + putExtra("filter", packageName) + } + + try { + startActivity(mainIntent) + } catch (e: ActivityNotFoundException) { + Log.e("KkmhUrlActivity", e.toString()) + } + } else { + Log.e("KkmhUrlActivity", "could not parse uri from intent $intent") + } + + finish() + exitProcess(0) + } +}