Skip to content

Commit

Permalink
Added null credentials checker and updated spotdl-android
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbyESP committed Mar 4, 2023
1 parent ea932b8 commit b8f18a5
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sealed class Version(

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

Expand Down Expand Up @@ -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)"
Expand Down
6 changes: 1 addition & 5 deletions app/src/main/java/com/bobbyesp/spowlo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,15 +30,13 @@ 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
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
Expand Down Expand Up @@ -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 = {
Expand All @@ -416,7 +413,7 @@ fun FABs(
)
}, modifier = Modifier.padding(vertical = 12.dp)
)
}
}*/
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/com/bobbyesp/spowlo/utils/UpdateUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,5 @@
<string name="audio_provider_desc">Choose from where you want to download the songs</string>
<string name="api_call_failed">Calling the MODs API wasn\'t successful</string>
<string name="mods_advertisement">This mods are hosted by me. If you cannot download them, please, report it in the Telegram channel if possible!</string>
<string name="spotDl_uptodate">SpotDL is up to date</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.5"

spotdlAndroidVersion = "3bac9b161a"
spotdlAndroidVersion = "fc391374c9"
spotifyApiKotlinVersion = "3.8.8"

crashHandlerVersion = "2.0.2"
Expand Down

0 comments on commit b8f18a5

Please sign in to comment.