bug fixes

This commit is contained in:
deniscerri 2025-02-23 11:18:09 +01:00
parent 86414b7119
commit f4ebd90641
No known key found for this signature in database
GPG key ID: 95C43D517D830350
4 changed files with 90 additions and 82 deletions

View file

@ -267,8 +267,7 @@ class DownloadLogFragment : Fragment() {
val progressBar = requireView().findViewById<LinearProgressIndicator>(R.id.progress) val progressBar = requireView().findViewById<LinearProgressIndicator>(R.id.progress)
if (event.logItemID == logID) { if (event.logItemID == logID) {
progressBar.isVisible = event.progress < 100 progressBar.isVisible = event.progress < 100
progressBar.setProgress(event.progress, true) progressBar.setProgressCompat(event.progress, true)
progressBar.isIndeterminate = event.progress == 0
} }
} }

View file

@ -8,7 +8,6 @@ import androidx.preference.PreferenceManager
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.database.models.Format import com.deniscerri.ytdl.database.models.Format
import java.util.Collections
class FormatUtil(private var context: Context) { class FormatUtil(private var context: Context) {
private val sharedPreferences : SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) private val sharedPreferences : SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
@ -30,12 +29,12 @@ class FormatUtil(private var context: Context) {
private val preferSmallerFormats = sharedPreferences.getBoolean("prefer_smaller_formats", false) private val preferSmallerFormats = sharedPreferences.getBoolean("prefer_smaller_formats", false)
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
fun getAudioFormatImportance() : Set<String> { fun getAudioFormatImportance() : List<String> {
val itemValues = context.getStringArray(R.array.format_importance_audio_values).toSet() val itemValues = context.getStringArray(R.array.format_importance_audio_values).toMutableList()
val orderPreferences = sharedPreferences.getString("format_importance_audio", itemValues.joinToString(","))!!.split(",").toMutableSet() val orderPreferences = sharedPreferences.getString("format_importance_audio", itemValues.joinToString(","))!!.split(",").toMutableList()
if (preferSmallerFormats) { if (preferSmallerFormats) {
orderPreferences.add("smallsize")
orderPreferences.remove("file_size") orderPreferences.remove("file_size")
orderPreferences.add(0,"smallsize")
} }
val preferContainerOverCodec = sharedPreferences.getBoolean("prefer_container_over_codec_audio", false) val preferContainerOverCodec = sharedPreferences.getBoolean("prefer_container_over_codec_audio", false)
@ -47,12 +46,12 @@ class FormatUtil(private var context: Context) {
} }
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
fun getVideoFormatImportance() : Set<String> { fun getVideoFormatImportance() : List<String> {
val itemValues = context.getStringArray(R.array.format_importance_video_values).toSet() val itemValues = context.getStringArray(R.array.format_importance_video_values).toList()
val orderPreferences = sharedPreferences.getString("format_importance_video", itemValues.joinToString(","))!!.split(",").toMutableSet() val orderPreferences = sharedPreferences.getString("format_importance_video", itemValues.joinToString(","))!!.split(",").toMutableList()
if (preferSmallerFormats) { if (preferSmallerFormats) {
orderPreferences.add("smallsize")
orderPreferences.remove("file_size") orderPreferences.remove("file_size")
orderPreferences.add(0, "smallsize")
} }
return orderPreferences return orderPreferences
@ -137,8 +136,8 @@ class FormatUtil(private var context: Context) {
videoFormatIDPreference.contains(b.format_id).compareTo(videoFormatIDPreference.contains(a.format_id)) videoFormatIDPreference.contains(b.format_id).compareTo(videoFormatIDPreference.contains(a.format_id))
} }
"codec" -> { "codec" -> {
var first = "$videoCodecPreference".toRegex(RegexOption.IGNORE_CASE).containsMatchIn(b.vcodec.uppercase()) val first = videoCodecPreference.toRegex(RegexOption.IGNORE_CASE).containsMatchIn(b.vcodec.uppercase())
var second = "$videoCodecPreference".toRegex(RegexOption.IGNORE_CASE).containsMatchIn(a.vcodec.uppercase()) val second = videoCodecPreference.toRegex(RegexOption.IGNORE_CASE).containsMatchIn(a.vcodec.uppercase())
first.compareTo(second) first.compareTo(second)
} }
"resolution" -> { "resolution" -> {

View file

@ -824,11 +824,23 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
request.addOption("-x") request.addOption("-x")
val formatSorting = mutableListOf<String>() val formatSorting = mutableListOf<String>()
if (sharedPreferences.getBoolean("use_format_sorting", false)) { val formatImportance: MutableList<String>
val useCustomFormatSorting = sharedPreferences.getBoolean("use_format_sorting", false)
if (useCustomFormatSorting) {
formatSorting.add("hasaud") formatSorting.add("hasaud")
val formatImportance = formatUtil.getAudioFormatImportance() 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) { for(order in formatImportance) {
when(order) { when(order) {
"smallsize" -> {
formatSorting.add("+size")
}
"file_size" -> { "file_size" -> {
formatSorting.add("size") formatSorting.add("size")
} }
@ -854,19 +866,10 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
} }
if (downloadItem.format.format_id == context.resources.getString(R.string.worst_quality) || downloadItem.format.format_id == "wa" || downloadItem.format.format_id == "worst") { if (downloadItem.format.format_id == context.resources.getString(R.string.worst_quality) || downloadItem.format.format_id == "wa" || downloadItem.format.format_id == "worst") {
if(formatSorting.contains("size")) {
formatSorting.remove("size") formatSorting.remove("size")
} formatSorting.remove("+size")
formatSorting.addAll(0,listOf("+br", "+res", "+fps")) formatSorting.addAll(0,listOf("+br", "+res", "+fps"))
} }
}else if (preferredLanguage.isNotBlank()) {
formatSorting.add("lang:${preferredLanguage}")
}
if (sharedPreferences.getBoolean("prefer_smaller_formats", false) && !formatSorting.contains("+size")) {
formatSorting.remove("size")
formatSorting.add(0, "+size")
}
if (abrSort.isNotBlank()){ if (abrSort.isNotBlank()){
formatSorting.add(0, "abr:${abrSort}") formatSorting.add(0, "abr:${abrSort}")
@ -1089,9 +1092,8 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
preferredFormatIDs.forEach { v -> preferredFormatIDs.forEach { v ->
preferredAudioFormatIDs.forEach { a -> preferredAudioFormatIDs.filter { it.isNotBlank() }.forEach { a ->
val aa = if (a.isNotBlank()) "+$a" else "" f.append("$v+$a/")
f.append("$v$aa/")
} }
//build format with just videoformatid and audio if remove audio is not checked //build format with just videoformatid and audio if remove audio is not checked
if (!downloadItem.videoPreferences.removeAudio){ if (!downloadItem.videoPreferences.removeAudio){
@ -1124,12 +1126,26 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
val preferredLanguage = sharedPreferences.getString("audio_language","")!! val preferredLanguage = sharedPreferences.getString("audio_language","")!!
val formatImportance = formatUtil.getVideoFormatImportance() val formatImportance : MutableList<String>
val formatSorting = mutableListOf<String>() 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")
}
}
if (sharedPreferences.getBoolean("use_format_sorting", false)) {
for(order in formatImportance) { for(order in formatImportance) {
when(order) { when(order) {
"smallsize" -> {
formatSorting.add("+size")
}
"filesize" -> {
formatSorting.add("size")
}
"no_audio" -> { "no_audio" -> {
formatSorting.add("+hasaud") formatSorting.add("+hasaud")
} }
@ -1150,20 +1166,13 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
} }
if (downloadItem.format.format_id == context.resources.getString(R.string.worst_quality) || downloadItem.format.format_id == "worst") { if (downloadItem.format.format_id == context.resources.getString(R.string.worst_quality) || downloadItem.format.format_id == "worst") {
formatSorting.remove("+size")
formatSorting.remove("size")
formatSorting.addAll(0, listOf("+br","+res","+fps")) formatSorting.addAll(0, listOf("+br","+res","+fps"))
}else {
if (sharedPreferences.getBoolean("prefer_smaller_formats", false)) {
formatSorting.add(0, "+size")
}
}
}
if (sharedPreferences.getBoolean("prefer_smaller_formats", false) && !formatSorting.contains("+br")) {
formatSorting.add(0, "+size")
} }
if (abrSort.isNotBlank()) { if (abrSort.isNotBlank()) {
formatSorting.add("abr~${abrSort}") formatSorting.add("abr:${abrSort}")
} }
if (preferredLanguage.isNotBlank()) { if (preferredLanguage.isNotBlank()) {

View file

@ -86,6 +86,7 @@
android:id="@+id/progress" android:id="@+id/progress"
android:layout_width="match_parent" android:layout_width="match_parent"
android:visibility="gone" android:visibility="gone"
android:indeterminate="true"
app:layout_constraintBottom_toTopOf="@id/coordinatorLayout3" app:layout_constraintBottom_toTopOf="@id/coordinatorLayout3"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>