Skip to content

Commit

Permalink
Added the ability to choose the audio provider and bumped up yt-dlp
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbyESP committed Feb 23, 2023
1 parent cb4b27a commit 3c2ceb7
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ sealed class Version(
}

val currentVersion: Version = Version.Stable(
versionMajor = 0,
versionMinor = 2,
versionMajor = 1,
versionMinor = 1,
versionPatch = 0,
)

Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/com/bobbyesp/spowlo/ui/components/DialogItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Text
Expand All @@ -16,6 +18,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.unit.dp

Expand Down Expand Up @@ -46,6 +49,34 @@ fun SingleChoiceItem(
}
}

@Composable
fun SingleChoiceItemWithIcon(
modifier: Modifier = Modifier, text: String, selected: Boolean, onClick: () -> Unit, icon: ImageVector
) {
Row(
modifier = modifier
.padding(vertical = 2.dp)
.clip(CircleShape)
.selectable(
selected = selected,
enabled = true,
onClick = onClick,
)
.fillMaxWidth()
// .padding(vertical = 12.dp)
, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Start
) {
RadioButton(
modifier = Modifier.clearAndSetSemantics { }, selected = selected, onClick = onClick
)
Icon(imageVector = icon, null, modifier = Modifier.padding(horizontal = 8.dp).size(32.dp))
Text(
// modifier = Modifier.padding(start = 18.dp),
text = text, style = MaterialTheme.typography.bodyLarge
)
}
}

@Composable
fun MultiChoiceItem(
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.bobbyesp.spowlo.ui.pages.settings.format

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.MusicNote
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.bobbyesp.spowlo.R
import com.bobbyesp.spowlo.ui.components.ConfirmButton
import com.bobbyesp.spowlo.ui.components.SingleChoiceItemWithIcon
import com.bobbyesp.spowlo.utils.AUDIO_PROVIDER
import com.bobbyesp.spowlo.utils.PreferencesUtil

@Composable
fun AudioProviderDialog(
onDismissRequest: () -> Unit
) {
var audioProvider by remember { mutableStateOf(PreferencesUtil.getAudioProvider()) }
AlertDialog(
onDismissRequest = onDismissRequest,
title = { Text(stringResource(id = R.string.audio_provider)) },
icon = { Icon(Icons.Outlined.MusicNote, null) },
text = {
Column() {
Text(
stringResource(id = R.string.audio_provider_desc),
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 12.dp)
.padding(horizontal = 24.dp),
style = MaterialTheme.typography.bodyLarge
)
LazyColumn {
for (i in 0..1) {
item {
SingleChoiceItemWithIcon(
text = PreferencesUtil.getAudioProviderDesc(i),
selected = audioProvider == i,
icon = PreferencesUtil.getAudioProviderIcon(i),
onClick = {
audioProvider = i
}
)
}
}
}
}
},
confirmButton = {
ConfirmButton(
onClick = {
PreferencesUtil.encodeInt(AUDIO_PROVIDER, audioProvider)
onDismissRequest()
}
)
},
dismissButton = { TextButton(onClick = { onDismissRequest() }) {
Text(text = stringResource(id = R.string.dismiss))
} },
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.bobbyesp.spowlo.ui.pages.settings.format
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -88,19 +90,23 @@ fun AudioQualityDialog(onDismissRequest: () -> Unit, onConfirm: () -> Unit = {})
Text(text = stringResource(R.string.confirm))
}
}, text = {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
Column(modifier = Modifier) {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 12.dp),
text = stringResource(R.string.audio_quality_desc),
style = MaterialTheme.typography.bodyLarge
)
for (i in 0..17)
SingleChoiceItem(
text = PreferencesUtil.getAudioQualityDesc(i),
selected = audioQuality == i
) { audioQuality = i }
LazyColumn(content = {
for (i in 0..17)
item {
SingleChoiceItem(
text = PreferencesUtil.getAudioQualityDesc(i),
selected = audioQuality == i
) { audioQuality = i }
}
}, modifier = Modifier.size(400.dp))
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fun SettingsFormatsPage(onBackPressed: () -> Unit) {

var showAudioFormatDialog by remember { mutableStateOf(false) }
var showAudioQualityDialog by remember { mutableStateOf(false) }
var showAudioProviderDialog by remember { mutableStateOf(false) }


Scaffold(
Expand Down Expand Up @@ -102,6 +103,14 @@ fun SettingsFormatsPage(onBackPressed: () -> Unit) {
enabled = !preserveOriginalAudio,
) { showAudioQualityDialog = true }
}
item {
PreferenceItem(
title = stringResource(R.string.audio_provider),
description = stringResource(R.string.audio_provider_desc),
icon = Icons.Outlined.HighQuality,
enabled = !isCustomCommandEnabled,
) { showAudioProviderDialog = true }
}
}
})
if (showAudioFormatDialog) {
Expand All @@ -118,4 +127,10 @@ fun SettingsFormatsPage(onBackPressed: () -> Unit) {
audioQuality = PreferencesUtil.getAudioQualityDesc()
}
}
if (showAudioProviderDialog) {
AudioProviderDialog(
onDismissRequest = { showAudioProviderDialog = false }
)
}

}
2 changes: 2 additions & 0 deletions app/src/main/java/com/bobbyesp/spowlo/utils/DownloaderUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ object DownloaderUtil {
addAudioFormat()
}

addOption("--audio", PreferencesUtil.getAudioProviderDesc())

