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 a400b1f..7bef65d 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/extension/Convertors.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/extension/Convertors.kt @@ -98,26 +98,26 @@ fun JsonElement.toPlaylist(api: DeezerApi): Playlist { fun getCover(jsonObject: JsonObject, type: String? = null): ImageHolder { if(type != null) { val md5 = jsonObject["PLAYLIST_PICTURE"]!!.jsonPrimitive.content - val url = "https://e-cdns-images.dzcdn.net/images/$type/$md5/264x264-000000-80-0-0.jpg" + val url = "https://e-cdns-images.dzcdn.net/images/$type/$md5/1200x1200-000000-80-0-0.jpg" return url.toImageHolder() } else { if (jsonObject["pictures"]?.jsonArray != null) { val pictureArray = jsonObject["pictures"]!!.jsonArray val picObject = pictureArray.first().jsonObject val md5 = picObject["md5"]!!.jsonPrimitive.content - val type = picObject["type"]!!.jsonPrimitive.content - val url = "https://e-cdns-images.dzcdn.net/images/$type/$md5/264x264-000000-80-0-0.jpg" + val ownType = picObject["type"]!!.jsonPrimitive.content + val url = "https://e-cdns-images.dzcdn.net/images/$ownType/$md5/1200x1200-000000-80-0-0.jpg" return url.toImageHolder() } else if (jsonObject["DATA"]?.jsonObject != null) { val dataObject = jsonObject["DATA"]!!.jsonObject val md5 = dataObject["PLAYLIST_PICTURE"]?.jsonPrimitive?.content ?: dataObject["ALB_PICTURE"]?.jsonPrimitive?.content ?: "" - val type = dataObject["PICTURE_TYPE"]?.jsonPrimitive?.content ?: "cover" - val url = "https://e-cdns-images.dzcdn.net/images/$type/$md5/264x264-000000-80-0-0.jpg" + val ownType = dataObject["PICTURE_TYPE"]?.jsonPrimitive?.content ?: "cover" + val url = "https://e-cdns-images.dzcdn.net/images/$ownType/$md5/1200x1200-000000-80-0-0.jpg" return url.toImageHolder() } else { val md5 = jsonObject["ALB_PICTURE"]?.jsonPrimitive?.content ?: "" - val url = "https://e-cdns-images.dzcdn.net/images/cover/$md5/264x264-000000-80-0-0.jpg" + val url = "https://e-cdns-images.dzcdn.net/images/cover/$md5/1200x1200-000000-80-0-0.jpg" return url.toImageHolder() } } 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 61f998e..433befc 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerApi.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerApi.kt @@ -141,7 +141,7 @@ class DeezerApi( } } - suspend fun makeUser(): List{ + suspend fun makeUser(): List { val userList = mutableListOf() val jsonData = callApi("deezer.getUserData") val jObject = json.decodeFromString(jsonData) @@ -170,18 +170,7 @@ class DeezerApi( suspend fun getArlByEmail(mail: String, password: String): Map { //Get SID - val url = "https://www.deezer.com/" - val request = Request.Builder() - .url(url) - .get() - .build() - - val response = client.newCall(request).execute() - response.headers.forEach { - if(it.second.startsWith("sid=")) { - sid = it.second.substringAfter("sid=").substringBefore(";") - } - } + getSid() val clientId = "447462" val clientSecret = "a83bf7f38ad2f137e444727cfc3775cf" @@ -240,6 +229,23 @@ class DeezerApi( } } + fun getSid(): String { + //Get SID + val url = "https://www.deezer.com/" + val request = Request.Builder() + .url(url) + .get() + .build() + + val response = client.newCall(request).execute() + response.headers.forEach { + if (it.second.startsWith("sid=")) { + 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") @@ -307,7 +313,8 @@ class DeezerApi( // Create request body val requestBody = JSONObject(mapOf( - "formats" to arrayOf("FLAC", "MP3_320", "MP3_128", "MP3_64", "MP3_MISC"), + // Limit to 320 until download is added + "formats" to arrayOf(/*"FLAC", */"MP3_320", "MP3_128", "MP3_64", "MP3_MISC"), "ids" to arrayOf(track.id.toLong()) )).toString().toRequestBody("application/json; charset=utf-8".toMediaType()) 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 2084434..883c5e9 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerExtension.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/extension/DeezerExtension.kt @@ -36,7 +36,7 @@ import org.apache.http.conn.ConnectTimeoutException import java.util.Locale class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClient, AlbumClient, - PlaylistClient, LoginClient.WebView, LoginClient.UsernamePassword, LibraryClient { + PlaylistClient, LoginClient.WebView, LoginClient.UsernamePassword, LoginClient.CustomTextInput, LibraryClient { private val json = Json { isLenient = true @@ -417,6 +417,24 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie } } + override val loginInputFields: List + get() = listOf( + LoginClient.InputField( + key = "arl", + label = "ARL", + isRequired = false, + isPassword = true + + ) + ) + + override suspend fun onLogin(data: Map): List { + val arl = data["arl"] ?: "" + val sid = DeezerApi().getSid() + val userList = DeezerApi(arl, sid).makeUser() + return userList + } + override suspend fun onLogin(username: String, password: String): List { val map = DeezerApi().getArlByEmail(username, password) val arl = map["arl"] ?: ""