From ce8fe2d5db699627bc1477069679705b6e768b01 Mon Sep 17 00:00:00 2001 From: LuftVerbot <97435834+LuftVerbot@users.noreply.github.com> Date: Fri, 24 May 2024 21:12:24 +0200 Subject: [PATCH] Parameter Refactor. Should hopefully erase some bugs --- .../echo/extension/Convertors.kt | 21 ++- .../echo/extension/DeezerApi.kt | 96 +++++++------ .../echo/extension/DeezerBase.kt | 11 ++ .../echo/extension/DeezerExtension.kt | 132 ++++++++---------- 4 files changed, 132 insertions(+), 128 deletions(-) create mode 100644 app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerBase.kt diff --git a/app/src/main/java/dev/brahmkshatriya/echo/extension/Convertors.kt b/app/src/main/java/dev/brahmkshatriya/echo/extension/Convertors.kt index 6f5215f..047e3b6 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/extension/Convertors.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/extension/Convertors.kt @@ -18,47 +18,42 @@ import kotlinx.serialization.json.jsonPrimitive fun JsonElement.toMediaItemsContainer( - api: DeezerApi = DeezerApi(), name: String? ): MediaItemsContainer { val itemsArray = jsonObject["items"]!!.jsonArray return MediaItemsContainer.Category( title = name ?: "Unknown", list = itemsArray.mapNotNull { item -> - item.jsonObject.toEchoMediaItem(api) + item.jsonObject.toEchoMediaItem() } ) } fun JsonObject.toMediaItemsContainer( - api: DeezerApi = DeezerApi(), name: String? ): MediaItemsContainer { return MediaItemsContainer.Category( title = name ?: "Unknown", - list = listOf(jsonObject.toEchoMediaItem(api) ?: emptyList().first()) + list = listOf(jsonObject.toEchoMediaItem() ?: emptyList().first()) ) } fun JsonArray.toMediaItemsContainer( - api: DeezerApi = DeezerApi(), name: String? ): MediaItemsContainer { val itemsArray = jsonArray return MediaItemsContainer.Category( title = name ?: "Unknown", list = itemsArray.mapNotNull { item -> - item.jsonObject.toEchoMediaItem(api) + item.jsonObject.toEchoMediaItem() } ) } -fun JsonElement.toEchoMediaItem( - api: DeezerApi -): EchoMediaItem? { +fun JsonElement.toEchoMediaItem(): EchoMediaItem? { val data = jsonObject["data"]?.jsonObject ?: jsonObject val type = data["__TYPE__"]!!.jsonPrimitive.content return when { - type.contains("playlist") -> EchoMediaItem.Lists.PlaylistItem(toPlaylist(api)) + type.contains("playlist") -> EchoMediaItem.Lists.PlaylistItem(toPlaylist()) type.contains("album") -> EchoMediaItem.Lists.AlbumItem(toAlbum()) type.contains("song") -> EchoMediaItem.TrackItem(toTrack()) type.contains("artist") -> EchoMediaItem.Profile.ArtistItem(toArtist()) @@ -101,12 +96,12 @@ fun JsonElement.toTrack(): Track { cover = getCover(md5, "cover"), extras = mapOf( "TRACK_TOKEN" to (data["TRACK_TOKEN"]?.jsonPrimitive?.content ?: ""), - "FILESIZE_MP3_MISC" to (data["FILESIZE_MP3_MISC"]?.jsonPrimitive?.content ?: "") + "FILESIZE_MP3_MISC" to (data["FILESIZE_MP3_MISC"]?.jsonPrimitive?.content ?: "0") ) ) } -fun JsonElement.toPlaylist(api: DeezerApi): Playlist { +fun JsonElement.toPlaylist(): Playlist { val data = jsonObject["data"]?.jsonObject ?: jsonObject["DATA"]?.jsonObject ?: jsonObject val type = data["PICTURE_TYPE"]?.jsonPrimitive?.content ?: "" val md5 = data["PLAYLIST_PICTURE"]?.jsonPrimitive?.content ?: "" @@ -116,7 +111,7 @@ fun JsonElement.toPlaylist(api: DeezerApi): Playlist { cover = getCover(md5, type), description = data["DESCRIPTION"]?.jsonPrimitive?.content ?: "", subtitle = jsonObject["subtitle"]?.jsonPrimitive?.content ?: "", - isEditable = data["PARENT_USER_ID"]!!.jsonPrimitive.content == api.userId, + isEditable = data["PARENT_USER_ID"]!!.jsonPrimitive.content == DeezerCredentials.userId, tracks = data["NB_SONG"]?.jsonPrimitive?.int ?: 0, ) } diff --git a/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerApi.kt b/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerApi.kt index 157de4b..0d4f751 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerApi.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerApi.kt @@ -27,22 +27,36 @@ import java.util.zip.GZIPInputStream // Settings placeholder class Settings { - val deezerLanguage: String? = "en" - val deezerCountry: String? = "US" + val deezerLanguage: String = "en" + val deezerCountry: String = "US" } -class DeezerApi( - private var arl: String = "", - private var sid: String = "", - private var token: String = "", - var userId: String = "", - private var licenseToken: String = "", - private var userName: String = "", - private var favoritesPlaylistId: String = "" -) { +class DeezerApi { private val settings = Settings() + // Access shared email and pass + private val arl: String + get() = DeezerCredentials.arl + + private val sid: String + get() = DeezerCredentials.sid + + private val token: String + get() = DeezerCredentials.token + + private val userId: String + get() = DeezerCredentials.userId + + private val licenseToken: String + get() = DeezerCredentials.licenseToken + + private val email: String + get() = DeezerCredentials.email + + private val pass: String + get() = DeezerCredentials.pass + private val client: OkHttpClient = OkHttpClient.Builder() .addInterceptor { chain -> val originalResponse = chain.proceed(chain.request()) @@ -66,10 +80,10 @@ class DeezerApi( headersBuilder.add("Accept", "*/*") headersBuilder.add("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.3") headersBuilder.add("Accept-Encoding", "gzip") - headersBuilder.add("Accept-Language", settings.deezerLanguage ?: "en") + headersBuilder.add("Accept-Language", settings.deezerLanguage) headersBuilder.add("Cache-Control", "max-age=0") headersBuilder.add("Connection", "keep-alive") - headersBuilder.add("Content-Language", "${settings.deezerLanguage ?: "en"}-${settings.deezerCountry ?: "US"}") + headersBuilder.add("Content-Language", "${settings.deezerLanguage}-${settings.deezerCountry}") headersBuilder.add("Content-Type", "application/json; charset=utf-8") if (method != "user.getArl") { headersBuilder.add("Cookie", "arl=$arl; sid=$sid") @@ -121,27 +135,24 @@ class DeezerApi( val responseBody = response.body?.string() val body = responseBody.toString() - body - } + if (method == "deezer.getUserData") { + response.headers.forEach { + if (it.second.startsWith("sid=")) { + DeezerCredentials.sid = it.second.substringAfter("sid=").substringBefore(";") + } + } + } - private suspend fun rawAuthorize(): Boolean { - val jsonData = callApi("deezer.getUserData") - val jObject = json.decodeFromString(jsonData) - val userResults = jObject["results"] - val user = userResults!!.jsonObject["USER"] - val userId = user!!.jsonObject["USER_ID"]!!.jsonPrimitive.content - if (userId.contentEquals("0")) { - return false - } else { - //token = userResults.jsonObject["checkForm"]!!.jsonPrimitive.content - //userId = user.jsonObject["USER_ID"]!!.jsonPrimitive.int.toString() - userName = user.jsonObject["BLOG_NAME"]!!.jsonPrimitive.content - favoritesPlaylistId = user.jsonObject["LOVEDTRACKS_ID"]!!.jsonPrimitive.content - return true + if(body.contains("\"VALID_TOKEN_REQUIRED\":\"Invalid CSRF token\"")) { + val userList = DeezerExtension().onLogin(email, pass) + DeezerExtension().onSetLoginUser(userList.first()) + return@withContext callApi(method, params, gatewayInput) } + + body } - suspend fun makeUser(): List { + suspend fun makeUser(email: String = "", pass: String = ""): List { val userList = mutableListOf() val jsonData = callApi("deezer.getUserData") val jObject = json.decodeFromString(jsonData) @@ -161,16 +172,18 @@ class DeezerApi( "user_id" to userId, "sid" to sid, "token" to token, - "license_token" to licenseToken + "license_token" to licenseToken, + "email" to email, + "pass" to pass ) ) userList.add(user) return userList } - suspend fun getArlByEmail(mail: String, password: String): Map { + suspend fun getArlByEmail(mail: String, password: String) { //Get SID - getSid() + //getSid() val clientId = "447462" val clientSecret = "a83bf7f38ad2f137e444727cfc3775cf" @@ -186,18 +199,12 @@ class DeezerApi( //Get access token val responseJson = getToken(params) val apiResponse = json.decodeFromString(responseJson) - token = apiResponse.jsonObject["access_token"]!!.jsonPrimitive.content + DeezerCredentials.token = apiResponse.jsonObject["access_token"]!!.jsonPrimitive.content // Get ARL val arlResponse = callApi("user.getArl") val arlObject = json.decodeFromString(arlResponse) - arl = arlObject["results"]!!.jsonPrimitive.content - - return mapOf( - "arl" to arl, - "token" to token, - "sid" to sid - ) + DeezerCredentials.arl = arlObject["results"]!!.jsonPrimitive.content } private fun md5(input: String): String { @@ -229,7 +236,7 @@ class DeezerApi( } } - fun getSid(): String { + fun getSid() { //Get SID val url = "https://www.deezer.com/" val request = Request.Builder() @@ -240,16 +247,15 @@ class DeezerApi( val response = client.newCall(request).execute() response.headers.forEach { if (it.second.startsWith("sid=")) { - sid = it.second.substringAfter("sid=").substringBefore(";") + DeezerCredentials.sid = it.second.substringAfter("sid=").substringBefore(";") } } - return sid } suspend fun getMP3MediaUrl(track: Track): JsonObject = withContext(Dispatchers.IO) { val headersBuilder = Headers.Builder() headersBuilder.add("Accept-Encoding", "gzip") - headersBuilder.add("Accept-Language", settings.deezerLanguage ?: "en") + headersBuilder.add("Accept-Language", settings.deezerLanguage) headersBuilder.add("Cache-Control", "max-age=0") headersBuilder.add("Connection", "Keep-alive") headersBuilder.add("Content-Type", "application/json; charset=utf-8") diff --git a/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerBase.kt b/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerBase.kt new file mode 100644 index 0000000..a579ecb --- /dev/null +++ b/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerBase.kt @@ -0,0 +1,11 @@ +package dev.brahmkshatriya.echo.extension + +object DeezerCredentials { + var arl: String = "" + var sid: String = "" + var token: String = "" + var userId: String = "" + var licenseToken: String = "" + var email: String = "" + var pass: String = "" +} diff --git a/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerExtension.kt b/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerExtension.kt index 381f859..f30043b 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerExtension.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerExtension.kt @@ -1,6 +1,5 @@ package dev.brahmkshatriya.echo.extension -import android.util.Log import dev.brahmkshatriya.echo.common.clients.AlbumClient import dev.brahmkshatriya.echo.common.clients.ArtistClient import dev.brahmkshatriya.echo.common.clients.ExtensionClient @@ -52,25 +51,9 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie this.settings = settings } - private var arl: String - get() = settings.getString("arl") ?: "" - set(value) = settings.putString("arl", value) - - private var sid: String - get() = settings.getString("sid") ?: "" - set(value) = settings.putString("sid", value) - - private var userId: String - get() = settings.getString("user_id") ?: "" - set(value) = settings.putString("user_id", value) - - private var token: String - get() = settings.getString("token") ?: "" - set(value) = settings.putString("token", value) - - private var licenseToken: String - get() = settings.getString("license_token") ?: "" - set(value) = settings.putString("license_token", value) + // Access shared email and pass + private val arl: String + get() = DeezerCredentials.arl override suspend fun onExtensionSelected() {} @@ -78,7 +61,7 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie override suspend fun getHomeTabs(): List { if (arl == "") return emptyList() - val jObject = DeezerApi(arl, sid, token, userId).homePage() + val jObject = DeezerApi().homePage() val resultObject = jObject["results"]!!.jsonObject val sections = resultObject["sections"]!!.jsonArray val tab = Tab( @@ -116,34 +99,34 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie allTabs = "all" to tabs.mapNotNull { tab -> when(tab.id) { "playlists" -> { - val jsonObject = DeezerApi(arl, sid, token, userId).getPlaylists() + val jsonObject = DeezerApi().getPlaylists() val resultObject = jsonObject["results"]!!.jsonObject val tabObject = resultObject["TAB"]!!.jsonObject val playlistObject = tabObject["playlists"]!!.jsonObject val dataArray = playlistObject["data"]!!.jsonArray - dataArray.toMediaItemsContainer(DeezerApi(arl, sid, token, userId), tab.name) + dataArray.toMediaItemsContainer(tab.name) } "albums" -> { - val jsonObject = DeezerApi(arl, sid, token, userId).getAlbums() + val jsonObject = DeezerApi().getAlbums() val resultObject = jsonObject["results"]!!.jsonObject val tabObject = resultObject["TAB"]!!.jsonObject val playlistObject = tabObject["albums"]!!.jsonObject val dataArray = playlistObject["data"]!!.jsonArray - dataArray.toMediaItemsContainer(DeezerApi(arl, sid, token, userId), tab.name) + dataArray.toMediaItemsContainer(tab.name) } "tracks" -> { - val jsonObject = DeezerApi(arl, sid, token, userId).getTracks() + val jsonObject = DeezerApi().getTracks() val resultObject = jsonObject["results"]!!.jsonObject val dataArray = resultObject["data"]!!.jsonArray - dataArray.toMediaItemsContainer(DeezerApi(arl, sid, token, userId), tab.name) + dataArray.toMediaItemsContainer(tab.name) } "artists" -> { - val jsonObject = DeezerApi(arl, sid, token, userId).getArtists() + val jsonObject = DeezerApi().getArtists() val resultObject = jsonObject["results"]!!.jsonObject val tabObject = resultObject["TAB"]!!.jsonObject val playlistObject = tabObject["artists"]!!.jsonObject val dataArray = playlistObject["data"]!!.jsonArray - dataArray.toMediaItemsContainer(DeezerApi(arl, sid, token, userId), tab.name) + dataArray.toMediaItemsContainer(tab.name) } else -> { null @@ -163,51 +146,51 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie if (all != null) return@Single all } "playlists" -> { - val jsonObject = DeezerApi(arl, sid, token, userId).getPlaylists() + val jsonObject = DeezerApi().getPlaylists() val resultObject = jsonObject["results"]!!.jsonObject val tabObject = resultObject["TAB"]!!.jsonObject val playlistObject = tabObject["playlists"]!!.jsonObject val dataArray = playlistObject["data"]!!.jsonArray val itemArray = dataArray.mapNotNull { item -> - item.toEchoMediaItem(DeezerApi(arl, sid, token, userId))?.toMediaItemsContainer() + item.toEchoMediaItem()?.toMediaItemsContainer() } list = itemArray } "albums" -> { - val jsonObject = DeezerApi(arl, sid, token, userId).getAlbums() + val jsonObject = DeezerApi().getAlbums() val resultObject = jsonObject["results"]!!.jsonObject val tabObject = resultObject["TAB"]!!.jsonObject val playlistObject = tabObject["albums"]!!.jsonObject val dataArray = playlistObject["data"]!!.jsonArray val itemArray = dataArray.mapNotNull { item -> - item.toEchoMediaItem(DeezerApi(arl, sid, token, userId))?.toMediaItemsContainer() + item.toEchoMediaItem()?.toMediaItemsContainer() } list = itemArray } "tracks" -> { - val jsonObject = DeezerApi(arl, sid, token, userId).getTracks() + val jsonObject = DeezerApi().getTracks() val resultObject = jsonObject["results"]!!.jsonObject val dataArray = resultObject["data"]!!.jsonArray val itemArray = dataArray.mapNotNull { item -> - item.toEchoMediaItem(DeezerApi(arl, sid, token, userId))?.toMediaItemsContainer() + item.toEchoMediaItem()?.toMediaItemsContainer() } list = itemArray } "artists" -> { - val jsonObject = DeezerApi(arl, sid, token, userId).getArtists() + val jsonObject = DeezerApi().getArtists() val resultObject = jsonObject["results"]!!.jsonObject val tabObject = resultObject["TAB"]!!.jsonObject val playlistObject = tabObject["artists"]!!.jsonObject val dataArray = playlistObject["data"]!!.jsonArray val itemArray = dataArray.mapNotNull { item -> - item.toEchoMediaItem(DeezerApi(arl, sid, token, userId))?.toMediaItemsContainer() + item.toEchoMediaItem()?.toMediaItemsContainer() } list = itemArray } @@ -251,7 +234,7 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie override suspend fun quickSearch(query: String?) = query?.run { try { - val jsonObject = DeezerApi(arl, sid, token, userId).searchSuggestions(query) + val jsonObject = DeezerApi().searchSuggestions(query) val resultObject = jsonObject["results"]!!.jsonObject val suggestionArray = resultObject["SUGGESTION"]!!.jsonArray suggestionArray.map { item -> @@ -276,13 +259,13 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie var list = listOf() if(tab?.id != "TOP_RESULT") { - val jsonObject = DeezerApi(arl, sid, token, userId).search(query) + val jsonObject = DeezerApi().search(query) val resultObject = jsonObject["results"]!!.jsonObject val tabObject = resultObject[tab?.id]!!.jsonObject val dataArray = tabObject["data"]!!.jsonArray val itemArray = dataArray.mapNotNull { item -> - item.toEchoMediaItem(DeezerApi(arl, sid, token, userId))?.toMediaItemsContainer() + item.toEchoMediaItem()?.toMediaItemsContainer() } list = itemArray } @@ -292,7 +275,7 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie override suspend fun searchTabs(query: String?): List { if (arl == "") return emptyList() query ?: return emptyList() - val jsonObject = DeezerApi(arl, sid, token, userId).search(query) + val jsonObject = DeezerApi().search(query) val resultObject = jsonObject["results"]!!.jsonObject val orderObject = resultObject["ORDER"]!!.jsonArray @@ -311,7 +294,7 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie val name = tab.id val tabObject = resultObject[name]!!.jsonObject val dataArray = tabObject["data"]!!.jsonArray - dataArray.toMediaItemsContainer(DeezerApi(arl, sid, token, userId), name.lowercase().capitalize( + dataArray.toMediaItemsContainer(name.lowercase().capitalize( Locale.ROOT)) } return listOf(Tab("All", "All")) + tabs @@ -326,10 +309,10 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie override suspend fun getStreamableVideo(streamable: Streamable) = throw Exception("not Used") override suspend fun loadTrack(track: Track) = coroutineScope { - val jsonObject = if (track.extras["FILESIZE_MP3_MISC"] != "") { - DeezerApi(arl, sid, token, userId, licenseToken).getMP3MediaUrl(track) + val jsonObject = if (track.extras["FILESIZE_MP3_MISC"] != "0") { + DeezerApi().getMP3MediaUrl(track) } else { - DeezerApi(arl, sid, token, userId, licenseToken).getMediaUrl(track) + DeezerApi().getMediaUrl(track) } val dataObject = jsonObject["data"]!!.jsonArray.first().jsonObject val mediaObject = dataObject["media"]!!.jsonArray.first().jsonObject @@ -365,7 +348,7 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie //<============= Album =============> override fun getMediaItems(album: Album) = PagedData.Single { - val jsonObject = DeezerApi(arl, sid, token, userId).album(album) + val jsonObject = DeezerApi().album(album) val resultsObject = jsonObject["results"]!!.jsonObject val songsObject = resultsObject["SONGS"]!!.jsonObject val dataArray = songsObject["data"]!!.jsonArray @@ -376,13 +359,13 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie } override suspend fun loadAlbum(album: Album): Album { - val jsonObject = DeezerApi(arl, sid, token, userId).album(album) + val jsonObject = DeezerApi().album(album) val resultsObject = jsonObject["results"]!!.jsonObject return resultsObject.toAlbum() } override fun loadTracks(album: Album): PagedData = PagedData.Single { - val jsonObject = DeezerApi(arl, sid, token, userId).album(album) + val jsonObject = DeezerApi().album(album) val resultsObject = jsonObject["results"]!!.jsonObject val songsObject = resultsObject["SONGS"]!!.jsonObject val dataArray = songsObject["data"]!!.jsonArray @@ -395,7 +378,7 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie //<============= Playlist =============> override fun getMediaItems(playlist: Playlist) = PagedData.Single { - val jsonObject = DeezerApi(arl, sid, token, userId).playlist(playlist) + val jsonObject = DeezerApi().playlist(playlist) val resultsObject = jsonObject["results"]!!.jsonObject val songsObject = resultsObject["SONGS"]!!.jsonObject val dataArray = songsObject["data"]!!.jsonArray @@ -406,13 +389,13 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie } override suspend fun loadPlaylist(playlist: Playlist): Playlist { - val jsonObject = DeezerApi(arl, sid, token, userId).playlist(playlist) + val jsonObject = DeezerApi().playlist(playlist) val resultsObject = jsonObject["results"]!!.jsonObject - return resultsObject.toPlaylist(DeezerApi(userId = userId)) + return resultsObject.toPlaylist() } override fun loadTracks(playlist: Playlist): PagedData = PagedData.Single { - val jsonObject = DeezerApi(arl, sid, token, userId).playlist(playlist) + val jsonObject = DeezerApi().playlist(playlist) val resultsObject = jsonObject["results"]!!.jsonObject val songsObject = resultsObject["SONGS"]!!.jsonObject val dataArray = songsObject["data"]!!.jsonArray @@ -426,7 +409,8 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie override fun getMediaItems(artist: Artist) = PagedData.Single { val dataList = mutableListOf() - val jsonObject = DeezerApi(arl, sid, token, userId).artist(artist) + val jsonObject = DeezerApi().artist(artist) + val resultsObject = jsonObject["results"]!!.jsonObject for (result in resultsObject) { when (result.key) { @@ -472,7 +456,7 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie } override suspend fun loadArtist(artist: Artist): Artist { - val jsonObject = DeezerApi(arl, sid, token, userId).artist(artist) + val jsonObject = DeezerApi().artist(artist) val resultsObject = jsonObject["results"]!!.jsonObject["DATA"]!!.jsonObject return resultsObject.toArtist() } @@ -488,9 +472,9 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie override suspend fun onLoginWebviewStop(url: String, cookie: String): List { if (cookie.contains("arl=")) { - val arl = cookie.substringAfter("arl=").substringBefore(";") - val sid = cookie.substringAfter("sid=").substringBefore(";") - val userList = DeezerApi(arl, sid).makeUser() + DeezerCredentials.arl = cookie.substringAfter("arl=").substringBefore(";") + DeezerCredentials.sid = cookie.substringAfter("sid=").substringBefore(";") + val userList = DeezerApi().makeUser() return userList } else { return emptyList() @@ -509,28 +493,36 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie ) override suspend fun onLogin(data: Map): List { - val arl = data["arl"] ?: "" - val sid = DeezerApi().getSid() - val userList = DeezerApi(arl, sid).makeUser() + DeezerCredentials.arl = data["arl"] ?: "" + DeezerApi().getSid() + val userList = DeezerApi().makeUser() return userList } override suspend fun onLogin(username: String, password: String): List { - val map = DeezerApi().getArlByEmail(username, password) - val arl = map["arl"] ?: "" - val token = map["token"] ?: "" - val sid = map["sid"] ?: "" - val userList = DeezerApi(arl, sid, token).makeUser() + // Set shared credentials + DeezerCredentials.email = username + DeezerCredentials.pass = password + + DeezerApi().getArlByEmail(username, password) + val userList = DeezerApi().makeUser(username, password) return userList } + suspend fun reLogin(username: String, password: String) { + DeezerApi().getArlByEmail(username, password) + DeezerApi().makeUser(username, password) + } + override suspend fun onSetLoginUser(user: User?) { if (user != null) { - arl = user.extras["arl"] ?: "" - userId = user.extras["user_id"] ?: "" - sid = user.extras["sid"] ?: "" - token = user.extras["token"] ?: "" - licenseToken = user.extras["license_token"] ?: "" + DeezerCredentials.arl = user.extras["arl"] ?: "" + DeezerCredentials.userId = user.extras["user_id"] ?: "" + DeezerCredentials.sid = user.extras["sid"] ?: "" + DeezerCredentials.token = user.extras["token"] ?: "" + DeezerCredentials.licenseToken = user.extras["license_token"] ?: "" + DeezerCredentials.email = user.extras["email"] ?: "" + DeezerCredentials.pass = user.extras["pass"] ?: "" } } } \ No newline at end of file