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)
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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" -> {
|
||||||
|
|
|
||||||
|
|
@ -824,48 +824,51 @@ 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()
|
||||||
for(order in formatImportance) {
|
}else{
|
||||||
when(order) {
|
formatImportance = mutableListOf("codec", "container", "language")
|
||||||
"file_size" -> {
|
if (sharedPreferences.getBoolean("prefer_smaller_formats", false)) {
|
||||||
formatSorting.add("size")
|
formatImportance.add(0, "smallsize")
|
||||||
}
|
|
||||||
"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") {
|
|
||||||
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.remove("size")
|
||||||
formatSorting.add(0, "+size")
|
formatSorting.remove("+size")
|
||||||
|
formatSorting.addAll(0,listOf("+br", "+res", "+fps"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abrSort.isNotBlank()){
|
if (abrSort.isNotBlank()){
|
||||||
|
|
@ -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,46 +1126,53 @@ 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" -> {
|
||||||
"no_audio" -> {
|
formatSorting.add("+size")
|
||||||
formatSorting.add("+hasaud")
|
}
|
||||||
}
|
"filesize" -> {
|
||||||
"codec" -> {
|
formatSorting.add("size")
|
||||||
if (vCodecPref.isNotBlank()) formatSorting.add("vcodec:$vCodecPref")
|
}
|
||||||
if (aCodecPref.isNotBlank()) formatSorting.add("acodec:$aCodecPref")
|
"no_audio" -> {
|
||||||
}
|
formatSorting.add("+hasaud")
|
||||||
"resolution" -> {
|
}
|
||||||
if (hasGenericResulutionFormat.isNotBlank()) {
|
"codec" -> {
|
||||||
formatSorting.add("res:${hasGenericResulutionFormat}")
|
if (vCodecPref.isNotBlank()) formatSorting.add("vcodec:$vCodecPref")
|
||||||
}
|
if (aCodecPref.isNotBlank()) formatSorting.add("acodec:$aCodecPref")
|
||||||
}
|
}
|
||||||
"container" -> {
|
"resolution" -> {
|
||||||
if (cont.isNotBlank()) formatSorting.add("vext:$cont")
|
if (hasGenericResulutionFormat.isNotBlank()) {
|
||||||
if (acont.isNotBlank()) formatSorting.add("aext:$acont")
|
formatSorting.add("res:${hasGenericResulutionFormat}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
"container" -> {
|
||||||
|
if (cont.isNotBlank()) formatSorting.add("vext:$cont")
|
||||||
if (downloadItem.format.format_id == context.resources.getString(R.string.worst_quality) || downloadItem.format.format_id == "worst") {
|
if (acont.isNotBlank()) formatSorting.add("aext:$acont")
|
||||||
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")) {
|
if (downloadItem.format.format_id == context.resources.getString(R.string.worst_quality) || downloadItem.format.format_id == "worst") {
|
||||||
formatSorting.add(0, "+size")
|
formatSorting.remove("+size")
|
||||||
|
formatSorting.remove("size")
|
||||||
|
formatSorting.addAll(0, listOf("+br","+res","+fps"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abrSort.isNotBlank()) {
|
if (abrSort.isNotBlank()) {
|
||||||
formatSorting.add("abr~${abrSort}")
|
formatSorting.add("abr:${abrSort}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preferredLanguage.isNotBlank()) {
|
if (preferredLanguage.isNotBlank()) {
|
||||||
|
|
|
||||||
|
|
@ -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"/>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue