added generic formats for audio

This commit is contained in:
deniscerri 2023-03-22 18:15:09 +01:00
parent 0e23d88c74
commit badf4fb0d9
No known key found for this signature in database
GPG key ID: 95C43D517D830350
25 changed files with 108 additions and 74 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View file

@ -182,11 +182,14 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
private fun getFormat(formats: List<Format>, type: Type) : Format {
when(type) {
Type.audio -> {
return try {
cloneFormat(formats.last { it.format_note.contains("audio", ignoreCase = true) })
}catch (e: Exception){
bestAudioFormat
}
return cloneFormat (
try {
formats.last { it.format_note.contains("audio", ignoreCase = true) }
}catch (e: Exception){
bestAudioFormat
}
)
}
Type.video -> {
return cloneFormat(

View file

@ -30,6 +30,7 @@ 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
@ -48,6 +49,7 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
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
@ -66,6 +68,8 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
fragmentView = inflater.inflate(R.layout.fragment_download_audio, container, false)
activity = getActivity()
downloadViewModel = ViewModelProvider(this)[DownloadViewModel::class.java]
resultViewModel = ViewModelProvider(this)[ResultViewModel::class.java]
fileUtil = FileUtil()
uiUtil = UiUtil(fileUtil)
return fragmentView
@ -123,8 +127,9 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace
)
var formats = resultItem.formats.filter { it.format_note.contains("audio", ignoreCase = true) }
var formats = mutableListOf<Format>()
formats.addAll(resultItem.formats.filter { it.format_note.contains("audio", ignoreCase = true) })
val audioFormats = resources.getStringArray(R.array.audio_formats)
val containers = requireContext().resources.getStringArray(R.array.audio_containers)
val containerPreference = sharedPreferences.getString("audio_format", getString(R.string.defaultValue))
@ -132,36 +137,37 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
val containerAutoCompleteTextView =
view.findViewById<AutoCompleteTextView>(R.id.container_textview)
if (formats.isEmpty()) {
audioFormats.forEach { formats.add(Format(it, containerPreference!!,"","", "",0, it)) }
}
val formatCard = view.findViewById<ConstraintLayout>(R.id.format_card_constraintLayout)
if (formats.isEmpty()) {
formatCard.visibility = View.GONE
view.findViewById<TextView>(R.id.audio_quality_title).visibility = View.GONE
} else {
val chosenFormat = downloadItem.format
uiUtil.populateFormatCard(formatCard, chosenFormat)
val listener = object : OnFormatClickListener {
override fun onFormatClick(allFormats: List<Format>, item: Format) {
downloadItem.format = item
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)
val chosenFormat = downloadItem.format
uiUtil.populateFormatCard(formatCard, chosenFormat)
val listener = object : OnFormatClickListener {
override fun onFormatClick(allFormats: List<Format>, item: Format) {
downloadItem.format = item
uiUtil.populateFormatCard(formatCard, item)
if (containers.contains(item.container)){
downloadItem.format.container = item.container
containerAutoCompleteTextView.setText(item.container, false)
}
lifecycleScope.launch {
withContext(Dispatchers.IO){
resultItem.formats.removeAll(formats.toSet())
resultItem.formats.addAll(allFormats)
resultViewModel.update(resultItem)
}
uiUtil.populateFormatCard(formatCard, item)
formats = allFormats
}
formats = allFormats.toMutableList()
}
formatCard.setOnClickListener{_ ->
formats.forEach {
Log.e("aa", it.toString())
}
val bottomSheet = FormatSelectionBottomSheetDialog(downloadItem, formats, listener)
bottomSheet.show(parentFragmentManager, "formatSheet")
}
formatCard.setOnClickListener{_ ->
formats.forEach {
Log.e("aa", it.toString())
}
val bottomSheet = FormatSelectionBottomSheetDialog(downloadItem, formats, listener)
bottomSheet.show(parentFragmentManager, "formatSheet")
}

View file

@ -137,7 +137,6 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
val containerPreference = sharedPreferences.getString("video_format", getString(R.string.defaultValue))
if (formats.isEmpty()) {
videoFormats.forEach { formats.add(Format(it, containerPreference!!,"","", "",0, it)) }
}
@ -152,12 +151,11 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
if (containers.contains(item.container)){
downloadItem.format.container = item.container
containerAutoCompleteTextView.setText(item.container, false)
}else{
containerAutoCompleteTextView.setText(containers[0], false)
}
lifecycleScope.launch {
withContext(Dispatchers.IO){
resultItem.formats = ArrayList(allFormats)
resultItem.formats.removeAll(formats.toSet())
resultItem.formats.addAll(allFormats)
resultViewModel.update(resultItem)
}
}
@ -165,7 +163,7 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
uiUtil.populateFormatCard(formatCard, item)
}
}
formatCard.setOnClickListener{_ ->
formatCard.setOnClickListener{
val bottomSheet = FormatSelectionBottomSheetDialog(downloadItem, formats, listener)
bottomSheet.show(parentFragmentManager, "formatSheet")
}
@ -219,8 +217,8 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
downloadItem.SaveThumb = saveThumbnail.isChecked
}
val sponsorblock = view.findViewById<Chip>(R.id.sponsorblock_filters)
sponsorblock!!.setOnClickListener {
val sponsorBlock = view.findViewById<Chip>(R.id.sponsorblock_filters)
sponsorBlock!!.setOnClickListener {
val builder = MaterialAlertDialogBuilder(requireContext())
builder.setTitle(getString(R.string.select_sponsorblock_filtering))
val values = resources.getStringArray(R.array.sponsorblock_settings_values)

View file

@ -108,15 +108,18 @@ class CancelledDownloadsFragment : Fragment(), GenericDownloadAdapter.OnItemClic
author!!.text = item.author
// BUTTON ----------------------------------
val buttonLayout = bottomSheet.findViewById<LinearLayout>(R.id.downloads_download_button_layout)
val btn = buttonLayout!!.findViewById<MaterialButton>(R.id.downloads_download_button_type)
val btn = bottomSheet.findViewById<MaterialButton>(R.id.downloads_download_button_type)
if (item.type == DownloadViewModel.Type.audio) {
btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_music)
} else if (item.type == DownloadViewModel.Type.video) {
btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_video)
}else{
btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_terminal)
when (item.type) {
DownloadViewModel.Type.audio -> {
btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_music)
}
DownloadViewModel.Type.video -> {
btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_video)
}
else -> {
btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_terminal)
}
}
val time = bottomSheet.findViewById<Chip>(R.id.time)

View file

@ -108,15 +108,18 @@ class ErroredDownloadsFragment() : Fragment(), GenericDownloadAdapter.OnItemClic
author!!.text = item.author
// BUTTON ----------------------------------
val buttonLayout = bottomSheet.findViewById<LinearLayout>(R.id.downloads_download_button_layout)
val btn = buttonLayout!!.findViewById<MaterialButton>(R.id.downloads_download_button_type)
val btn = bottomSheet.findViewById<MaterialButton>(R.id.downloads_download_button_type)
if (item.type == DownloadViewModel.Type.audio) {
btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_music)
} else if (item.type == DownloadViewModel.Type.video) {
btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_video)
}else{
btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_terminal)
when (item.type) {
DownloadViewModel.Type.audio -> {
btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_music)
}
DownloadViewModel.Type.video -> {
btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_video)
}
else -> {
btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_terminal)
}
}
val time = bottomSheet.findViewById<Chip>(R.id.time)

