[Manga Plus] Add URL intent for chapter links (#12252)
* [Manga Plus] Add URL intent for chapter links * Use a when block instead of nested if-else * Add more descriptive error message
This commit is contained in:
parent
a687771b10
commit
ea96bab86b
|
@ -30,6 +30,14 @@
|
||||||
android:host="www.jumpg-webapi.tokyo-cdn.com"
|
android:host="www.jumpg-webapi.tokyo-cdn.com"
|
||||||
android:path="/www/sns_share"
|
android:path="/www/sns_share"
|
||||||
android:scheme="https" />
|
android:scheme="https" />
|
||||||
|
<data
|
||||||
|
android:host="mangaplus.shueisha.co.jp"
|
||||||
|
android:pathPattern="/viewer/..*"
|
||||||
|
android:scheme="https" />
|
||||||
|
<data
|
||||||
|
android:host="www.mangaplus.shueisha.co.jp"
|
||||||
|
android:pathPattern="/viewer/..*"
|
||||||
|
android:scheme="https" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
|
@ -6,7 +6,7 @@ ext {
|
||||||
extName = 'MANGA Plus by SHUEISHA'
|
extName = 'MANGA Plus by SHUEISHA'
|
||||||
pkgNameSuffix = 'all.mangaplus'
|
pkgNameSuffix = 'all.mangaplus'
|
||||||
extClass = '.MangaPlusFactory'
|
extClass = '.MangaPlusFactory'
|
||||||
extVersionCode = 33
|
extVersionCode = 34
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -139,7 +139,29 @@ abstract class MangaPlus(
|
||||||
return MangasPage(mangas, false)
|
return MangasPage(mangas, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fetchTitleIdFromChapterId(chapterId: String): Observable<Int> {
|
||||||
|
|
||||||
|
return Observable.defer {
|
||||||
|
client.newCall(pageListRequestFromChapterId(chapterId)).asObservableSuccess()
|
||||||
|
}.map { response ->
|
||||||
|
titleIdParse(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun titleIdParse(response: Response): Int {
|
||||||
|
val result = response.asMangaPlusResponse()
|
||||||
|
|
||||||
|
checkNotNull(result.success) { result.error!!.langPopup(langCode).body }
|
||||||
|
|
||||||
|
return checkNotNull(result.success.mangaViewer?.titleId) { "Chapter is invalid or expired" }
|
||||||
|
}
|
||||||
|
|
||||||
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
|
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
|
||||||
|
if (query.startsWith(PREFIX_CHAPTER_ID_SEARCH) && query.matches(CHAPTER_ID_SEARCH_PATTERN)) {
|
||||||
|
return fetchTitleIdFromChapterId(query.removePrefix(PREFIX_CHAPTER_ID_SEARCH)).flatMap {
|
||||||
|
fetchSearchManga(page, "$PREFIX_ID_SEARCH$it", filters)
|
||||||
|
}
|
||||||
|
}
|
||||||
return super.fetchSearchManga(page, query, filters)
|
return super.fetchSearchManga(page, query, filters)
|
||||||
.map {
|
.map {
|
||||||
if (it.mangas.size == 1) {
|
if (it.mangas.size == 1) {
|
||||||
|
@ -268,7 +290,10 @@ abstract class MangaPlus(
|
||||||
|
|
||||||
override fun pageListRequest(chapter: SChapter): Request {
|
override fun pageListRequest(chapter: SChapter): Request {
|
||||||
val chapterId = chapter.url.substringAfterLast("/")
|
val chapterId = chapter.url.substringAfterLast("/")
|
||||||
|
return pageListRequestFromChapterId(chapterId)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun pageListRequestFromChapterId(chapterId: String): Request {
|
||||||
val newHeaders = headersBuilder()
|
val newHeaders = headersBuilder()
|
||||||
.set("Referer", "$baseUrl/viewer/$chapterId")
|
.set("Referer", "$baseUrl/viewer/$chapterId")
|
||||||
.build()
|
.build()
|
||||||
|
@ -434,5 +459,7 @@ abstract class MangaPlus(
|
||||||
|
|
||||||
const val PREFIX_ID_SEARCH = "id:"
|
const val PREFIX_ID_SEARCH = "id:"
|
||||||
private val ID_SEARCH_PATTERN = "^id:(\\d+)$".toRegex()
|
private val ID_SEARCH_PATTERN = "^id:(\\d+)$".toRegex()
|
||||||
|
const val PREFIX_CHAPTER_ID_SEARCH = "ch_id:"
|
||||||
|
private val CHAPTER_ID_SEARCH_PATTERN = "^ch_id:(\\d+)$".toRegex()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,10 @@ data class TitleDetailView(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class MangaViewer(val pages: List<MangaPlusPage> = emptyList())
|
data class MangaViewer(
|
||||||
|
val pages: List<MangaPlusPage> = emptyList(),
|
||||||
|
val titleId: Int? = null
|
||||||
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Title(
|
data class Title(
|
||||||
|
|
|
@ -14,13 +14,16 @@ class MangaPlusUrlActivity : Activity() {
|
||||||
|
|
||||||
val pathSegments = intent?.data?.pathSegments
|
val pathSegments = intent?.data?.pathSegments
|
||||||
if (pathSegments != null && pathSegments.size > 1) {
|
if (pathSegments != null && pathSegments.size > 1) {
|
||||||
val titleId = if (!pathSegments[1].equals("sns_share")) pathSegments[1] else
|
val query = when {
|
||||||
intent?.data?.getQueryParameter("title_id")
|
pathSegments[0].equals("viewer") -> MangaPlus.PREFIX_CHAPTER_ID_SEARCH + pathSegments[1]
|
||||||
|
pathSegments[0].equals("sns_share") -> intent?.data?.getQueryParameter("title_id")?.let { MangaPlus.PREFIX_ID_SEARCH + it }
|
||||||
|
else -> MangaPlus.PREFIX_ID_SEARCH + pathSegments[1]
|
||||||
|
}
|
||||||
|
|
||||||
if (titleId != null) {
|
if (query != null) {
|
||||||
val mainIntent = Intent().apply {
|
val mainIntent = Intent().apply {
|
||||||
action = "eu.kanade.tachiyomi.SEARCH"
|
action = "eu.kanade.tachiyomi.SEARCH"
|
||||||
putExtra("query", MangaPlus.PREFIX_ID_SEARCH + titleId)
|
putExtra("query", query)
|
||||||
putExtra("filter", packageName)
|
putExtra("filter", packageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +33,7 @@ class MangaPlusUrlActivity : Activity() {
|
||||||
Log.e("MangaPlusUrlActivity", e.toString())
|
Log.e("MangaPlusUrlActivity", e.toString())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e("MangaPlusUrlActivity", "Missing title ID from the URL")
|
Log.e("MangaPlusUrlActivity", "Missing title/chapter ID from the URL")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e("MangaPlusUrlActivity", "Could not parse URI from intent $intent")
|
Log.e("MangaPlusUrlActivity", "Could not parse URI from intent $intent")
|
||||||
|
|
Loading…
Reference in New Issue