From 0b069ca86a40c12a17769205a73ddd984f953b76 Mon Sep 17 00:00:00 2001 From: junkfood <69683722+JunkFood02@users.noreply.github.com> Date: Sun, 24 Dec 2023 00:52:10 +0800 Subject: [PATCH] feat: force ipv4 --- .../page/settings/network/NetworkPreferences.kt | 15 +++++++++++++++ .../java/com/junkfood/seal/util/DownloadUtil.kt | 12 +++++++++++- .../java/com/junkfood/seal/util/PreferenceUtil.kt | 1 + app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/junkfood/seal/ui/page/settings/network/NetworkPreferences.kt b/app/src/main/java/com/junkfood/seal/ui/page/settings/network/NetworkPreferences.kt index 02d99a1e5b..4e43b7c526 100644 --- a/app/src/main/java/com/junkfood/seal/ui/page/settings/network/NetworkPreferences.kt +++ b/app/src/main/java/com/junkfood/seal/ui/page/settings/network/NetworkPreferences.kt @@ -7,6 +7,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Bolt import androidx.compose.material.icons.outlined.Cookie import androidx.compose.material.icons.outlined.OfflineBolt +import androidx.compose.material.icons.outlined.SettingsEthernet import androidx.compose.material.icons.outlined.SignalCellular4Bar import androidx.compose.material.icons.outlined.SignalCellularConnectedNoInternet4Bar import androidx.compose.material.icons.outlined.Speed @@ -37,6 +38,7 @@ import com.junkfood.seal.util.ARIA2C import com.junkfood.seal.util.CELLULAR_DOWNLOAD import com.junkfood.seal.util.COOKIES import com.junkfood.seal.util.CUSTOM_COMMAND +import com.junkfood.seal.util.FORCE_IPV4 import com.junkfood.seal.util.PROXY import com.junkfood.seal.util.PreferenceUtil.getValue import com.junkfood.seal.util.PreferenceUtil.updateBoolean @@ -60,6 +62,7 @@ fun NetworkPreferences( var aria2c by remember { mutableStateOf(getValue(ARIA2C)) } var proxy by PROXY.booleanState var isCookiesEnabled by COOKIES.booleanState + var forceIpv4 by FORCE_IPV4.booleanState Scaffold( modifier = Modifier @@ -170,6 +173,18 @@ fun NetworkPreferences( enabled = !aria2c && !isCustomCommandEnabled, ) { showConcurrentDownloadDialog = true } } + item { + PreferenceSwitch( + title = stringResource(R.string.force_ipv4), + description = stringResource(id = R.string.force_ipv4_desc), + icon = Icons.Outlined.SettingsEthernet, + enabled = !isCustomCommandEnabled, + isChecked = forceIpv4 + ) { + forceIpv4 = !forceIpv4 + FORCE_IPV4.updateBoolean(forceIpv4) + } + } item { PreferenceItem(title = stringResource(R.string.cookies), description = stringResource(R.string.cookies_desc), diff --git a/app/src/main/java/com/junkfood/seal/util/DownloadUtil.kt b/app/src/main/java/com/junkfood/seal/util/DownloadUtil.kt index 73c2ed31aa..9f084e6f0f 100644 --- a/app/src/main/java/com/junkfood/seal/util/DownloadUtil.kt +++ b/app/src/main/java/com/junkfood/seal/util/DownloadUtil.kt @@ -107,6 +107,9 @@ object DownloadUtil { if (proxy) { enableProxy(proxyUrl) } + if (forceIpv4) { + addOption("-4") + } if (cookies) { enableCookies(userAgentString) } @@ -150,6 +153,9 @@ object DownloadUtil { if (proxy) { enableProxy(proxyUrl) } + if (forceIpv4) { + addOption("-4") + } /* if (debug) { addOption("-v") }*/ @@ -213,7 +219,8 @@ object DownloadUtil { val useDownloadArchive: Boolean = DOWNLOAD_ARCHIVE.getBoolean(), val embedMetadata: Boolean = EMBED_METADATA.getBoolean(), val restrictFilenames: Boolean = RESTRICT_FILENAMES.getBoolean(), - val supportAv1HardwareDecoding: Boolean = checkIfAv1HardwareAccelerated() + val supportAv1HardwareDecoding: Boolean = checkIfAv1HardwareAccelerated(), + val forceIpv4: Boolean = FORCE_IPV4.getBoolean(), ) private fun YoutubeDLRequest.enableCookies(userAgentString: String): YoutubeDLRequest = @@ -498,6 +505,9 @@ object DownloadUtil { if (proxy) { enableProxy(proxyUrl) } + if (forceIpv4) { + addOption("-4") + } if (debug) { addOption("-v") } diff --git a/app/src/main/java/com/junkfood/seal/util/PreferenceUtil.kt b/app/src/main/java/com/junkfood/seal/util/PreferenceUtil.kt index 0790e1d19f..88a8136661 100644 --- a/app/src/main/java/com/junkfood/seal/util/PreferenceUtil.kt +++ b/app/src/main/java/com/junkfood/seal/util/PreferenceUtil.kt @@ -97,6 +97,7 @@ const val DOWNLOAD_ARCHIVE = "download_archive" const val EMBED_METADATA = "embed_metadata" const val RESTRICT_FILENAMES = "restrict_filenames" const val AV1_HARDWARE_ACCELERATED = "av1_hardware_accelerated" +const val FORCE_IPV4 = "force_ipv4" const val DEFAULT = 0 const val NOT_SPECIFIED = 0 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f8013d3c11..df7315c28d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -402,6 +402,8 @@ Playlist title Your downloads will be saved as: System settings + Force IPv4 + Make all connections via IPv4 %d item %d items