View file

@ -408,19 +408,18 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
author!!.text = item.author
// BUTTON ----------------------------------
val buttonLayout = bottomSheet!!.findViewById<LinearLayout>(R.id.downloads_download_button_layout)
val btn = buttonLayout!!.findViewById<MaterialButton>(R.id.downloads_download_button_type)
val btn = bottomSheet!!.findViewById<MaterialButton>(R.id.downloads_download_button_type)
if (item.type == DownloadViewModel.Type.audio) {
if (isPresent) btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_music_downloaded) else btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_music)
if (isPresent) btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_music_downloaded) else btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_music)
} else if (item.type == DownloadViewModel.Type.video) {
if (isPresent) btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_video_downloaded) else btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_video)
if (isPresent) btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_video_downloaded) else btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_video)
}else{
btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_terminal)
btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_terminal)
}
if (isPresent){
btn.setOnClickListener {
btn!!.setOnClickListener {
uiUtil!!.shareFileIntent(requireContext(),item.downloadPath)
}
}

View file

@ -116,15 +116,18 @@ class QueuedDownloadsFragment : Fragment(), GenericDownloadAdapter.OnItemClickLi
author!!.text = item.author
// BUTTON ----------------------------------
val buttonLayout = bottomSheet.findViewById<LinearLayout>(R.id.downloads_download_button_layout)
val btn = buttonLayout!!.findViewById<MaterialButton>(R.id.downloads_download_button_type)
val btn = bottomSheet.findViewById<MaterialButton>(R.id.downloads_download_button_type)
if (item.type == DownloadViewModel.Type.audio) {
btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_music)
} else if (item.type == DownloadViewModel.Type.video) {
btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_video)
}else{
btn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_terminal)
when (item.type) {
DownloadViewModel.Type.audio -> {
btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_music)
}
DownloadViewModel.Type.video -> {
btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_video)
}
else -> {
btn!!.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_terminal)
}
}
val time = bottomSheet.findViewById<Chip>(R.id.time)

View file

@ -129,7 +129,9 @@ class DownloadWorker(
DownloadViewModel.Type.audio -> {
request.addOption("-x")
var audioQualityId : String = downloadItem.format.format_id
if (audioQualityId.isBlank() || audioQualityId == "0" || audioQualityId == context.getString(R.string.best_quality)) audioQualityId = ""
if (audioQualityId.isBlank() || audioQualityId == "0") audioQualityId = ""
else if (audioQualityId == context.getString(R.string.worst_quality)) audioQualityId = "worstaudio"
if (audioQualityId.isNotBlank()){
request.addOption("-f", audioQualityId)
}

View file

@ -11,7 +11,7 @@
android:layout_width="0dp"
app:shapeAppearance="@style/ShapeAppearanceOverlay.Avatar"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="10dp"
android:checkable="true"
android:clickable="true"
android:focusable="true"
@ -86,6 +86,13 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
app:barrierDirection="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="title,action_button"/>
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -97,7 +104,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/action_button">
app:layout_constraintTop_toBottomOf="@+id/barrier">
<LinearLayout
android:layout_width="wrap_content"

View file

@ -73,7 +73,7 @@
<LinearLayout
android:id="@+id/adjust_commands"
android:layout_width="wrap_content"
android:padding="10dp"
android:paddingVertical="10dp"
android:layout_height="wrap_content"
android:orientation="vertical"
>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View file

@ -28,6 +28,11 @@
<item>@string/best_quality</item>
</string-array>
<string-array name="audio_formats">
<item>@string/worst_quality</item>
<item>@string/best_quality</item>
</string-array>
<string-array name="sponsorblock_settings_entries">
<item>@string/sponsorblock_nonmusic</item>
<item>@string/sponsorblock_sponsors</item>