This commit is contained in:
deniscerri 2025-08-24 11:13:19 +02:00
parent 04b5dd5f72
commit 7a25a19127
No known key found for this signature in database
GPG key ID: 95C43D517D830350
7 changed files with 67 additions and 20 deletions

View file

@ -198,7 +198,20 @@ class FolderSettingsFragment : BaseSettingsFragment() {
downloadViewModel.getActiveDownloadsCount() downloadViewModel.getActiveDownloadsCount()
} }
if (activeDownloadCount == 0){ if (activeDownloadCount == 0){
File(FileUtil.getCachePath(requireContext())).deleteRecursively() fun clearCacheFolder(folder: File) {
if (folder.exists() && folder.isDirectory) {
folder.listFiles()?.forEach { file ->
if (file.isDirectory) {
clearCacheFolder(file)
file.delete()
} else {
file.delete()
}
}
}
}
clearCacheFolder(File(FileUtil.getCachePath(requireContext())))
Snackbar.make(requireView(), getString(R.string.cache_cleared), Snackbar.LENGTH_SHORT).show() Snackbar.make(requireView(), getString(R.string.cache_cleared), Snackbar.LENGTH_SHORT).show()
cacheSize = File(FileUtil.getCachePath(requireContext())).walkBottomUp().fold(0L) { acc, file -> acc + file.length() } cacheSize = File(FileUtil.getCachePath(requireContext())).walkBottomUp().fold(0L) { acc, file -> acc + file.length() }
clearCache!!.summary = "(${FileUtil.convertFileSize(cacheSize)}) ${resources.getString(R.string.clear_temporary_files_summary)}" clearCache!!.summary = "(${FileUtil.convertFileSize(cacheSize)}) ${resources.getString(R.string.clear_temporary_files_summary)}"

View file

@ -6,6 +6,7 @@ import androidx.navigation.fragment.findNavController
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import androidx.preference.SwitchPreferenceCompat
import com.afollestad.materialdialogs.utils.MDUtil.getStringArray import com.afollestad.materialdialogs.utils.MDUtil.getStringArray
import com.deniscerri.ytdl.R import com.deniscerri.ytdl.R
import com.deniscerri.ytdl.util.UiUtil import com.deniscerri.ytdl.util.UiUtil
@ -100,6 +101,23 @@ class ProcessingSettingsFragment : BaseSettingsFragment() {
} }
} }
val recodeVideoPreference = findPreference<SwitchPreferenceCompat>("recode_video")!!
val compatibleVideoPreference = findPreference<SwitchPreferenceCompat>("compatible_video")!!
recodeVideoPreference.setOnPreferenceClickListener {
if (compatibleVideoPreference.isChecked && recodeVideoPreference.isChecked) {
compatibleVideoPreference.performClick()
}
true
}
compatibleVideoPreference.setOnPreferenceClickListener {
if (compatibleVideoPreference.isChecked && recodeVideoPreference.isChecked) {
recodeVideoPreference.performClick()
}
true
}
findPreference<Preference>("reset_preferences")?.setOnPreferenceClickListener { findPreference<Preference>("reset_preferences")?.setOnPreferenceClickListener {
UiUtil.showGenericConfirmDialog(requireContext(), getString(R.string.reset), getString(R.string.reset_preferences_in_screen)) { UiUtil.showGenericConfirmDialog(requireContext(), getString(R.string.reset), getString(R.string.reset_preferences_in_screen)) {
resetPreferences(editor, R.xml.processing_preferences) resetPreferences(editor, R.xml.processing_preferences)

View file

@ -1457,25 +1457,35 @@ object UiUtil {
val recodeVideo = view.findViewById<Chip>(R.id.recode_video) val recodeVideo = view.findViewById<Chip>(R.id.recode_video)
recodeVideo.setOnClickListener { recodeVideo.setOnClickListener {
val adjustVideoView = context.layoutInflater.inflate(R.layout.video_download_preferences_dialog, null) val adjustVideoView = context.layoutInflater.inflate(R.layout.video_download_preferences_dialog, null)
adjustVideoView.findViewById<MaterialSwitch>(R.id.recodeVideoSwitch).apply {
val recodeVideoSwitch = adjustVideoView.findViewById<MaterialSwitch>(R.id.recodeVideoSwitch)
val compatibilityModeSwitch = adjustVideoView.findViewById<MaterialSwitch>(R.id.compatiblityModeSwitch)
recodeVideoSwitch.apply {
isChecked = items.all { it.videoPreferences.recodeVideo } isChecked = items.all { it.videoPreferences.recodeVideo }
setOnCheckedChangeListener { _, b -> setOnClickListener { _ ->
recodeVideoClicked(b) recodeVideoClicked(isChecked)
compatibilityModeSwitch.isChecked = false
compatibilityModeClicked(false)
} }
} }
adjustVideoView.findViewById<MaterialSwitch>(R.id.compatiblityModeSwitch).apply { compatibilityModeSwitch.apply {
isChecked = items.first().videoPreferences.compatibilityMode isChecked = items.first().videoPreferences.compatibilityMode
setOnCheckedChangeListener { _, b -> setOnClickListener { _ ->
compatibilityModeClicked(b) compatibilityModeClicked(isChecked)
recodeVideoSwitch.isChecked = false
recodeVideoClicked(false)
} }
} }
val adjustVideoDialog = MaterialAlertDialogBuilder(context) val adjustVideoDialog = MaterialAlertDialogBuilder(context)
.setTitle(context.getString(R.string.recode_video)) .setTitle(context.getString(R.string.recode_video))
.setView(adjustVideoView) .setView(adjustVideoView)
.setIcon(R.drawable.ic_video) .setIcon(R.drawable.baseline_video_metadata)
.setNegativeButton(context.resources.getString(R.string.dismiss)) { _: DialogInterface?, _: Int -> } .setNegativeButton(context.resources.getString(R.string.ok)) { _: DialogInterface?, _: Int -> }
adjustVideoDialog.show() adjustVideoDialog.show()
} }

View file

@ -1115,12 +1115,7 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
var cont = "" var cont = ""
val outputContainer = downloadItem.container val outputContainer = downloadItem.container
if( if(outputContainer.isNotEmpty() && outputContainer != "Default" && outputContainer != context.getString(R.string.defaultValue) && supportedContainers.contains(outputContainer)){
outputContainer.isNotEmpty() &&
outputContainer != "Default" &&
outputContainer != context.getString(R.string.defaultValue) &&
supportedContainers.contains(outputContainer)
){
cont = outputContainer cont = outputContainer
val cantRecode = listOf("avi") val cantRecode = listOf("avi")
@ -1150,7 +1145,7 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
//format logic //format logic
var videoF = downloadItem.format.format_id var videoF = downloadItem.format.format_id
var altAudioF = "" var altAudioF = ""
var audioF = downloadItem.videoPreferences.audioFormatIDs.map { f -> var audioF = downloadItem.videoPreferences.audioFormatIDs.joinToString("+") { f ->
val format = downloadItem.allFormats.find { it.format_id == f } val format = downloadItem.allFormats.find { it.format_id == f }
format?.run { format?.run {
if (this.format_id.matches(".*-[0-9]+".toRegex())) { if (this.format_id.matches(".*-[0-9]+".toRegex())) {
@ -1162,7 +1157,7 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
} }
} else this.format_id } else this.format_id
} ?: f } ?: f
}.joinToString("+").ifBlank { "ba" } }.ifBlank { "ba" }
val preferredAudioLanguage = sharedPreferences.getString("audio_language", "")!! val preferredAudioLanguage = sharedPreferences.getString("audio_language", "")!!
if (downloadItem.videoPreferences.removeAudio) audioF = "" if (downloadItem.videoPreferences.removeAudio) audioF = ""
@ -1175,7 +1170,6 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
val f = StringBuilder() val f = StringBuilder()
val preferredCodec = sharedPreferences.getString("video_codec", "") val preferredCodec = sharedPreferences.getString("video_codec", "")
val preferredQuality = sharedPreferences.getString("video_quality", "best")
val vCodecPrefIndex = context.getStringArray(R.array.video_codec_values).indexOf(preferredCodec) val vCodecPrefIndex = context.getStringArray(R.array.video_codec_values).indexOf(preferredCodec)
var vCodecPref = context.getStringArray(R.array.video_codec_values_ytdlp)[vCodecPrefIndex] var vCodecPref = context.getStringArray(R.array.video_codec_values_ytdlp)[vCodecPrefIndex]
@ -1277,6 +1271,10 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
if(!f.endsWith("b/")){ if(!f.endsWith("b/")){
//last fallback //last fallback
if (f.isBlank()) {
f.append("bv/")
}
f.append("b") f.append("b")
} }

View file

@ -116,7 +116,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:checked="false" android:checked="false"
app:chipIconVisible="true" app:chipIconVisible="true"
app:chipIcon="@drawable/ic_video" app:chipIcon="@drawable/baseline_video_metadata"
android:text="@string/recode_video" /> android:text="@string/recode_video" />
<com.google.android.material.chip.Chip <com.google.android.material.chip.Chip

View file

@ -222,7 +222,7 @@
<string name="accents">Accents</string> <string name="accents">Accents</string>
<string name="high_contrast">High contrast</string> <string name="high_contrast">High contrast</string>
<string name="pure_theme_summary">Pure black / white theme</string> <string name="pure_theme_summary">Pure black / white theme</string>
<string name="material_you">Material you</string> <string name="material_you">Material You</string>
<string name="blue">Blue</string> <string name="blue">Blue</string>
<string name="red">Red</string> <string name="red">Red</string>
<string name="green">Green</string> <string name="green">Green</string>

View file

@ -243,6 +243,14 @@
android:summary="@string/recode_video_summary" android:summary="@string/recode_video_summary"
app:title="@string/recode_video" /> app:title="@string/recode_video" />
<SwitchPreferenceCompat
android:widgetLayout="@layout/preferece_material_switch"
app:defaultValue="false"
app:icon="@drawable/baseline_video_metadata"
app:key="compatible_video"
android:summary="@string/video_compatible_summary"
app:title="@string/video_compatible" />
<ListPreference <ListPreference
android:defaultValue="" android:defaultValue=""