bug fixes
This commit is contained in:
parent
86414b7119
commit
f4ebd90641
4 changed files with 90 additions and 82 deletions
|
|
@ -267,8 +267,7 @@ class DownloadLogFragment : Fragment() {
|
|||
val progressBar = requireView().findViewById<LinearProgressIndicator>(R.id.progress)
|
||||
if (event.logItemID == logID) {
|
||||
progressBar.isVisible = event.progress < 100
|
||||
progressBar.setProgress(event.progress, true)
|
||||
progressBar.isIndeterminate = event.progress == 0
|
||||
progressBar.setProgressCompat(event.progress, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import androidx.preference.PreferenceManager
|
|||
import com.afollestad.materialdialogs.utils.MDUtil.getStringArray
|
||||
import com.deniscerri.ytdl.R
|
||||
import com.deniscerri.ytdl.database.models.Format
|
||||
import java.util.Collections
|
||||
|
||||
class FormatUtil(private var context: 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)
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
fun getAudioFormatImportance() : Set<String> {
|
||||
val itemValues = context.getStringArray(R.array.format_importance_audio_values).toSet()
|
||||
val orderPreferences = sharedPreferences.getString("format_importance_audio", itemValues.joinToString(","))!!.split(",").toMutableSet()
|
||||
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.add("smallsize")
|
||||
orderPreferences.remove("file_size")
|
||||
orderPreferences.add(0,"smallsize")
|
||||
}
|
||||
|
||||
val preferContainerOverCodec = sharedPreferences.getBoolean("prefer_container_over_codec_audio", false)
|
||||
|
|
@ -47,12 +46,12 @@ class FormatUtil(private var context: Context) {
|
|||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
fun getVideoFormatImportance() : Set<String> {
|
||||
val itemValues = context.getStringArray(R.array.format_importance_video_values).toSet()
|
||||
val orderPreferences = sharedPreferences.getString("format_importance_video", itemValues.joinToString(","))!!.split(",").toMutableSet()
|
||||
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.add("smallsize")
|
||||
orderPreferences.remove("file_size")
|
||||
orderPreferences.add(0, "smallsize")
|
||||
}
|
||||
|
||||
return orderPreferences
|
||||
|
|
@ -137,8 +136,8 @@ class FormatUtil(private var context: Context) {
|
|||
videoFormatIDPreference.contains(b.format_id).compareTo(videoFormatIDPreference.contains(a.format_id))
|
||||
}
|
||||
"codec" -> {
|
||||
var first = "$videoCodecPreference".toRegex(RegexOption.IGNORE_CASE).containsMatchIn(b.vcodec.uppercase())
|
||||
var second = "$videoCodecPreference".toRegex(RegexOption.IGNORE_CASE).containsMatchIn(a.vcodec.uppercase())
|
||||
val first = videoCodecPreference.toRegex(RegexOption.IGNORE_CASE).containsMatchIn(b.vcodec.uppercase())
|
||||
val second = videoCodecPreference.toRegex(RegexOption.IGNORE_CASE).containsMatchIn(a.vcodec.uppercase())
|
||||
first.compareTo(second)
|
||||
}
|
||||
"resolution" -> {
|
||||
|
|
|
|||
|
|
@ -824,48 +824,51 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
|
|||
request.addOption("-x")
|
||||
|
||||
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")
|
||||
val formatImportance = formatUtil.getAudioFormatImportance()
|
||||
for(order in formatImportance) {
|
||||
when(order) {
|
||||
"file_size" -> {
|
||||
formatSorting.add("size")
|
||||
}
|
||||
"language" -> {
|
||||
if (preferredLanguage.isNotBlank()) {
|
||||
formatSorting.add("lang:${preferredLanguage}")
|
||||
}
|
||||
}
|
||||
"codec" -> {
|
||||
if (aCodecPref.isNotBlank()){
|
||||
formatSorting.add("acodec:$aCodecPref")
|
||||
}
|
||||
}
|
||||
"container" -> {
|
||||
if(ext.isNotBlank()){
|
||||
if(!ext.matches("(webm)|(Default)|(${context.getString(R.string.defaultValue)})".toRegex()) && supportedContainers.contains(ext)){
|
||||
request.addOption("--audio-format", ext)
|
||||
formatSorting.add("aext:$ext")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
formatImportance = formatUtil.getAudioFormatImportance().toMutableList()
|
||||
}else{
|
||||
formatImportance = mutableListOf("codec", "container", "language")
|
||||
if (sharedPreferences.getBoolean("prefer_smaller_formats", false)) {
|
||||
formatImportance.add(0, "smallsize")
|
||||
}
|
||||
|
||||
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.addAll(0,listOf("+br", "+res", "+fps"))
|
||||
}
|
||||
}else if (preferredLanguage.isNotBlank()) {
|
||||
formatSorting.add("lang:${preferredLanguage}")
|
||||
}
|
||||
|
||||
if (sharedPreferences.getBoolean("prefer_smaller_formats", false) && !formatSorting.contains("+size")) {
|
||||
for(order in formatImportance) {
|
||||
when(order) {
|
||||
"smallsize" -> {
|
||||
formatSorting.add("+size")
|
||||
}
|
||||
"file_size" -> {
|
||||
formatSorting.add("size")
|
||||
}
|
||||
"language" -> {
|
||||
if (preferredLanguage.isNotBlank()) {
|
||||
formatSorting.add("lang:${preferredLanguage}")
|
||||
}
|
||||
}
|
||||
"codec" -> {
|
||||
if (aCodecPref.isNotBlank()){
|
||||
formatSorting.add("acodec:$aCodecPref")
|
||||
}
|
||||
}
|
||||
"container" -> {
|
||||
if(ext.isNotBlank()){
|
||||
if(!ext.matches("(webm)|(Default)|(${context.getString(R.string.defaultValue)})".toRegex()) && supportedContainers.contains(ext)){
|
||||
request.addOption("--audio-format", ext)
|
||||
formatSorting.add("aext:$ext")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (downloadItem.format.format_id == context.resources.getString(R.string.worst_quality) || downloadItem.format.format_id == "wa" || downloadItem.format.format_id == "worst") {
|
||||
formatSorting.remove("size")
|
||||
formatSorting.add(0, "+size")
|
||||
formatSorting.remove("+size")
|
||||
formatSorting.addAll(0,listOf("+br", "+res", "+fps"))
|
||||
}
|
||||
|
||||
if (abrSort.isNotBlank()){
|
||||
|
|
@ -1089,9 +1092,8 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
|
|||
|
||||
|
||||
preferredFormatIDs.forEach { v ->
|
||||
preferredAudioFormatIDs.forEach { a ->
|
||||
val aa = if (a.isNotBlank()) "+$a" else ""
|
||||
f.append("$v$aa/")
|
||||
preferredAudioFormatIDs.filter { it.isNotBlank() }.forEach { a ->
|
||||
f.append("$v+$a/")
|
||||
}
|
||||
//build format with just videoformatid and audio if remove audio is not checked
|
||||
if (!downloadItem.videoPreferences.removeAudio){
|
||||
|
|
@ -1124,46 +1126,53 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
|
|||
|
||||
val preferredLanguage = sharedPreferences.getString("audio_language","")!!
|
||||
|
||||
val formatImportance = formatUtil.getVideoFormatImportance()
|
||||
val formatImportance : MutableList<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) {
|
||||
when(order) {
|
||||
"no_audio" -> {
|
||||
formatSorting.add("+hasaud")
|
||||
}
|
||||
"codec" -> {
|
||||
if (vCodecPref.isNotBlank()) formatSorting.add("vcodec:$vCodecPref")
|
||||
if (aCodecPref.isNotBlank()) formatSorting.add("acodec:$aCodecPref")
|
||||
}
|
||||
"resolution" -> {
|
||||
if (hasGenericResulutionFormat.isNotBlank()) {
|
||||
formatSorting.add("res:${hasGenericResulutionFormat}")
|
||||
}
|
||||
}
|
||||
"container" -> {
|
||||
if (cont.isNotBlank()) formatSorting.add("vext:$cont")
|
||||
if (acont.isNotBlank()) formatSorting.add("aext:$acont")
|
||||
for(order in formatImportance) {
|
||||
when(order) {
|
||||
"smallsize" -> {
|
||||
formatSorting.add("+size")
|
||||
}
|
||||
"filesize" -> {
|
||||
formatSorting.add("size")
|
||||
}
|
||||
"no_audio" -> {
|
||||
formatSorting.add("+hasaud")
|
||||
}
|
||||
"codec" -> {
|
||||
if (vCodecPref.isNotBlank()) formatSorting.add("vcodec:$vCodecPref")
|
||||
if (aCodecPref.isNotBlank()) formatSorting.add("acodec:$aCodecPref")
|
||||
}
|
||||
"resolution" -> {
|
||||
if (hasGenericResulutionFormat.isNotBlank()) {
|
||||
formatSorting.add("res:${hasGenericResulutionFormat}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (downloadItem.format.format_id == context.resources.getString(R.string.worst_quality) || downloadItem.format.format_id == "worst") {
|
||||
formatSorting.addAll(0, listOf("+br","+res","+fps"))
|
||||
}else {
|
||||
if (sharedPreferences.getBoolean("prefer_smaller_formats", false)) {
|
||||
formatSorting.add(0, "+size")
|
||||
"container" -> {
|
||||
if (cont.isNotBlank()) formatSorting.add("vext:$cont")
|
||||
if (acont.isNotBlank()) formatSorting.add("aext:$acont")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sharedPreferences.getBoolean("prefer_smaller_formats", false) && !formatSorting.contains("+br")) {
|
||||
formatSorting.add(0, "+size")
|
||||
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"))
|
||||
}
|
||||
|
||||
if (abrSort.isNotBlank()) {
|
||||
formatSorting.add("abr~${abrSort}")
|
||||
formatSorting.add("abr:${abrSort}")
|
||||
}
|
||||
|
||||
if (preferredLanguage.isNotBlank()) {
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@
|
|||
android:id="@+id/progress"
|
||||
android:layout_width="match_parent"
|
||||
android:visibility="gone"
|
||||
android:indeterminate="true"
|
||||
app:layout_constraintBottom_toTopOf="@id/coordinatorLayout3"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue