MangaDex: Add Slug to Share url, Prefer `jp-ro` titles and Verify host link intents (#10539)

* Add slug to Share URL

cleans up the title and adds it as a slug to the end of the url that can
then be shared without any issues

Co-authored-by: Henrik <22085664+henrik9999@users.noreply.github.com>

* Check for Japanese Romanized titles

ko-ro and zh-ro also exist but arent that readable compared to ja-ro
personally. And those have a confirmed en title (or fallbacks) anyways

* Increment mangadex.extversioncode

* Linting by Android Studio build process

* Actually use the correct lang code

it's `ja-ro` not `jp-ro`

* Support verified deeplinks (A12+)

* Replace intent host to wildcard hosts

helps with A12 link verify
Ref https://github.com/tachiyomiorg/tachiyomi-extensions/pull/9993

Co-authored-by: funkyhippo <52957110+funkyhippo@users.noreply.github.com>

* Make `titleToSlug` more idiomatic

perhaps java.text.Normalizer could have helped but didnt want to add an
import just for that :d

Co-authored-by: Henrik <22085664+henrik9999@users.noreply.github.com>
Co-authored-by: funkyhippo <52957110+funkyhippo@users.noreply.github.com>
This commit is contained in:
nicki 2022-01-22 00:43:43 +05:30 committed by GitHub
parent 20593546ac
commit a84a3e275f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 23 deletions

View File

@ -8,42 +8,25 @@
android:excludeFromRecents="true"
android:exported="true"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="*.mangadex.org" />
<data android:host="mangadex.org" />
<data
android:host="mangadex.org"
android:pathPattern="/title/..*"
android:scheme="https" />
<data
android:host="www.mangadex.org"
android:pathPattern="/title/..*"
android:scheme="https" />
<data
android:host="mangadex.org"
android:pathPattern="/manga/..*"
android:scheme="https" />
<data
android:host="www.mangadex.org"
android:pathPattern="/manga/..*"
android:scheme="https" />
<data
android:host="mangadex.org"
android:pathPattern="/chapter/..*"
android:scheme="https" />
<data
android:host="www.mangadex.org"
android:pathPattern="/chapter/..*"
android:scheme="https" />
<data
android:host="mangadex.org"
android:pathPattern="/group/..*"
android:scheme="https" />
<data
android:host="www.mangadex.org"
android:pathPattern="/group/..*"
android:scheme="https" />
</intent-filter>

View File

@ -6,7 +6,7 @@ ext {
extName = 'MangaDex'
pkgNameSuffix = 'all.mangadex'
extClass = '.MangaDexFactory'
extVersionCode = 152
extVersionCode = 153
isNsfw = true
}

View File

@ -272,7 +272,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
override fun mangaDetailsRequest(manga: SManga): Request {
// remove once redirect for /manga is fixed
return GET("${baseUrl}${manga.url.replace("manga", "title")}", headers)
val title = manga.title
val url = "${baseUrl}${manga.url.replace("manga", "title")}"
val shareUrl = "$url/" + helper.titleToSlug(title)
return GET(shareUrl, headers)
}
/**

View File

@ -190,6 +190,7 @@ class MangaDexHelper() {
val titleMap = mangaDataDto.attributes.title.asMdMap()
val dirtyTitle = titleMap[lang]
?: titleMap["en"]
?: titleMap["ja-ro"]
?: mangaDataDto.attributes.altTitles.jsonArray
.find {
val altTitle = it.asMdMap()
@ -348,4 +349,18 @@ class MangaDexHelper() {
throw(e)
}
}
fun titleToSlug(title: String) = title.trim()
.toLowerCase(Locale.US)
.replace("[^a-z0-9]+".toRegex(), "-")
.replace("-+$".toRegex(), "")
.split("-")
.reduce { accumulator, element ->
val currentSlug = "$accumulator-$element"
if (currentSlug.length > 100) {
accumulator
} else {
currentSlug
}
}
}