Skip to content

Commit

Permalink
Add fallback url
Browse files Browse the repository at this point in the history
  • Loading branch information
LuftVerbot committed May 29, 2024
1 parent 6c1bd63 commit 8da43a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
val name = "Deezer"
val version = "1.0.0"
val description = "Deezer Extension for Echo."
val author = "luft"
val author = "LuftVerbot"
val iconUrl = "https://e-cdn-files.dzcdn.net/cache/images/common/favicon/favicon-240x240.bb3a6a29ad16a77f10cb.png"

applicationId = "dev.brahmkshatriya.echo.extension.deezer"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package dev.brahmkshatriya.echo.extension

import dev.brahmkshatriya.echo.common.exceptions.LoginRequiredException
import dev.brahmkshatriya.echo.common.models.Album
import dev.brahmkshatriya.echo.common.models.Artist
import dev.brahmkshatriya.echo.common.models.ExtensionType
import dev.brahmkshatriya.echo.common.models.ImageHolder.Companion.toImageHolder
import dev.brahmkshatriya.echo.common.models.Playlist
import dev.brahmkshatriya.echo.common.models.Track
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +14,6 @@ import dev.brahmkshatriya.echo.common.exceptions.LoginRequiredException
import dev.brahmkshatriya.echo.common.helpers.PagedData
import dev.brahmkshatriya.echo.common.models.Album
import dev.brahmkshatriya.echo.common.models.Artist
import dev.brahmkshatriya.echo.common.models.EchoMediaItem.Companion.toMediaItem
import dev.brahmkshatriya.echo.common.models.ExtensionType
import dev.brahmkshatriya.echo.common.models.MediaItemsContainer
import dev.brahmkshatriya.echo.common.models.Playlist
Expand All @@ -26,17 +24,16 @@ import dev.brahmkshatriya.echo.common.models.Tab
import dev.brahmkshatriya.echo.common.models.Track
import dev.brahmkshatriya.echo.common.models.User
import dev.brahmkshatriya.echo.common.settings.Setting
import dev.brahmkshatriya.echo.common.settings.SettingItem
import dev.brahmkshatriya.echo.common.settings.SettingSwitch
import dev.brahmkshatriya.echo.common.settings.Settings
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import okhttp3.OkHttpClient
import okhttp3.Request
import org.apache.http.conn.ConnectTimeoutException
import java.util.Locale

Expand Down Expand Up @@ -384,7 +381,17 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie
val dataObject = resultObject["data"]!!.jsonArray[0].jsonObject
val md5Origin = dataObject["MD5_ORIGIN"]?.jsonPrimitive?.content ?: ""
val mediaVersion = dataObject["MEDIA_VERSION"]?.jsonPrimitive?.content ?: ""
val url = generateTrackUrl(track.id, md5Origin, mediaVersion, 1)
var url = generateTrackUrl(track.id, md5Origin, mediaVersion, 1)

val request = Request.Builder().url(url).build()
val code = client.newCall(request).execute().code
if(code == 403) {
val fallbackObject = dataObject["FALLBACK"]!!.jsonObject
val backId = fallbackObject["SNG_ID"]?.jsonPrimitive?.content ?: ""
val backMd5Origin = fallbackObject["MD5_ORIGIN"]?.jsonPrimitive?.content ?: ""
val backMediaVersion = fallbackObject["MEDIA_VERSION"]?.jsonPrimitive?.content ?: ""
url = generateTrackUrl(backId, backMd5Origin, backMediaVersion, 1)
}

Track(
id = track.id,
Expand Down Expand Up @@ -596,13 +603,13 @@ class DeezerExtension : ExtensionClient, HomeFeedClient, TrackClient, SearchClie

//<============= Share =============>

override suspend fun onShare(album: Album): String = "https://www.deezer.com/us/album/${album.id}"
override suspend fun onShare(album: Album): String = "https://www.deezer.com/album/${album.id}"

override suspend fun onShare(artist: Artist): String = "https://www.deezer.com/us/artist/${artist.id}"
override suspend fun onShare(artist: Artist): String = "https://www.deezer.com/artist/${artist.id}"

override suspend fun onShare(playlist: Playlist): String = "https://www.deezer.com/us/playlist/${playlist.id}"
override suspend fun onShare(playlist: Playlist): String = "https://www.deezer.com/playlist/${playlist.id}"

override suspend fun onShare(track: Track): String = "https://www.deezer.com/us/track/${track.id}"
override suspend fun onShare(track: Track): String = "https://www.deezer.com/track/${track.id}"

override suspend fun onShare(user: User): String = "https://www.deezer.com/us/profile/${user.id}"
override suspend fun onShare(user: User): String = "https://www.deezer.com/profile/${user.id}"
}

0 comments on commit 8da43a9

Please sign in to comment.