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.
This commit is contained in:
E3FxGaming 2021-02-02 12:50:24 +01:00 committed by GitHub
parent 771f65d7e9
commit 98f0495b4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 99 additions and 6 deletions

View File

@ -1,2 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="eu.kanade.tachiyomi.extension" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.kanade.tachiyomi.extension">
<application>
<activity
android:name=".en.mangamutiny.MangaMutinyUrlActivity"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="mangamutiny.org"
android:pathPattern="/title/..*"
android:scheme="https" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -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"

View File

@ -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<MangasPage> {
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) {

View File

@ -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)
}
}