if (useSpotifyPreferences) {
addOption("--client-id", spotifyClientID)
addOption("--client-secret", spotifyClientSecret)
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/bobbyesp/spowlo/utils/PreferencesUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bobbyesp.spowlo.utils
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.core.os.LocaleListCompat
import com.bobbyesp.spowlo.App
Expand All @@ -11,6 +12,7 @@ import com.bobbyesp.spowlo.App.Companion.isFDroidBuild
import com.bobbyesp.spowlo.R
import com.bobbyesp.spowlo.database.CommandTemplate
import com.bobbyesp.spowlo.database.CookieProfile
import com.bobbyesp.spowlo.ui.pages.settings.about.LocalAsset
import com.bobbyesp.spowlo.ui.theme.DEFAULT_SEED_COLOR
import com.google.android.material.color.DynamicColors
import com.kyant.monet.PaletteStyle
Expand Down Expand Up @@ -57,6 +59,8 @@ const val SPOTIFY_CLIENT_SECRET = "spotify_client_secret"
const val USE_CACHING = "use_caching"
const val DONT_FILTER_RESULTS = "dont_filter_results"

const val AUDIO_PROVIDER = "audio_provider"

const val TEMPLATE_ID = "template_id"
const val MAX_FILE_SIZE = "max_file_size"
const val COOKIES = "cookies"
Expand Down Expand Up @@ -105,6 +109,7 @@ private val IntPreferenceDefaults = mapOf(
WELCOME_DIALOG to 1,
AUDIO_FORMAT to 5,
AUDIO_QUALITY to 17,
AUDIO_PROVIDER to 0,
UPDATE_CHANNEL to STABLE,
)

Expand Down Expand Up @@ -141,6 +146,8 @@ object PreferencesUtil {

fun getAudioFormat(): Int = AUDIO_FORMAT.getInt()

fun getAudioProvider(): Int = AUDIO_PROVIDER.getInt()

fun getAudioQuality(): Int = AUDIO_QUALITY.getInt()

fun getAudioFormatDesc(audioQualityStr: Int = getAudioFormat()): String {
Expand All @@ -155,6 +162,23 @@ object PreferencesUtil {
}
}

fun getAudioProviderDesc(audioProviderInt: Int = getAudioProvider()): String {
return when (audioProviderInt){
0 -> "youtube-music"
1 -> "youtube"
else -> "youtube-music"
}
}

@Composable
fun getAudioProviderIcon(audioProviderInt: Int = getAudioProvider()): ImageVector {
return when (audioProviderInt){
0 -> LocalAsset(id = R.drawable.youtube_music_icons8)
1 -> LocalAsset(id = R.drawable.icons8_youtube)
else -> LocalAsset(id = R.drawable.youtube_music_icons8)
}
}

fun getAudioQualityDesc(audioQualityStr: Int = getAudioQuality()): String {
return when (audioQualityStr) {
0 -> "8k"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/icons8_youtube.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<vector android:autoMirrored="true" android:height="144dp"
android:viewportHeight="48" android:viewportWidth="48"
android:width="144dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF3D00" android:pathData="M43.2,33.9c-0.4,2.1 -2.1,3.7 -4.2,4c-3.3,0.5 -8.8,1.1 -15,1.1c-6.1,0 -11.6,-0.6 -15,-1.1c-2.1,-0.3 -3.8,-1.9 -4.2,-4C4.4,31.6 4,28.2 4,24c0,-4.2 0.4,-7.6 0.8,-9.9c0.4,-2.1 2.1,-3.7 4.2,-4C12.3,9.6 17.8,9 24,9c6.2,0 11.6,0.6 15,1.1c2.1,0.3 3.8,1.9 4.2,4c0.4,2.3 0.9,5.7 0.9,9.9C44,28.2 43.6,31.6 43.2,33.9z"/>
<path android:fillColor="#FFF" android:pathData="M20,31L20,17 32,24z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/youtube_music_icons8.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector android:autoMirrored="true" android:height="144dp"
android:viewportHeight="48" android:viewportWidth="48"
android:width="144dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#f44336" android:pathData="M24,24m-20,0a20,20 0,1 1,40 0a20,20 0,1 1,-40 0"/>
<path android:fillColor="#fff" android:pathData="M21,29l8,-5l-8,-5z"/>
<path android:fillColor="#00000000"
android:pathData="M24,14c5.5,0 10,4.476 10,10s-4.476,10 -10,10s-10,-4.476 -10,-10S18.5,14 24,14"
android:strokeColor="#fff" android:strokeWidth="1"/>
</vector>
7 changes: 4 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@
<string name="la_az" translatable="false">Azərbaycanca</string>
<string name="la_nn" translatable="false">Nynorsk</string>
<string name="la_pa" translatable="false">ਪੰਜਾਬੀ</string>

<string name="update_available">A new update is available!</string>
<string name="dont_filter_results">Don\'t filter results</string>
<string name="dont_filter_results_desc">If your download wasn\'t succesful or the song not found, using this command should work all.</string>


<string name="dont_filter_results_desc">Do not filter searching results in the available platforms.</string>
<string name="audio_provider">Audio provider</string>
<string name="audio_provider_desc">Choose from where you want to download the songs</string>
</resources>
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ androidxHiltNavigationCompose = "1.0.0"

androidxTestExt = "1.1.4"

spotdlAndroidVersion = "4.1.0-preview-SNAPSHOT"
spotdlAndroidVersion = "884fabd1ba"
spotifyApiKotlinVersion = "3.8.8"

crashHandlerVersion = "2.0.2"
Expand Down

0 comments on commit 3c2ceb7

Please sign in to comment.