Skip to content

Commit

Permalink
feat: restrict filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Nov 21, 2023
1 parent 7f7cd38 commit 726794e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.material.icons.outlined.FolderSpecial
import androidx.compose.material.icons.outlined.LibraryMusic
import androidx.compose.material.icons.outlined.SdCard
import androidx.compose.material.icons.outlined.SnippetFolder
import androidx.compose.material.icons.outlined.Spellcheck
import androidx.compose.material.icons.outlined.TabUnselected
import androidx.compose.material.icons.outlined.VideoLibrary
import androidx.compose.material3.AlertDialog
Expand Down Expand Up @@ -74,6 +75,7 @@ import com.google.accompanist.permissions.PermissionStatus
import com.google.accompanist.permissions.rememberPermissionState
import com.junkfood.seal.App
import com.junkfood.seal.R
import com.junkfood.seal.ui.common.booleanState
import com.junkfood.seal.ui.common.stringState
import com.junkfood.seal.ui.component.BackButton
import com.junkfood.seal.ui.component.ConfirmButton
Expand All @@ -100,7 +102,9 @@ import com.junkfood.seal.util.OUTPUT_TEMPLATE
import com.junkfood.seal.util.PRIVATE_DIRECTORY
import com.junkfood.seal.util.PreferenceUtil
import com.junkfood.seal.util.PreferenceUtil.getString
import com.junkfood.seal.util.PreferenceUtil.updateBoolean
import com.junkfood.seal.util.PreferenceUtil.updateString
import com.junkfood.seal.util.RESTRICT_FILENAMES
import com.junkfood.seal.util.SDCARD_DOWNLOAD
import com.junkfood.seal.util.SDCARD_URI
import com.junkfood.seal.util.SUBDIRECTORY
Expand Down Expand Up @@ -366,6 +370,18 @@ fun DownloadDirectoryPreferences(onBackPressed: () -> Unit) {
onClick = { showOutputTemplateDialog = true }
)
}
item {
var restrictFilenames by RESTRICT_FILENAMES.booleanState
PreferenceSwitch(
title = stringResource(id = R.string.restrict_filenames),
icon = Icons.Outlined.Spellcheck,
description = stringResource(id = R.string.restrict_filenames_desc),
isChecked = restrictFilenames
) {
restrictFilenames = !restrictFilenames
RESTRICT_FILENAMES.updateBoolean(restrictFilenames)
}
}
item {
PreferenceItem(
title = stringResource(R.string.clear_temp_files),
Expand All @@ -390,7 +406,10 @@ fun DownloadDirectoryPreferences(onBackPressed: () -> Unit) {
},
text = {
Text(
stringResource(R.string.clear_temp_files_info, getExternalTempDir().absolutePath),
stringResource(
R.string.clear_temp_files_info,
getExternalTempDir().absolutePath
),
style = MaterialTheme.typography.bodyLarge
)
},
Expand Down
11 changes: 10 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 @@ -105,6 +105,9 @@ object DownloadUtil {
if (cookies) {
enableCookies(userAgentString)
}
if (restrictFilenames) {
addOption("--restrict-filenames")
}
}
}
execute(request, playlistURL).out.run {
Expand All @@ -129,7 +132,9 @@ object DownloadUtil {
): Result<VideoInfo> = YoutubeDLRequest(url).apply {
preferences.run {
addOption("-o", BASENAME)

if (restrictFilenames) {
addOption("--restrict-filenames")
}
if (extractAudio) {
addOption("-x")
}
Expand Down Expand Up @@ -201,6 +206,7 @@ object DownloadUtil {
val outputTemplate: String = OUTPUT_TEMPLATE.getString(),
val useDownloadArchive: Boolean = DOWNLOAD_ARCHIVE.getBoolean(),
val embedMetadata: Boolean = EMBED_METADATA.getBoolean(),
val restrictFilenames: Boolean = RESTRICT_FILENAMES.getBoolean()
)

private fun YoutubeDLRequest.enableCookies(userAgentString: String): YoutubeDLRequest =
Expand Down Expand Up @@ -473,6 +479,9 @@ object DownloadUtil {
if (cookies) {
enableCookies(userAgentString)
}
if (restrictFilenames) {
addOption("--restrict-filenames")
}
if (proxy) {
enableProxy(proxyUrl)
}
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 @@ -94,6 +94,7 @@ const val OUTPUT_TEMPLATE = "output_template"
const val CUSTOM_OUTPUT_TEMPLATE = "custom_output_template"
const val DOWNLOAD_ARCHIVE = "download_archive"
const val EMBED_METADATA = "embed_metadata"
const val RESTRICT_FILENAMES = "restrict_filenames"

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 @@ -396,6 +396,8 @@
<string name="edit_file">Edit file</string>
<string name="save">Save</string>
<string name="use_format_sorting">Use format sorting</string>
<string name="restrict_filenames">Restrict filenames</string>
<string name="restrict_filenames_desc">Limit filenames to specific characters to ensure compatibility</string>
<plurals name="item_count">
<item quantity="one">%d item</item>
<item quantity="other">%d items</item>
Expand Down

0 comments on commit 726794e

Please sign in to comment.