From b8f18a5be94b05f00ee65f6be36dd8cba66f3073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Font=C3=A1n?= Date: Sat, 4 Mar 2023 17:52:27 +0100 Subject: [PATCH] Added null credentials checker and updated spotdl-android --- app/build.gradle.kts | 4 ++-- app/src/main/java/com/bobbyesp/spowlo/App.kt | 6 +----- .../bobbyesp/spowlo/ui/pages/InitialEntry.kt | 19 +++++++++++++++++++ .../ui/pages/downloader/DownloaderPage.kt | 7 ++----- .../bobbyesp/spowlo/utils/DownloaderUtil.kt | 5 ++++- .../bobbyesp/spowlo/utils/PreferencesUtil.kt | 2 ++ .../com/bobbyesp/spowlo/utils/UpdateUtil.kt | 16 +++++++++++++++- app/src/main/res/values/strings.xml | 1 + gradle/libs.versions.toml | 2 +- 9 files changed, 47 insertions(+), 15 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0d3082d2..cea5d4e8 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -43,7 +43,7 @@ sealed class Version( val currentVersion: Version = Version.Stable( versionMajor = 1, - versionMinor = 1, + versionMinor = 2, versionPatch = 0, ) @@ -71,7 +71,7 @@ android { applicationId = "com.bobbyesp.spowlo" minSdk = 26 targetSdk = 33 - versionCode = 10000 + versionCode = 10200 versionName = currentVersion.toVersionName().run { if (!splitApks) "$this-(F-Droid)" diff --git a/app/src/main/java/com/bobbyesp/spowlo/App.kt b/app/src/main/java/com/bobbyesp/spowlo/App.kt index cbedf25c..5ad52d2a 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/App.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/App.kt @@ -14,17 +14,13 @@ import android.os.Looper import androidx.core.content.getSystemService import com.bobbyesp.ffmpeg.FFmpeg import com.bobbyesp.library.SpotDL -import com.bobbyesp.spowlo.database.CommandTemplate import com.bobbyesp.spowlo.utils.AUDIO_DIRECTORY -import com.bobbyesp.spowlo.utils.DatabaseUtil import com.bobbyesp.spowlo.utils.DownloaderUtil import com.bobbyesp.spowlo.utils.FilesUtil import com.bobbyesp.spowlo.utils.FilesUtil.createEmptyFile import com.bobbyesp.spowlo.utils.FilesUtil.getCookiesFile import com.bobbyesp.spowlo.utils.PreferencesUtil import com.bobbyesp.spowlo.utils.PreferencesUtil.getString -import com.bobbyesp.spowlo.utils.TEMPLATE_EXAMPLE -import com.bobbyesp.spowlo.utils.TEMPLATE_ID import com.bobbyesp.spowlo.utils.ToastUtil import com.google.android.material.color.DynamicColors import com.tencent.mmkv.MMKV @@ -56,7 +52,7 @@ class App : Application() { applicationScope.launch((Dispatchers.IO)) { try { SpotDL.getInstance().init(this@App) - FFmpeg.getInstance().init(this@App) + FFmpeg.init(this@App) DownloaderUtil.getCookiesContentFromDatabase().getOrNull()?.let { FilesUtil.writeContentToFile(it, getCookiesFile()) } diff --git a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt index 9db68729..eb119fa1 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt @@ -41,6 +41,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.dialog import androidx.navigation.navArgument import androidx.navigation.navDeepLink +import com.bobbyesp.library.SpotDL import com.bobbyesp.spowlo.App import com.bobbyesp.spowlo.MainActivity import com.bobbyesp.spowlo.R @@ -71,6 +72,10 @@ import com.bobbyesp.spowlo.ui.pages.settings.format.SettingsFormatsPage import com.bobbyesp.spowlo.ui.pages.settings.general.GeneralSettingsPage import com.bobbyesp.spowlo.ui.pages.settings.spotify.SpotifySettingsPage import com.bobbyesp.spowlo.ui.pages.settings.updater.UpdaterPage +import com.bobbyesp.spowlo.utils.PreferencesUtil.getBoolean +import com.bobbyesp.spowlo.utils.PreferencesUtil.getString +import com.bobbyesp.spowlo.utils.SPOTDL +import com.bobbyesp.spowlo.utils.SPOTDL_UPDATE import com.bobbyesp.spowlo.utils.ToastUtil import com.bobbyesp.spowlo.utils.UpdateUtil import com.google.accompanist.navigation.animation.AnimatedNavHost @@ -80,6 +85,7 @@ import com.google.accompanist.navigation.material.rememberBottomSheetNavigator import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext private const val TAG = "InitialEntry" @@ -340,6 +346,19 @@ fun InitialEntry( } //} + LaunchedEffect(Unit) { + if (!SPOTDL_UPDATE.getBoolean()) return@LaunchedEffect + runCatching { + withContext(Dispatchers.IO) { + val res = UpdateUtil.updateSpotDL() + if (res == SpotDL.UpdateStatus.DONE) { + ToastUtil.makeToastSuspend(context.getString(R.string.spotDl_uptodate) + " (${SPOTDL.getString()})") + } + } + }.onFailure { + it.printStackTrace() + } + } LaunchedEffect(Unit) { launch(Dispatchers.IO) { runCatching { diff --git a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderPage.kt b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderPage.kt index aa3dc0fa..fd7bb438 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderPage.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/downloader/DownloaderPage.kt @@ -4,7 +4,6 @@ import android.Manifest import android.os.Build import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedVisibility -import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.animation.core.FastOutSlowInEasing import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween @@ -31,7 +30,6 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material.ContentAlpha import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.Cancel import androidx.compose.material.icons.outlined.ContentPaste import androidx.compose.material.icons.outlined.Error import androidx.compose.material.icons.outlined.FileDownload @@ -39,7 +37,6 @@ import androidx.compose.material.icons.outlined.Settings import androidx.compose.material.icons.outlined.Subscriptions import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.ExtendedFloatingActionButton import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.IconButton @@ -406,7 +403,7 @@ fun FABs( }, modifier = Modifier.padding(vertical = 12.dp) ) - AnimatedVisibility(visible = isDownloading) { + /*AnimatedVisibility(visible = isDownloading) { ExtendedFloatingActionButton( text = { Text(stringResource(R.string.cancel)) }, onClick = cancelCallback, icon = { @@ -416,7 +413,7 @@ fun FABs( ) }, modifier = Modifier.padding(vertical = 12.dp) ) - } + }*/ } } diff --git a/app/src/main/java/com/bobbyesp/spowlo/utils/DownloaderUtil.kt b/app/src/main/java/com/bobbyesp/spowlo/utils/DownloaderUtil.kt index dec0f08f..b8186907 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/utils/DownloaderUtil.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/utils/DownloaderUtil.kt @@ -257,6 +257,9 @@ object DownloaderUtil { addOption("--audio", PreferencesUtil.getAudioProviderDesc()) if (useSpotifyPreferences) { + if (spotifyClientID.isEmpty() || spotifyClientSecret.isEmpty()) return Result.failure( + Throwable("Spotify client ID or secret is empty while you have the custom credentials option enabled! \n Please check your settings.") + ) addOption("--client-id", spotifyClientID) addOption("--client-secret", spotifyClientSecret) } @@ -277,7 +280,7 @@ object DownloaderUtil { return Result.failure(th) } }.onSuccess { response -> - return when{ + return when { response.output.contains("LookupError") -> Result.failure(Throwable("A LookupError occurred. The song wasn't found.")) response.output.contains("YT-DLP") -> Result.failure(Throwable("An error occurred to yt-dlp while downloading the song. Please, report this issue in GitHub.")) else -> onFinishDownloading( diff --git a/app/src/main/java/com/bobbyesp/spowlo/utils/PreferencesUtil.kt b/app/src/main/java/com/bobbyesp/spowlo/utils/PreferencesUtil.kt index bd54eb81..bfbb046e 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/utils/PreferencesUtil.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/utils/PreferencesUtil.kt @@ -61,6 +61,7 @@ const val DONT_FILTER_RESULTS = "dont_filter_results" const val AUDIO_PROVIDER = "audio_provider" +const val SPOTDL_UPDATE = "spotdl_update" const val TEMPLATE_ID = "template_id" const val MAX_FILE_SIZE = "max_file_size" const val COOKIES = "cookies" @@ -99,6 +100,7 @@ private val BooleanPreferenceDefaults = AUTO_UPDATE to true, USE_CACHING to true, DONT_FILTER_RESULTS to false, + SPOTDL_UPDATE to true, ) private val IntPreferenceDefaults = mapOf( diff --git a/app/src/main/java/com/bobbyesp/spowlo/utils/UpdateUtil.kt b/app/src/main/java/com/bobbyesp/spowlo/utils/UpdateUtil.kt index 0c96be92..41dbf50a 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/utils/UpdateUtil.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/utils/UpdateUtil.kt @@ -9,9 +9,10 @@ import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.ModalBottomSheetState import androidx.compose.material.ModalBottomSheetValue import androidx.core.content.FileProvider +import com.bobbyesp.library.SpotDL import com.bobbyesp.spowlo.App +import com.bobbyesp.spowlo.App.Companion.context import com.bobbyesp.spowlo.R -import com.bobbyesp.spowlo.ui.pages.history.DownloadsHistoryViewModel import com.bobbyesp.spowlo.utils.PreferencesUtil.getInt import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow @@ -85,6 +86,19 @@ object UpdateUtil { private val jsonFormat = Json { ignoreUnknownKeys = true } + suspend fun updateSpotDL(): SpotDL.UpdateStatus? = + withContext(Dispatchers.IO) { + SpotDL.getInstance().updateSpotDL( + context, + "https://api.github.com/repos/spotDL/spotify-downloader/releases/latest" + ).apply { + if (this == SpotDL.UpdateStatus.DONE) + SpotDL.getInstance().version(context)?.let { + PreferencesUtil.encodeString(SPOTDL, it) + } + } + } + private suspend fun getLatestRelease(): LatestRelease { return suspendCoroutine { continuation -> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7dc5af96..af753d0f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -255,4 +255,5 @@ Choose from where you want to download the songs Calling the MODs API wasn\'t successful This mods are hosted by me. If you cannot download them, please, report it in the Telegram channel if possible! + SpotDL is up to date \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d816d25c..5dac6440 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,7 +19,7 @@ androidxHiltNavigationCompose = "1.0.0" androidxTestExt = "1.1.5" -spotdlAndroidVersion = "3bac9b161a" +spotdlAndroidVersion = "fc391374c9" spotifyApiKotlinVersion = "3.8.8" crashHandlerVersion = "2.0.2"