Guya: Add support for opening guya.moe titles directly in Tachiyomi (#2284)
Guya: Add support for opening guya.moe titles directly in Tachiyomi
This commit is contained in:
parent
e23b69f8a7
commit
7c51b89575
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application>
|
||||
<activity
|
||||
android:name=".GuyaUrlActivity"
|
||||
android:theme="@android:style/Theme.NoDisplay"
|
||||
android:excludeFromRecents="true">
|
||||
<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:scheme="https"
|
||||
android:host="guya.moe"
|
||||
android:pathPattern="/read/manga/..*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
|
@ -5,7 +5,7 @@ ext {
|
|||
appName = 'Tachiyomi: Guya'
|
||||
pkgNameSuffix = "en.guya"
|
||||
extClass = '.Guya'
|
||||
extVersionCode = 9
|
||||
extVersionCode = 10
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
|
|
@ -131,12 +131,21 @@ open class Guya() : ConfigurableSource, HttpSource() {
|
|||
}
|
||||
|
||||
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
|
||||
return client.newCall(searchMangaRequest(page, query, filters))
|
||||
return if ( query.startsWith(SLUG_PREFIX)) {
|
||||
val slug = query.removePrefix(SLUG_PREFIX)
|
||||
client.newCall(searchMangaRequest(page, query, filters))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchMangaParseWithSlug(response, slug)
|
||||
}
|
||||
} else {
|
||||
client.newCall(searchMangaRequest(page, query, filters))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchMangaParse(response, query)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||
return GET("$baseUrl/api/get_all_series/", headers)
|
||||
|
@ -146,6 +155,24 @@ open class Guya() : ConfigurableSource, HttpSource() {
|
|||
throw Exception("Unused.")
|
||||
}
|
||||
|
||||
private fun searchMangaParseWithSlug(response: Response, slug: String) : MangasPage {
|
||||
val results = JSONObject(response.body()!!.string())
|
||||
val mangaIter = results.keys()
|
||||
val truncatedJSON = JSONObject()
|
||||
|
||||
while (mangaIter.hasNext()) {
|
||||
val mangaTitle = mangaIter.next()
|
||||
val mangaDetails = results.getJSONObject(mangaTitle)
|
||||
|
||||
if (mangaDetails.get("slug") == slug) {
|
||||
truncatedJSON.put(mangaTitle, mangaDetails)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return parseManga(truncatedJSON)
|
||||
}
|
||||
|
||||
private fun searchMangaParse(response: Response, query: String): MangasPage {
|
||||
val res = response.body()!!.string()
|
||||
val json = JSONObject(res)
|
||||
|
@ -393,4 +420,7 @@ open class Guya() : ConfigurableSource, HttpSource() {
|
|||
throw Exception("Latest updates not supported.")
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val SLUG_PREFIX = "slug:"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package eu.kanade.tachiyomi.extension.en.guya
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
/**
|
||||
* Accepts https://guya.moe/read/manga/xyz intents
|
||||
*
|
||||
* Added due to requests from various users to allow for opening of titles when given the
|
||||
* Guya URL whilst on mobile.
|
||||
*/
|
||||
class GuyaUrlActivity : Activity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val pathSegments = intent?.data?.pathSegments
|
||||
if (pathSegments != null && pathSegments.size == 3) {
|
||||
val slug = pathSegments[2]
|
||||
|
||||
// Gotta do it like this since slug title != actual title
|
||||
val mainIntent = Intent().apply {
|
||||
action = "eu.kanade.tachiyomi.SEARCH"
|
||||
putExtra("query", "${Guya.SLUG_PREFIX}$slug")
|
||||
putExtra("filter", packageName)
|
||||
}
|
||||
|
||||
try {
|
||||
startActivity(mainIntent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
Log.e("GuyaUrlActivity", e.toString())
|
||||
}
|
||||
} else {
|
||||
Log.e("GuyaUrlActivity", "Unable to parse URI from intent $intent")
|
||||
}
|
||||
|
||||
finish()
|
||||
exitProcess(0)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue