Skip to content

Commit

Permalink
feat: force ipv4
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Dec 23, 2023
1 parent f261d1f commit 0b069ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/junkfood/seal/util/DownloadUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ object DownloadUtil {
if (proxy) {
enableProxy(proxyUrl)
}
if (forceIpv4) {
addOption("-4")
}
if (cookies) {
enableCookies(userAgentString)
}
Expand Down Expand Up @@ -150,6 +153,9 @@ object DownloadUtil {
if (proxy) {
enableProxy(proxyUrl)
}
if (forceIpv4) {
addOption("-4")
}
/* if (debug) {
addOption("-v")
}*/
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -498,6 +505,9 @@ object DownloadUtil {
if (proxy) {
enableProxy(proxyUrl)
}
if (forceIpv4) {
addOption("-4")
}
if (debug) {
addOption("-v")
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/junkfood/seal/util/PreferenceUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@
<string name="playlist_title">Playlist title</string>
<string name="subdirectory_hint">Your downloads will be saved as:</string>
<string name="system_settings">System settings</string>
<string name="force_ipv4">Force IPv4</string>
<string name="force_ipv4_desc">Make all connections via IPv4</string>
<plurals name="item_count">
<item quantity="one">%d item</item>
<item quantity="other">%d items</item>
Expand Down

0 comments on commit 0b069ca

Please sign in to comment.