added mtime preference & format updating on empty formatted results
This commit is contained in:
parent
1adba854e8
commit
ee4d422bf0
12 changed files with 133 additions and 36 deletions
|
|
@ -320,7 +320,7 @@
|
|||
<PersistentState>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/terminal/baseline_terminal_24.xml" />
|
||||
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/refresh/baseline_refresh_24.xml" />
|
||||
</map>
|
||||
</option>
|
||||
</PersistentState>
|
||||
|
|
@ -330,7 +330,7 @@
|
|||
</option>
|
||||
<option name="values">
|
||||
<map>
|
||||
<entry key="outputName" value="ic_terminal" />
|
||||
<entry key="outputName" value="ic_refresh" />
|
||||
<entry key="sourceFile" value="C:\Users\denis\Desktop\adaptiveproduct_youtube_foreground_color_108 (1).svg" />
|
||||
</map>
|
||||
</option>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@ data class ResultItem(
|
|||
val thumb: String,
|
||||
val website: String,
|
||||
var playlistTitle: String,
|
||||
val formats: ArrayList<Format>,
|
||||
var formats: ArrayList<Format>,
|
||||
var creationTime: Long = System.currentTimeMillis() / 1000,
|
||||
)
|
||||
|
|
@ -146,7 +146,7 @@ class DownloadAudioFragment(private var resultItem: ResultItem) : Fragment() {
|
|||
formats.forEach {
|
||||
Log.e("aa", it.toString())
|
||||
}
|
||||
val bottomSheet = FormatSelectionBottomSheetDialog(formats, listener)
|
||||
val bottomSheet = FormatSelectionBottomSheetDialog(downloadItem, formats, listener)
|
||||
bottomSheet.show(parentFragmentManager, "formatSheet")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,31 +5,31 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.*
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.AutoCompleteTextView
|
||||
import android.widget.TextView
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.deniscerri.ytdlnis.MainActivity
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.database.models.DownloadItem
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel.Type
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.ResultViewModel
|
||||
import com.deniscerri.ytdlnis.databinding.FragmentHomeBinding
|
||||
import com.deniscerri.ytdlnis.util.FileUtil
|
||||
import com.deniscerri.ytdlnis.util.UiUtil
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel.Type
|
||||
import com.deniscerri.ytdlnis.util.UiUtil
|
||||
|
||||
|
||||
class DownloadVideoFragment(private val resultItem: ResultItem) : Fragment() {
|
||||
|
|
@ -37,6 +37,7 @@ class DownloadVideoFragment(private val resultItem: ResultItem) : Fragment() {
|
|||
private var fragmentView: View? = null
|
||||
private var activity: Activity? = null
|
||||
private lateinit var downloadViewModel : DownloadViewModel
|
||||
private lateinit var resultViewModel: ResultViewModel
|
||||
private lateinit var fileUtil : FileUtil
|
||||
private lateinit var uiUtil : UiUtil
|
||||
|
||||
|
|
@ -55,6 +56,7 @@ class DownloadVideoFragment(private val resultItem: ResultItem) : Fragment() {
|
|||
fragmentView = inflater.inflate(R.layout.fragment_download_video, container, false)
|
||||
activity = getActivity()
|
||||
downloadViewModel = ViewModelProvider(this)[DownloadViewModel::class.java]
|
||||
resultViewModel = ViewModelProvider(this)[ResultViewModel::class.java]
|
||||
downloadItem = downloadViewModel.createDownloadItemFromResult(resultItem, Type.video)
|
||||
fileUtil = FileUtil()
|
||||
uiUtil = UiUtil(fileUtil)
|
||||
|
|
@ -107,7 +109,7 @@ class DownloadVideoFragment(private val resultItem: ResultItem) : Fragment() {
|
|||
videoPathResultLauncher.launch(intent)
|
||||
}
|
||||
|
||||
val formats = mutableListOf<Format>()
|
||||
var formats = mutableListOf<Format>()
|
||||
formats.addAll(resultItem.formats.filter { !it.format_note.contains("audio", ignoreCase = true) })
|
||||
if (formats.isEmpty()) {
|
||||
val videoFormats = resources.getStringArray(R.array.video_formats)
|
||||
|
|
@ -140,19 +142,28 @@ class DownloadVideoFragment(private val resultItem: ResultItem) : Fragment() {
|
|||
val listener = object : OnFormatClickListener {
|
||||
override fun onFormatClick(allFormats: List<Format>, item: Format) {
|
||||
downloadItem.format = item
|
||||
Log.e("Aa", item.toString())
|
||||
|
||||
if (containers.contains(item.container)){
|
||||
downloadItem.format.container = item.container
|
||||
containerAutoCompleteTextView.setText(item.container, false)
|
||||
}else{
|
||||
downloadItem.format.container = containers[0]
|
||||
containerAutoCompleteTextView.setText(containers[0], false)
|
||||
}
|
||||
if (resultItem.formats.isEmpty()){
|
||||
resultItem.formats = ArrayList(allFormats)
|
||||
}else{
|
||||
resultItem.formats = ArrayList(resultItem.formats.filter { it.format_note.contains("audio", ignoreCase = true) })
|
||||
resultItem.formats.addAll(allFormats)
|
||||
}
|
||||
resultViewModel.update(resultItem)
|
||||
formats = allFormats.toMutableList()
|
||||
Log.e("Aa", item.toString())
|
||||
uiUtil.populateFormatCard(formatCard, item)
|
||||
}
|
||||
}
|
||||
formatCard.setOnClickListener{_ ->
|
||||
val bottomSheet = FormatSelectionBottomSheetDialog(formats, listener)
|
||||
val bottomSheet = FormatSelectionBottomSheetDialog(downloadItem, formats, listener)
|
||||
bottomSheet.show(parentFragmentManager, "formatSheet")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,7 @@ import android.util.Log
|
|||
import android.view.Display
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.Adapter
|
||||
import android.widget.Button
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.*
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.view.get
|
||||
|
|
@ -28,6 +25,7 @@ import com.deniscerri.ytdlnis.database.models.ResultItem
|
|||
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel.Type
|
||||
import com.deniscerri.ytdlnis.util.FileUtil
|
||||
import com.deniscerri.ytdlnis.util.InfoUtil
|
||||
import com.deniscerri.ytdlnis.util.UiUtil
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
|
|
@ -42,15 +40,17 @@ import com.google.android.material.timepicker.TimeFormat
|
|||
import java.util.*
|
||||
|
||||
|
||||
class FormatSelectionBottomSheetDialog(private val formats: List<Format>, private val listener: OnFormatClickListener) : BottomSheetDialogFragment() {
|
||||
class FormatSelectionBottomSheetDialog(private val item: DownloadItem, private var formats: List<Format>, private val listener: OnFormatClickListener) : BottomSheetDialogFragment() {
|
||||
private lateinit var behavior: BottomSheetBehavior<View>
|
||||
private lateinit var fileUtil: FileUtil
|
||||
private lateinit var infoUtil: InfoUtil
|
||||
private lateinit var uiUtil: UiUtil
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
fileUtil = FileUtil()
|
||||
uiUtil = UiUtil(fileUtil)
|
||||
infoUtil = InfoUtil(requireActivity().applicationContext)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -68,7 +68,31 @@ class FormatSelectionBottomSheetDialog(private val formats: List<Format>, privat
|
|||
}
|
||||
|
||||
val linearLayout = view.findViewById<LinearLayout>(R.id.format_list_linear_layout)
|
||||
addFormatsToView(linearLayout)
|
||||
|
||||
val refreshBtn = view.findViewById<Button>(R.id.format_refresh)
|
||||
if (formats.none { it.filesize == 0L }) refreshBtn.visibility = View.GONE
|
||||
refreshBtn.setOnClickListener {
|
||||
try {
|
||||
refreshBtn.isEnabled = false
|
||||
val res = infoUtil.getFromYTDL(item.url)
|
||||
formats = res[0]!!.formats.filter { it.filesize != 0L }
|
||||
formats = when(item.type){
|
||||
Type.audio -> formats.filter { it.format_note.contains("audio", ignoreCase = true) }
|
||||
else -> formats.filter { !it.format_note.contains("audio", ignoreCase = true) }
|
||||
}
|
||||
addFormatsToView(linearLayout)
|
||||
refreshBtn.visibility = View.GONE
|
||||
}catch (e: Exception){
|
||||
refreshBtn.isEnabled = true
|
||||
e.printStackTrace()
|
||||
Toast.makeText(context, getString(R.string.error_updating_formats), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addFormatsToView(linearLayout: LinearLayout){
|
||||
linearLayout.removeAllViews()
|
||||
for (i in formats.lastIndex downTo 0){
|
||||
val it = formats[i]
|
||||
val formatItem = LayoutInflater.from(context).inflate(R.layout.format_item, null)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
private var aria2: SwitchPreferenceCompat? = null
|
||||
private var sponsorblockFilters: MultiSelectListPreference? = null
|
||||
private var filenameTemplate: EditTextPreference? = null
|
||||
private var mtime: SwitchPreferenceCompat? = null
|
||||
private var embedSubtitles: SwitchPreferenceCompat? = null
|
||||
private var embedThumbnail: SwitchPreferenceCompat? = null
|
||||
private var addChapters: SwitchPreferenceCompat? = null
|
||||
|
|
@ -69,6 +70,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
limitRate = findPreference("limit_rate")
|
||||
aria2 = findPreference("aria2")
|
||||
sponsorblockFilters = findPreference("sponsorblock_filter")
|
||||
mtime = findPreference("mtime")
|
||||
embedSubtitles = findPreference("embed_subtitles")
|
||||
filenameTemplate = findPreference("file_name_template")
|
||||
embedThumbnail = findPreference("embed_thumbnail")
|
||||
|
|
@ -115,6 +117,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
editor.putBoolean("aria2", aria2!!.isChecked)
|
||||
editor.putStringSet("sponsorblock_filters", sponsorblockFilters!!.values)
|
||||
editor.putString("file_name_template", filenameTemplate!!.text)
|
||||
editor.putBoolean("mtime", mtime!!.isChecked)
|
||||
editor.putBoolean("embed_subtitles", embedSubtitles!!.isChecked)
|
||||
editor.putBoolean("embed_thumbnail", embedThumbnail!!.isChecked)
|
||||
editor.putBoolean("add_chapters", addChapters!!.isChecked)
|
||||
|
|
@ -233,6 +236,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
editor.apply()
|
||||
true
|
||||
}
|
||||
mtime!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
val embed = newValue as Boolean
|
||||
editor.putBoolean("mtime", embed)
|
||||
editor.apply()
|
||||
true
|
||||
}
|
||||
embedSubtitles!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
val embed = newValue as Boolean
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.deniscerri.ytdlnis.util
|
||||
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
|
@ -8,6 +9,7 @@ import com.deniscerri.ytdlnis.database.models.Format
|
|||
|
||||
class UiUtil(private val fileUtil: FileUtil) {
|
||||
fun populateFormatCard(formatCard : ConstraintLayout, chosenFormat: Format){
|
||||
Log.e("aa", chosenFormat.toString())
|
||||
formatCard.findViewById<TextView>(R.id.container).text = chosenFormat.container.uppercase()
|
||||
formatCard.findViewById<TextView>(R.id.format_note).text = chosenFormat.format_note.uppercase()
|
||||
formatCard.findViewById<TextView>(R.id.format_id).text = "id: ${chosenFormat.format_id}"
|
||||
|
|
@ -22,6 +24,7 @@ class UiUtil(private val fileUtil: FileUtil) {
|
|||
if (codec == "" || codec == "none"){
|
||||
formatCard.findViewById<TextView>(R.id.codec).visibility = View.GONE
|
||||
}else{
|
||||
formatCard.findViewById<TextView>(R.id.codec).visibility = View.VISIBLE
|
||||
formatCard.findViewById<TextView>(R.id.codec).text = codec
|
||||
}
|
||||
formatCard.findViewById<TextView>(R.id.file_size).text = fileUtil.convertFileSize(chosenFormat.filesize)
|
||||
|
|
|
|||
|
|
@ -94,7 +94,9 @@ class DownloadWorker(
|
|||
request.addOption("--write-thumbnail")
|
||||
request.addOption("--convert-thumbnails", "png")
|
||||
}
|
||||
request.addOption("--no-mtime")
|
||||
if (!sharedPreferences.getBoolean("mtime", false)){
|
||||
request.addOption("--no-mtime")
|
||||
}
|
||||
val sponsorBlockFilters = sharedPreferences.getStringSet("sponsorblock_filters", emptySet())
|
||||
if (sponsorBlockFilters!!.isNotEmpty()) {
|
||||
val filters = java.lang.String.join(",", sponsorBlockFilters)
|
||||
|
|
@ -169,15 +171,16 @@ class DownloadWorker(
|
|||
Log.e(TAG, formatArgument)
|
||||
request.addOption("-f", formatArgument)
|
||||
val format = downloadItem.format.container
|
||||
if(format.isNotEmpty()){
|
||||
if(format.isNotEmpty() || format != "Default"){
|
||||
request.addOption("--merge-output-format", format)
|
||||
}
|
||||
if (format != "webm" && format != "DEFAULT") {
|
||||
val embedThumb = sharedPreferences.getBoolean("embed_thumbnail", false)
|
||||
if (embedThumb) {
|
||||
request.addOption("--embed-thumbnail")
|
||||
if (format != "webm") {
|
||||
val embedThumb = sharedPreferences.getBoolean("embed_thumbnail", false)
|
||||
if (embedThumb) {
|
||||
request.addOption("--embed-thumbnail")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
request.addOption("-o", tempFileDir.absolutePath + "/${downloadItem.customFileNameTemplate}.%(ext)s")
|
||||
}
|
||||
DownloadViewModel.Type.command -> {
|
||||
|
|
|
|||
5
app/src/main/res/drawable/ic_refresh.xml
Normal file
5
app/src/main/res/drawable/ic_refresh.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="?attr/colorAccent" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
|
||||
</vector>
|
||||
|
|
@ -10,26 +10,56 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp"
|
||||
android:paddingBottom="20dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/format"
|
||||
android:textSize="25sp" />
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="20dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/select_format"
|
||||
android:paddingBottom="20dp"
|
||||
android:textSize="12sp" />
|
||||
<TextView
|
||||
android:id="@+id/bottom_sheet_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/format"
|
||||
android:textSize="25sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bottom_sheet_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/select_format"
|
||||
android:textSize="12sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/bottom_sheet_title" />
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/format_refresh"
|
||||
style="@style/Widget.Material3.Button.ElevatedButton.Icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:autoLink="all"
|
||||
android:text="@string/update_formats"
|
||||
app:icon="@drawable/ic_refresh"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:scrollbars="none"
|
||||
android:padding="20dp"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
|||
|
|
@ -174,4 +174,8 @@
|
|||
<string name="select_format">Select Format</string>
|
||||
<string name="please_wait">Please Wait</string>
|
||||
<string name="remove_search_history">Clear Search History</string>
|
||||
<string name="enable_mtime">Enable mtime</string>
|
||||
<string name="enable_mtime_summary">Set the HTTP Last-Modified header as last modified time</string>
|
||||
<string name="update_formats">Update Formats</string>
|
||||
<string name="error_updating_formats">Error updating formats!</string>
|
||||
</resources>
|
||||
|
|
@ -108,6 +108,13 @@
|
|||
app:defaultValue="%(uploader)s - %(title)s"
|
||||
app:title="@string/file_name_template" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
app:icon="@drawable/ic_clock"
|
||||
app:key="mtime"
|
||||
app:summary="@string/enable_mtime_summary"
|
||||
app:title="@string/enable_mtime" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="true"
|
||||
app:icon="@drawable/ic_subtitles"
|
||||
|
|
|
|||
Loading…
Reference in a new issue