fix(rpc): no images
This commit is contained in:
parent
0214e6611b
commit
a8f7ff2a19
5 changed files with 93 additions and 38 deletions
|
@ -400,9 +400,7 @@ class AnilistQueries {
|
||||||
return media
|
return media
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun continueMediaQuery(type: String, status: String): String {
|
|
||||||
return """ MediaListCollection(userId: ${Anilist.userid}, type: $type, status: $status , sort: UPDATED_TIME ) { lists { entries { progress private score(format:POINT_100) status media { id idMal type isAdult status chapters episodes nextAiringEpisode {episode} meanScore isFavourite format bannerImage coverImage{large} title { english romaji userPreferred } } } } } """
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun favMedia(anime: Boolean, id: Int? = Anilist.userid): ArrayList<Media> {
|
private suspend fun favMedia(anime: Boolean, id: Int? = Anilist.userid): ArrayList<Media> {
|
||||||
var hasNextPage = true
|
var hasNextPage = true
|
||||||
|
@ -428,24 +426,14 @@ class AnilistQueries {
|
||||||
return responseArray
|
return responseArray
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun favMediaQuery(anime: Boolean, page: Int, id: Int? = Anilist.userid): String {
|
|
||||||
return """User(id:${id}){id favourites{${if (anime) "anime" else "manga"}(page:$page){pageInfo{hasNextPage}edges{favouriteOrder node{id idMal isAdult mediaListEntry{ progress private score(format:POINT_100) status } chapters isFavourite format episodes nextAiringEpisode{episode}meanScore isFavourite format startDate{year month day} title{english romaji userPreferred}type status(version:2)bannerImage coverImage{large}}}}}}"""
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun recommendationQuery(): String {
|
|
||||||
return """ Page(page: 1, perPage:30) { pageInfo { total currentPage hasNextPage } recommendations(sort: RATING_DESC, onList: true) { rating userRating mediaRecommendation { id idMal isAdult mediaListEntry { progress private score(format:POINT_100) status } chapters isFavourite format episodes nextAiringEpisode {episode} popularity meanScore isFavourite format title {english romaji userPreferred } type status(version: 2) bannerImage coverImage { large } } } } """
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun recommendationPlannedQuery(type: String): String {
|
|
||||||
return """ MediaListCollection(userId: ${Anilist.userid}, type: $type, status: PLANNING${if (type == "ANIME") ", sort: MEDIA_POPULARITY_DESC" else ""} ) { lists { entries { media { id mediaListEntry { progress private score(format:POINT_100) status } idMal type isAdult popularity status(version: 2) chapters episodes nextAiringEpisode {episode} meanScore isFavourite format bannerImage coverImage{large} title { english romaji userPreferred } } } } }"""
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getUserStatus(): ArrayList<User>? {
|
suspend fun getUserStatus(): ArrayList<User>? {
|
||||||
val toShow: List<Boolean> =
|
val toShow: List<Boolean> =
|
||||||
PrefManager.getVal(PrefName.HomeLayout)
|
PrefManager.getVal(PrefName.HomeLayout)
|
||||||
if (toShow.getOrNull(7) != true) return null
|
if (toShow.getOrNull(7) != true) return null
|
||||||
val query = """{Page1:${status(1)}Page2:${status(2)}}"""
|
val query = """{Page1:${status(1)}Page2:${status(2)}}"""
|
||||||
val response = executeQuery<Query.HomePageMedia>(query, show = true)
|
val response = executeQuery<Query.HomePageMedia>(query)
|
||||||
val list = mutableListOf<User>()
|
val list = mutableListOf<User>()
|
||||||
val threeDaysAgo = Calendar.getInstance().apply {
|
val threeDaysAgo = Calendar.getInstance().apply {
|
||||||
add(Calendar.DAY_OF_MONTH, -3)
|
add(Calendar.DAY_OF_MONTH, -3)
|
||||||
|
@ -497,7 +485,19 @@ class AnilistQueries {
|
||||||
return list.toCollection(ArrayList())
|
return list.toCollection(ArrayList())
|
||||||
} else return null
|
} else return null
|
||||||
}
|
}
|
||||||
|
private fun favMediaQuery(anime: Boolean, page: Int, id: Int? = Anilist.userid): String {
|
||||||
|
return """User(id:${id}){id favourites{${if (anime) "anime" else "manga"}(page:$page){pageInfo{hasNextPage}edges{favouriteOrder node{id idMal isAdult mediaListEntry{ progress private score(format:POINT_100) status } chapters isFavourite format episodes nextAiringEpisode{episode}meanScore isFavourite format startDate{year month day} title{english romaji userPreferred}type status(version:2)bannerImage coverImage{large}}}}}}"""
|
||||||
|
}
|
||||||
|
private fun recommendationQuery(): String {
|
||||||
|
return """ Page(page: 1, perPage:30) { pageInfo { total currentPage hasNextPage } recommendations(sort: RATING_DESC, onList: true) { rating userRating mediaRecommendation { id idMal isAdult mediaListEntry { progress private score(format:POINT_100) status } chapters isFavourite format episodes nextAiringEpisode {episode} popularity meanScore isFavourite format title {english romaji userPreferred } type status(version: 2) bannerImage coverImage { large } } } } """
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun recommendationPlannedQuery(type: String): String {
|
||||||
|
return """ MediaListCollection(userId: ${Anilist.userid}, type: $type, status: PLANNING${if (type == "ANIME") ", sort: MEDIA_POPULARITY_DESC" else ""} ) { lists { entries { media { id mediaListEntry { progress private score(format:POINT_100) status } idMal type isAdult popularity status(version: 2) chapters episodes nextAiringEpisode {episode} meanScore isFavourite format bannerImage coverImage{large} title { english romaji userPreferred } } } } }"""
|
||||||
|
}
|
||||||
|
private fun continueMediaQuery(type: String, status: String): String {
|
||||||
|
return """ MediaListCollection(userId: ${Anilist.userid}, type: $type, status: $status , sort: UPDATED_TIME ) { lists { entries { progress private score(format:POINT_100) status media { id idMal type isAdult status chapters episodes nextAiringEpisode {episode} meanScore isFavourite format bannerImage coverImage{large} title { english romaji userPreferred } } } } } """
|
||||||
|
}
|
||||||
suspend fun initHomePage(): Map<String, ArrayList<Media>> {
|
suspend fun initHomePage(): Map<String, ArrayList<Media>> {
|
||||||
val removeList = PrefManager.getCustomVal("removeList", setOf<Int>())
|
val removeList = PrefManager.getCustomVal("removeList", setOf<Int>())
|
||||||
val hidePrivate = PrefManager.getVal<Boolean>(PrefName.HidePrivate)
|
val hidePrivate = PrefManager.getVal<Boolean>(PrefName.HidePrivate)
|
||||||
|
|
|
@ -1,24 +1,19 @@
|
||||||
package ani.dantotsu.connections.discord
|
package ani.dantotsu.connections.discord
|
||||||
|
|
||||||
|
import ani.dantotsu.connections.discord.Discord.token
|
||||||
import ani.dantotsu.connections.discord.serializers.Activity
|
import ani.dantotsu.connections.discord.serializers.Activity
|
||||||
import ani.dantotsu.connections.discord.serializers.Presence
|
import ani.dantotsu.connections.discord.serializers.Presence
|
||||||
import ani.dantotsu.settings.saving.PrefManager
|
import ani.dantotsu.settings.saving.PrefManager
|
||||||
import ani.dantotsu.settings.saving.PrefName
|
import ani.dantotsu.settings.saving.PrefName
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import ani.dantotsu.client as app
|
import java.util.concurrent.TimeUnit.SECONDS
|
||||||
|
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
open class RPC(val token: String, val coroutineContext: CoroutineContext) {
|
open class RPC(val token: String, val coroutineContext: CoroutineContext) {
|
||||||
|
|
||||||
private val json = Json {
|
|
||||||
encodeDefaults = true
|
|
||||||
allowStructuredMapKeys = true
|
|
||||||
ignoreUnknownKeys = true
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class Type {
|
enum class Type {
|
||||||
PLAYING, STREAMING, LISTENING, WATCHING, COMPETING
|
PLAYING, STREAMING, LISTENING, WATCHING, COMPETING
|
||||||
}
|
}
|
||||||
|
@ -27,7 +22,7 @@ open class RPC(val token: String, val coroutineContext: CoroutineContext) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
data class RPCData(
|
data class RPCData(
|
||||||
val applicationId: String? = null,
|
val applicationId: String,
|
||||||
val type: Type? = null,
|
val type: Type? = null,
|
||||||
val activityName: String? = null,
|
val activityName: String? = null,
|
||||||
val details: String? = null,
|
val details: String? = null,
|
||||||
|
@ -39,23 +34,21 @@ open class RPC(val token: String, val coroutineContext: CoroutineContext) {
|
||||||
val stopTimestamp: Long? = null,
|
val stopTimestamp: Long? = null,
|
||||||
val buttons: MutableList<Link> = mutableListOf()
|
val buttons: MutableList<Link> = mutableListOf()
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class KizzyApi(val id: String)
|
|
||||||
|
|
||||||
val api = "https://kizzy-api.vercel.app/image?url="
|
|
||||||
private suspend fun String.discordUrl(): String? {
|
|
||||||
if (startsWith("mp:")) return this
|
|
||||||
val json = app.get("$api$this").parsedSafe<KizzyApi>()
|
|
||||||
return json?.id
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun createPresence(data: RPCData): String {
|
suspend fun createPresence(data: RPCData): String {
|
||||||
val json = Json {
|
val json = Json {
|
||||||
encodeDefaults = true
|
encodeDefaults = true
|
||||||
allowStructuredMapKeys = true
|
allowStructuredMapKeys = true
|
||||||
ignoreUnknownKeys = true
|
ignoreUnknownKeys = true
|
||||||
}
|
}
|
||||||
|
val client = OkHttpClient.Builder()
|
||||||
|
.connectTimeout(10, SECONDS)
|
||||||
|
.readTimeout(10, SECONDS)
|
||||||
|
.writeTimeout(10, SECONDS)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val assetApi = RPCExternalAsset(data.applicationId, token!!, client, json)
|
||||||
|
suspend fun String.discordUrl() = assetApi.getDiscordUri(this)
|
||||||
|
|
||||||
return json.encodeToString(Presence.Response(
|
return json.encodeToString(Presence.Response(
|
||||||
3,
|
3,
|
||||||
Presence(
|
Presence(
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package ani.dantotsu.connections.discord
|
||||||
|
|
||||||
|
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import okhttp3.Call
|
||||||
|
import okhttp3.Callback
|
||||||
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
import okhttp3.Response
|
||||||
|
import okio.IOException
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.resumeWithException
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
|
class RPCExternalAsset(
|
||||||
|
applicationId: String,
|
||||||
|
private val token: String,
|
||||||
|
private val client: OkHttpClient,
|
||||||
|
private val json: Json
|
||||||
|
) {
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class ExternalAsset(
|
||||||
|
val url: String? = null,
|
||||||
|
@SerialName("external_asset_path")
|
||||||
|
val externalAssetPath: String? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
private val api = "https://discord.com/api/v9/applications/$applicationId/external-assets"
|
||||||
|
suspend fun getDiscordUri(imageUrl: String): String? {
|
||||||
|
if (imageUrl.startsWith("mp:")) return imageUrl
|
||||||
|
val request = Request.Builder().url(api).header("Authorization", token)
|
||||||
|
.post("{\"urls\":[\"$imageUrl\"]}".toRequestBody("application/json".toMediaType()))
|
||||||
|
.build()
|
||||||
|
return runCatching {
|
||||||
|
val res = client.newCall(request).await()
|
||||||
|
json.decodeFromString<List<ExternalAsset>>(res.body.string())
|
||||||
|
.firstOrNull()?.externalAssetPath?.let { "mp:$it" }
|
||||||
|
}.getOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend inline fun Call.await(): Response {
|
||||||
|
return suspendCoroutine {
|
||||||
|
enqueue(object : Callback {
|
||||||
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
|
it.resumeWithException(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResponse(call: Call, response: Response) {
|
||||||
|
it.resume(response)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -507,6 +507,8 @@ class Stories @JvmOverloads constructor(
|
||||||
leftPanelTouch()
|
leftPanelTouch()
|
||||||
} else if (event.x > rightQuarter) {
|
} else if (event.x > rightQuarter) {
|
||||||
rightPanelTouch()
|
rightPanelTouch()
|
||||||
|
} else {
|
||||||
|
resume()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resume()
|
resume()
|
||||||
|
@ -523,7 +525,8 @@ class Stories @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val deltaX = event.x - startX
|
val deltaX = event.x - startX
|
||||||
if (abs(deltaX) > swipeThreshold) {
|
val deltaY = event.y - startY
|
||||||
|
if (abs(deltaX) > swipeThreshold && !(abs(deltaY) > 10)) {
|
||||||
if (deltaX > 0) onStoriesPrevious()
|
if (deltaX > 0) onStoriesPrevious()
|
||||||
else onStoriesCompleted()
|
else onStoriesCompleted()
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,9 @@ class SettingsAddonActivity : AppCompatActivity() {
|
||||||
bottomMargin = navBarHeight
|
bottomMargin = navBarHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.addonSettingsBack.setOnClickListener { onBackPressedDispatcher.onBackPressed() }
|
addonSettingsBack.setOnClickListener { onBackPressedDispatcher.onBackPressed() }
|
||||||
|
|
||||||
binding.settingsRecyclerView.adapter = SettingsAdapter(
|
settingsRecyclerView.adapter = SettingsAdapter(
|
||||||
arrayListOf(
|
arrayListOf(
|
||||||
Settings(
|
Settings(
|
||||||
type = 1,
|
type = 1,
|
||||||
|
@ -207,7 +207,7 @@ class SettingsAddonActivity : AppCompatActivity() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
binding.settingsRecyclerView.layoutManager =
|
settingsRecyclerView.layoutManager =
|
||||||
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue