BetterAnime: add URL intent handler (#589)
This commit is contained in:
@ -1,2 +1,24 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest package="eu.kanade.tachiyomi.animeextension"/>
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="eu.kanade.tachiyomi.animeextension">
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<activity
|
||||||
|
android:name=".pt.betteranime.BAUrlActivity"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:exported="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="betteranime.net"
|
||||||
|
android:pathPattern="/..*/..*/..*"
|
||||||
|
android:scheme="https" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
|
@ -6,12 +6,19 @@ ext {
|
|||||||
extName = 'Better Anime'
|
extName = 'Better Anime'
|
||||||
pkgNameSuffix = 'pt.betteranime'
|
pkgNameSuffix = 'pt.betteranime'
|
||||||
extClass = '.BetterAnime'
|
extClass = '.BetterAnime'
|
||||||
extVersionCode = 1
|
extVersionCode = 2
|
||||||
libVersion = '12'
|
libVersion = '12'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2'
|
compileOnly 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2'
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
kotlinOptions {
|
||||||
|
freeCompilerArgs += "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
package eu.kanade.tachiyomi.animeextension.pt.betteranime
|
||||||
|
|
||||||
|
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://betteranime.net/<type>/<lang>/<item> intents
|
||||||
|
* and redirects them to the main Aniyomi process.
|
||||||
|
*/
|
||||||
|
class BAUrlActivity : Activity() {
|
||||||
|
|
||||||
|
private val TAG = "BAUrlActivity"
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
val pathSegments = intent?.data?.pathSegments
|
||||||
|
if (pathSegments != null && pathSegments.size > 1) {
|
||||||
|
val type = pathSegments[0]
|
||||||
|
val lang = pathSegments[1]
|
||||||
|
val item = pathSegments[2]
|
||||||
|
val searchQuery = "$type/$lang/$item"
|
||||||
|
val mainIntent = Intent().apply {
|
||||||
|
action = "eu.kanade.tachiyomi.ANIMESEARCH"
|
||||||
|
putExtra("query", "${BetterAnime.PREFIX_SEARCH_PATH}$searchQuery")
|
||||||
|
putExtra("filter", packageName)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
startActivity(mainIntent)
|
||||||
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
Log.e(TAG, e.toString())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "could not parse uri from intent $intent")
|
||||||
|
}
|
||||||
|
|
||||||
|
finish()
|
||||||
|
exitProcess(0)
|
||||||
|
}
|
||||||
|
}
|
@ -139,12 +139,27 @@ class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
|
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
|
||||||
val params = BAFilters.getSearchParameters(filters)
|
return if (query.startsWith(PREFIX_SEARCH_PATH)) {
|
||||||
return client.newCall(searchAnimeRequest(page, query, params))
|
val path = query.removePrefix(PREFIX_SEARCH_PATH)
|
||||||
.asObservableSuccess()
|
client.newCall(GET("$baseUrl/$path"))
|
||||||
.map { response ->
|
.asObservableSuccess()
|
||||||
searchAnimeParse(response)
|
.map { response ->
|
||||||
}
|
searchAnimeByPathParse(response, path)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val params = BAFilters.getSearchParameters(filters)
|
||||||
|
client.newCall(searchAnimeRequest(page, query, params))
|
||||||
|
.asObservableSuccess()
|
||||||
|
.map { response ->
|
||||||
|
searchAnimeParse(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun searchAnimeByPathParse(response: Response, path: String): AnimesPage {
|
||||||
|
val details = animeDetailsParse(response)
|
||||||
|
details.url = "/$path"
|
||||||
|
return AnimesPage(listOf(details), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request = throw Exception("not used")
|
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request = throw Exception("not used")
|
||||||
@ -310,7 +325,7 @@ class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7"
|
private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7"
|
||||||
private const val PREFERRED_QUALITY = "preferred_quality"
|
private const val PREFERRED_QUALITY = "preferred_quality"
|
||||||
private val QUALITY_LIST = arrayOf("480p", "720p", "1080p")
|
private val QUALITY_LIST = arrayOf("480p", "720p", "1080p")
|
||||||
|
const val PREFIX_SEARCH_PATH = "path:"
|
||||||
private var INITIAL_DATA: String = ""
|
private var INITIAL_DATA: String = ""
|
||||||
private var WIRE_TOKEN: String = ""
|
private var WIRE_TOKEN: String = ""
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user