hot fixes

This commit is contained in:
deniscerri 2025-02-23 20:35:49 +01:00
parent 56edc8ae10
commit f6b2070443
No known key found for this signature in database
GPG key ID: 95C43D517D830350
3 changed files with 40 additions and 50 deletions

View file

@ -532,19 +532,12 @@ class DownloadViewModel(private val application: Application) : AndroidViewModel
fun getFormat(formats: List<Format>, type: Type, url: String? = null) : Format {
val sortFormats = sharedPreferences.getBoolean("use_format_sorting", false)
when(type) {
Type.audio -> {
return cloneFormat (
try {
val theFormats = formats.filter { it.vcodec.isBlank() || it.vcodec == "none" }
if (sortFormats) {
FormatUtil(application).sortAudioFormats(theFormats).first()
}else {
theFormats.first()
}
FormatUtil(application).sortAudioFormats(theFormats).first()
}catch (e: Exception){
formatUtil.getGenericAudioFormats(resources).first()
}
@ -558,11 +551,7 @@ class DownloadViewModel(private val application: Application) : AndroidViewModel
formatUtil.getGenericVideoFormats(resources).sortedByDescending { it.filesize }
}
if (sortFormats) {
FormatUtil(application).sortVideoFormats(theFormats).first()
}else {
theFormats.first()
}
FormatUtil(application).sortVideoFormats(theFormats).first()
}catch (e: Exception){
formatUtil.getGenericVideoFormats(resources).first()
}

View file

@ -30,31 +30,49 @@ class FormatUtil(private var context: Context) {
@SuppressLint("RestrictedApi")
fun getAudioFormatImportance() : List<String> {
val itemValues = context.getStringArray(R.array.format_importance_audio_values).toMutableList()
val orderPreferences = sharedPreferences.getString("format_importance_audio", itemValues.joinToString(","))!!.split(",").toMutableList()
if (preferSmallerFormats) {
orderPreferences.remove("file_size")
orderPreferences.add(0,"smallsize")
}
if (sharedPreferences.getBoolean("use_format_sorting", false)) {
val itemValues = context.getStringArray(R.array.format_importance_audio_values).toMutableList()
val orderPreferences = sharedPreferences.getString("format_importance_audio", itemValues.joinToString(","))!!.split(",").toMutableList()
if (preferSmallerFormats) {
orderPreferences.remove("file_size")
orderPreferences.add(0,"smallsize")
}
val preferContainerOverCodec = sharedPreferences.getBoolean("prefer_container_over_codec_audio", false)
if(preferContainerOverCodec) {
orderPreferences.remove("codec")
}
val preferContainerOverCodec = sharedPreferences.getBoolean("prefer_container_over_codec_audio", false)
if(preferContainerOverCodec) {
orderPreferences.remove("codec")
}
return orderPreferences
return orderPreferences
}else {
val formatImportance = mutableListOf("codec", "container", "language")
if (sharedPreferences.getBoolean("prefer_smaller_formats", false)) {
formatImportance.add(0, "smallsize")
}
return formatImportance
}
}
@SuppressLint("RestrictedApi")
fun getVideoFormatImportance() : List<String> {
val itemValues = context.getStringArray(R.array.format_importance_video_values).toList()
val orderPreferences = sharedPreferences.getString("format_importance_video", itemValues.joinToString(","))!!.split(",").toMutableList()
if (preferSmallerFormats) {
orderPreferences.remove("file_size")
orderPreferences.add(0, "smallsize")
}
if (sharedPreferences.getBoolean("use_format_sorting", false)) {
val itemValues = context.getStringArray(R.array.format_importance_video_values).toList()
val orderPreferences = sharedPreferences.getString("format_importance_video", itemValues.joinToString(","))!!.split(",").toMutableList()
if (preferSmallerFormats) {
orderPreferences.remove("file_size")
orderPreferences.add(0, "smallsize")
}
return orderPreferences
return orderPreferences
}else {
val formatImportance = mutableListOf("resolution", "codec", "container")
if (sharedPreferences.getBoolean("prefer_smaller_formats", false)) {
formatImportance.add(0, "smallsize")
}
return formatImportance
}
}

View file

@ -822,16 +822,10 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
val ext = downloadItem.container
val formatSorting = mutableListOf<String>()
val formatImportance: MutableList<String>
val formatImportance = formatUtil.getAudioFormatImportance()
val useCustomFormatSorting = sharedPreferences.getBoolean("use_format_sorting", false)
if (useCustomFormatSorting) {
formatSorting.add("hasaud")
formatImportance = formatUtil.getAudioFormatImportance().toMutableList()
}else{
formatImportance = mutableListOf("codec", "container", "language")
if (sharedPreferences.getBoolean("prefer_smaller_formats", false)) {
formatImportance.add(0, "smallsize")
}
}
for(order in formatImportance) {
@ -1126,19 +1120,8 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
}
val preferredLanguage = sharedPreferences.getString("audio_language","")!!
val formatImportance : MutableList<String>
val formatImportance = formatUtil.getVideoFormatImportance().toMutableList()
val formatSorting = mutableListOf<String>()
val useCustomFormatSorting = sharedPreferences.getBoolean("use_format_sorting", false)
if (useCustomFormatSorting) {
formatImportance = formatUtil.getVideoFormatImportance().toMutableList()
}else {
formatImportance = mutableListOf("resolution", "codec", "container")
if (sharedPreferences.getBoolean("prefer_smaller_formats", false)) {
formatImportance.add(0, "smallsize")
}
}
for(order in formatImportance) {
when(order) {