Skip to content

Commit

Permalink
Fixed #242 Added Spotify Search Lyrics
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Feb 9, 2024
1 parent 8493e01 commit 74d7f23
Show file tree
Hide file tree
Showing 25 changed files with 1,225 additions and 70 deletions.
5 changes: 4 additions & 1 deletion app/src/main/java/com/maxrave/simpmusic/common/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ object Config {
NOT_FOUND
}

const val SPOTIFY_LOG_IN_URL: String = "https://accounts.spotify.com/en/login"
const val SPOTIFY_ACCOUNT_URL = "https://accounts.spotify.com/en/status"
const val YOUTUBE_MUSIC_MAIN_URL = "https://music.youtube.com/"
const val LOG_IN_URL = "https://accounts.google.com/ServiceLogin?ltmpl=music&service=youtube&uilel=3&passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26app%3Ddesktop%26hl%3Den%26next%3Dhttps%253A%252F%252Fmusic.youtube.com%252F%26feature%3D__FEATURE__&hl=en"
const val LOG_IN_URL =
"https://accounts.google.com/ServiceLogin?ltmpl=music&service=youtube&uilel=3&passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26app%3Ddesktop%26hl%3Den%26next%3Dhttps%253A%252F%252Fmusic.youtube.com%252F%26feature%3D__FEATURE__&hl=en"

const val SONG_CLICK = "SONG_CLICK"
const val VIDEO_CLICK = "VIDEO_CLICK"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.media3.common.Player
import com.maxrave.simpmusic.common.SELECTED_LANGUAGE
Expand Down Expand Up @@ -379,6 +380,90 @@ class DataStoreManager @Inject constructor(private val settingsDataStore: DataSt
}
}

val spdc = settingsDataStore.data.map { preferences ->
preferences[SPDC] ?: ""
}

suspend fun setSpdc(spdc: String) {
withContext(Dispatchers.IO) {
settingsDataStore.edit { settings ->
settings[SPDC] = spdc
}
}
}

val spotifyLyrics: Flow<String> = settingsDataStore.data.map { preferences ->
preferences[SPOTIFY_LYRICS] ?: FALSE
}

suspend fun setSpotifyLyrics(spotifyLyrics: Boolean) {
withContext(Dispatchers.IO) {
if (spotifyLyrics) {
settingsDataStore.edit { settings ->
settings[SPOTIFY_LYRICS] = TRUE
}
} else {
settingsDataStore.edit { settings ->
settings[SPOTIFY_LYRICS] = FALSE
}
}
}
}

val spotifyCanvas: Flow<String> = settingsDataStore.data.map { preferences ->
preferences[SPOTIFY_CANVAS] ?: FALSE
}

suspend fun setSpotifyCanvas(spotifyCanvas: Boolean) {
withContext(Dispatchers.IO) {
if (spotifyCanvas) {
settingsDataStore.edit { settings ->
settings[SPOTIFY_CANVAS] = TRUE
}
} else {
settingsDataStore.edit { settings ->
settings[SPOTIFY_CANVAS] = FALSE
}
}
}
}

val spotifyPersonalToken: Flow<String> = settingsDataStore.data.map { preferences ->
preferences[SPOTIFY_PERSONAL_TOKEN] ?: ""
}

suspend fun setSpotifyPersonalToken(token: String) {
withContext(Dispatchers.IO) {
settingsDataStore.edit { settings ->
settings[SPOTIFY_PERSONAL_TOKEN] = token
}
}
}

val spotifyPersonalTokenExpires: Flow<Long> = settingsDataStore.data.map { preferences ->
preferences[SPOTIFY_PERSONAL_TOKEN_EXPIRES] ?: 0
}

suspend fun setSpotifyPersonalTokenExpires(expires: Long) {
withContext(Dispatchers.IO) {
settingsDataStore.edit { settings ->
settings[SPOTIFY_PERSONAL_TOKEN_EXPIRES] = expires
}
}
}

val spotifyClientToken: Flow<String> = settingsDataStore.data.map { preferences ->
preferences[SPOTIFY_CLIENT_TOKEN] ?: ""
}

suspend fun setSpotifyClientToken(token: String) {
withContext(Dispatchers.IO) {
settingsDataStore.edit { settings ->
settings[SPOTIFY_CLIENT_TOKEN] = token
}
}
}

companion object Settings {
val COOKIE = stringPreferencesKey("cookie")
val LOGGED_IN = stringPreferencesKey("logged_in")
Expand Down Expand Up @@ -408,6 +493,12 @@ class DataStoreManager @Inject constructor(private val settingsDataStore: DataSt
val WATCH_VIDEO_INSTEAD_OF_PLAYING_AUDIO =
stringPreferencesKey("watch_video_instead_of_playing_audio")
val VIDEO_QUALITY = stringPreferencesKey("video_quality")
val SPDC = stringPreferencesKey("sp_dc")
val SPOTIFY_LYRICS = stringPreferencesKey("spotify_lyrics")
val SPOTIFY_CANVAS = stringPreferencesKey("spotify_canvas")
val SPOTIFY_PERSONAL_TOKEN = stringPreferencesKey("spotify_personal_token")
val SPOTIFY_PERSONAL_TOKEN_EXPIRES = longPreferencesKey("spotify_personal_token_expires")
val SPOTIFY_CLIENT_TOKEN = stringPreferencesKey("spotify_client_token")
const val REPEAT_MODE_OFF = "REPEAT_MODE_OFF"
const val REPEAT_ONE = "REPEAT_ONE"
const val REPEAT_ALL = "REPEAT_ALL"
Expand Down
Loading

0 comments on commit 74d7f23

Please sign in to comment.