From 98f0495b4dd8fad30c82d5120e3d5bcb2de050c1 Mon Sep 17 00:00:00 2001 From: E3FxGaming <8276268+E3FxGaming@users.noreply.github.com> Date: Tue, 2 Feb 2021 12:50:24 +0100 Subject: [PATCH] MangaMutiny bugfix + link handler (#5623) * Fixing artist NullPointer exception * Added https://mangamutiny.org/title/* link handler Can now open manga from the mangamutiny.org website (when accessed with a web browser) in the Tachiyomi app. Borrowed the method from the Mangadex extension and adapted it to fit the Manga Mutiny extension. * Removed logging + changed comment * Adding containsNsfw = true Most manga offered are sfw, but a couple of manga cross the "not appropriate" line here and there. --- src/en/mangamutiny/AndroidManifest.xml | 23 ++++++++++- src/en/mangamutiny/build.gradle | 3 +- .../extension/en/mangamutiny/MangaMutiny.kt | 38 +++++++++++++++-- .../en/mangamutiny/MangaMutinyUrlActivity.kt | 41 +++++++++++++++++++ 4 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 src/en/mangamutiny/src/eu/kanade/tachiyomi/extension/en/mangamutiny/MangaMutinyUrlActivity.kt diff --git a/src/en/mangamutiny/AndroidManifest.xml b/src/en/mangamutiny/AndroidManifest.xml index 30deb7f79..dd8605dc3 100644 --- a/src/en/mangamutiny/AndroidManifest.xml +++ b/src/en/mangamutiny/AndroidManifest.xml @@ -1,2 +1,23 @@ - + + + + + + + + + + + + + + + diff --git a/src/en/mangamutiny/build.gradle b/src/en/mangamutiny/build.gradle index 0027d9fdb..d8a391708 100644 --- a/src/en/mangamutiny/build.gradle +++ b/src/en/mangamutiny/build.gradle @@ -5,8 +5,9 @@ ext { extName = 'Manga Mutiny' pkgNameSuffix = "en.mangamutiny" extClass = '.MangaMutiny' - extVersionCode = 3 + extVersionCode = 4 libVersion = '1.2' + containsNsfw = true } apply from: "$rootDir/common.gradle" diff --git a/src/en/mangamutiny/src/eu/kanade/tachiyomi/extension/en/mangamutiny/MangaMutiny.kt b/src/en/mangamutiny/src/eu/kanade/tachiyomi/extension/en/mangamutiny/MangaMutiny.kt index 106bdb967..97ad4cdc6 100644 --- a/src/en/mangamutiny/src/eu/kanade/tachiyomi/extension/en/mangamutiny/MangaMutiny.kt +++ b/src/en/mangamutiny/src/eu/kanade/tachiyomi/extension/en/mangamutiny/MangaMutiny.kt @@ -5,6 +5,7 @@ import com.google.gson.JsonElement import com.google.gson.JsonObject import com.google.gson.JsonParser 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 @@ -15,6 +16,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource import okhttp3.Headers import okhttp3.Request import okhttp3.Response +import rx.Observable import java.lang.Exception import java.text.SimpleDateFormat import java.util.Locale @@ -53,6 +55,10 @@ class MangaMutiny : HttpSource() { private val fetchAmount = 21 + companion object { + const val PREFIX_ID_SEARCH = "slug:" + } + // Popular manga override fun popularMangaRequest(page: Int): Request = mangaRequest(page) @@ -115,7 +121,7 @@ class MangaMutiny : HttpSource() { // latest override fun latestUpdatesRequest(page: Int): Request = - mangaRequest(page, FilterList(SortFilter().apply { this.state = 1 })) + mangaRequest(page, filters = FilterList(SortFilter().apply { this.state = 1 })) override fun latestUpdatesParse(response: Response): MangasPage = mangaParse(response) @@ -148,7 +154,7 @@ class MangaMutiny : HttpSource() { thumbnail_url = rootNode.getNullable("thumbnail")?.asString title = rootNode.get("title").asString url = rootNode.get("slug").asString - artist = rootNode.get("artists").asString + artist = rootNode.getNullable("artists")?.asString author = rootNode.get("authors").asString genre = rootNode.get("tags").asJsonArray @@ -195,7 +201,7 @@ class MangaMutiny : HttpSource() { // Search override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = - mangaRequest(page, filters, query) + mangaRequest(page, query, filters) override fun searchMangaParse(response: Response): MangasPage = mangaParse(response) @@ -229,7 +235,31 @@ class MangaMutiny : HttpSource() { return MangasPage(mangasPage, mangasPage.size == fetchAmount) } - private fun mangaRequest(page: Int, filters: FilterList? = null, query: String? = null): Request { + override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { + + return if (query.startsWith(PREFIX_ID_SEARCH)) { + val realQuery = query.removePrefix(PREFIX_ID_SEARCH) + + val tempManga = SManga.create().apply { + url = realQuery + } + + client.newCall(mangaDetailsRequestCommon(tempManga, true)) + .asObservableSuccess() + .map { response -> + val details = mangaDetailsParse(response) + MangasPage(listOf(details), false) + } + } else { + client.newCall(searchMangaRequest(page, query, filters)) + .asObservableSuccess() + .map { response -> + searchMangaParse(response) + } + } + } + + private fun mangaRequest(page: Int, query: String? = null, filters: FilterList? = null): Request { val uri = Uri.parse(baseUrl).buildUpon() uri.appendEncodedPath(apiMangaUrlPath) if (query?.isNotBlank() == true) { diff --git a/src/en/mangamutiny/src/eu/kanade/tachiyomi/extension/en/mangamutiny/MangaMutinyUrlActivity.kt b/src/en/mangamutiny/src/eu/kanade/tachiyomi/extension/en/mangamutiny/MangaMutinyUrlActivity.kt new file mode 100644 index 000000000..cc358b29d --- /dev/null +++ b/src/en/mangamutiny/src/eu/kanade/tachiyomi/extension/en/mangamutiny/MangaMutinyUrlActivity.kt @@ -0,0 +1,41 @@ +package eu.kanade.tachiyomi.extension.en.mangamutiny + +import android.app.Activity +import android.content.ActivityNotFoundException +import android.content.Intent +import android.os.Bundle +import android.util.Log +import kotlin.system.exitProcess + +/** + * Springboard that accepts https://mangamutiny.org/title/xxx intents and redirects them to + * the main tachiyomi process. The idea is to not install the intent filter unless + * you have this extension installed, but still let the main tachiyomi app control + * things. + */ +class MangaMutinyUrlActivity : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val pathSegments = intent?.data?.pathSegments + if (pathSegments != null && pathSegments.size > 1) { + val slug = pathSegments[1] + val mainIntent = Intent().apply { + action = "eu.kanade.tachiyomi.SEARCH" + putExtra("query", "${MangaMutiny.PREFIX_ID_SEARCH}$slug") + putExtra("filter", packageName) + } + + try { + startActivity(mainIntent) + } catch (e: ActivityNotFoundException) { + Log.e("MangaMutinyUrlActivity", e.toString()) + } + } else { + Log.e("MangaMutinyUrlActivity", "could not parse uri from intent $intent") + } + + finish() + exitProcess(0) + } +}