pull/1131/head
deniscerri 4 months ago
parent 81c20b15e2
commit 1e67778533
No known key found for this signature in database
GPG Key ID: 95C43D517D830350

@ -552,7 +552,8 @@ class DownloadViewModel(private val application: Application) : AndroidViewModel
}
fun getFormat(formats: List<Format>, type: DownloadType, url: String? = null) : Format {
//pass for video download for audio format sorter, so that it wont apply certain preferences that should be only for audio downloads
fun getFormat(formats: List<Format>, type: DownloadType, url: String? = null, forVideoDownload: Boolean = false) : Format {
when(type) {
DownloadType.audio -> {
return cloneFormat (
@ -560,7 +561,7 @@ class DownloadViewModel(private val application: Application) : AndroidViewModel
val theFormats = formats.filter { it.vcodec.isBlank() || it.vcodec == "none" }.ifEmpty {
formatUtil.getGenericAudioFormats(resources).sortedByDescending { it.filesize }
}
FormatUtil(application).sortAudioFormats(theFormats).first()
FormatUtil(application).sortAudioFormats(theFormats, forVideoDownload).first()
}catch (e: Exception){
formatUtil.getGenericAudioFormats(resources).first()
}
@ -625,7 +626,7 @@ class DownloadViewModel(private val application: Application) : AndroidViewModel
}
}
if (preferredAudioFormats.isEmpty()){
val audioF = getFormat(formats, DownloadType.audio)
val audioF = getFormat(formats, DownloadType.audio, forVideoDownload = true)
if (!formatUtil.getGenericAudioFormats(resources).contains(audioF)){
preferredAudioFormats.add(audioF.format_id)
}

@ -27,7 +27,7 @@ class FormatUtil(private var context: Context) {
}
@SuppressLint("RestrictedApi")
fun getAudioFormatImportance() : List<String> {
fun getAudioFormatImportance(forVideoDownload: Boolean) : List<String> {
val preferredFormatSize = sharedPreferences.getString("preferred_format_size", "")
if (sharedPreferences.getBoolean("use_format_sorting", false)) {
@ -39,9 +39,11 @@ class FormatUtil(private var context: Context) {
orderPreferences.add(0,"smallsize")
}
val preferContainerOverCodec = sharedPreferences.getBoolean("prefer_container_over_codec_audio", false)
if(preferContainerOverCodec) {
orderPreferences.remove("codec")
if(!forVideoDownload) {
val preferContainerOverCodec = sharedPreferences.getBoolean("prefer_container_over_codec_audio", false)
if(preferContainerOverCodec) {
orderPreferences.remove("codec")
}
}
return orderPreferences
@ -95,8 +97,8 @@ class FormatUtil(private var context: Context) {
@SuppressLint("RestrictedApi")
fun sortAudioFormats(formats: List<Format>) : List<Format> {
val orderPreferences = getAudioFormatImportance()
fun sortAudioFormats(formats: List<Format>, forVideoDownload: Boolean = false) : List<Format> {
val orderPreferences = getAudioFormatImportance(forVideoDownload)
val comparator = Comparator<Format> { a, b ->
if ("prefer_drc" in orderPreferences) {

Loading…
Cancel
Save