diff --git a/app/src/main/java/com/deniscerri/ytdl/App.kt b/app/src/main/java/com/deniscerri/ytdl/App.kt index 3f7b77d1..221c6ae8 100644 --- a/app/src/main/java/com/deniscerri/ytdl/App.kt +++ b/app/src/main/java/com/deniscerri/ytdl/App.kt @@ -64,6 +64,7 @@ class App : Application() { PreferenceManager.setDefaultValues(this, R.xml.processing_preferences, true) PreferenceManager.setDefaultValues(this, R.xml.folders_preference, true) PreferenceManager.setDefaultValues(this, R.xml.updating_preferences, true) + PreferenceManager.setDefaultValues(this, R.xml.advanced_preferences, true) sp.edit().putInt("spl", SPL).apply() } diff --git a/app/src/main/java/com/deniscerri/ytdl/database/repository/DownloadRepository.kt b/app/src/main/java/com/deniscerri/ytdl/database/repository/DownloadRepository.kt index 0f24b71f..602d2395 100644 --- a/app/src/main/java/com/deniscerri/ytdl/database/repository/DownloadRepository.kt +++ b/app/src/main/java/com/deniscerri/ytdl/database/repository/DownloadRepository.kt @@ -243,7 +243,7 @@ class DownloadRepository(private val downloadDao: DownloadDao) { earliestStart.downloadStartTime.minus(currentTime) } else 0 if (delay <= 60000L) delay = 0L - inputData.putLongArray("priority_item_ids", queuedItems.map { it.id }.toLongArray()) + inputData.putLongArray("priority_item_ids", queuedItems.take(20).map { it.id }.toLongArray()) } val useAlarmForScheduling = sharedPreferences.getBoolean("use_alarm_for_scheduling", false) diff --git a/app/src/main/java/com/deniscerri/ytdl/ui/downloadcard/ResultCardDetailsDialog.kt b/app/src/main/java/com/deniscerri/ytdl/ui/downloadcard/ResultCardDetailsDialog.kt index 2df12f00..d4407bb5 100644 --- a/app/src/main/java/com/deniscerri/ytdl/ui/downloadcard/ResultCardDetailsDialog.kt +++ b/app/src/main/java/com/deniscerri/ytdl/ui/downloadcard/ResultCardDetailsDialog.kt @@ -244,19 +244,7 @@ class ResultCardDetailsDialog : BottomSheetDialogFragment(), GenericDownloadAdap downloadThumb.isVisible = item.thumb.isNotBlank() downloadThumb.setOnClickListener { - runCatching { - downloadManager.enqueue( - DownloadManager.Request(item.thumb.toUri()) - .setAllowedNetworkTypes( - DownloadManager.Request.NETWORK_WIFI or - DownloadManager.Request.NETWORK_MOBILE - ) - .setAllowedOverRoaming(true) - .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) - .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "YTDLnis/" + item.title + ".jpg")) - }.onFailure { - Toast.makeText(requireContext(), getString(R.string.failed_download), Toast.LENGTH_SHORT).show() - } + UiUtil.openLinkIntent(requireContext(), item.thumb) } title.text = item.title diff --git a/app/src/main/java/com/deniscerri/ytdl/ui/more/downloadLogs/DownloadLogFragment.kt b/app/src/main/java/com/deniscerri/ytdl/ui/more/downloadLogs/DownloadLogFragment.kt index 764dec6a..11ffe4a8 100644 --- a/app/src/main/java/com/deniscerri/ytdl/ui/more/downloadLogs/DownloadLogFragment.kt +++ b/app/src/main/java/com/deniscerri/ytdl/ui/more/downloadLogs/DownloadLogFragment.kt @@ -14,6 +14,7 @@ import android.widget.HorizontalScrollView import android.widget.LinearLayout import android.widget.ScrollView import android.widget.TextView +import android.widget.Toast import androidx.core.content.edit import androidx.core.view.children import androidx.core.view.get @@ -103,9 +104,16 @@ class DownloadLogFragment : Fragment() { logViewModel = ViewModelProvider(this)[LogViewModel::class.java] CoroutineScope(Dispatchers.IO).launch { - val logItem = logViewModel.getItemById(id!!) - withContext(Dispatchers.Main){ - topAppBar.title = logItem.title + runCatching { + val logItem = logViewModel.getItemById(id!!) + withContext(Dispatchers.Main){ + topAppBar.title = logItem.title + } + }.onFailure { + withContext(Dispatchers.Main) { + Toast.makeText(requireContext(), "Log is deleted!", Toast.LENGTH_SHORT).show() + mainActivity.onBackPressedDispatcher.onBackPressed() + } } } diff --git a/app/src/main/java/com/deniscerri/ytdl/ui/more/settings/AdvancedSettingsFragment.kt b/app/src/main/java/com/deniscerri/ytdl/ui/more/settings/AdvancedSettingsFragment.kt new file mode 100644 index 00000000..aafd5d01 --- /dev/null +++ b/app/src/main/java/com/deniscerri/ytdl/ui/more/settings/AdvancedSettingsFragment.kt @@ -0,0 +1,28 @@ +package com.deniscerri.ytdl.ui.more.settings + +import android.annotation.SuppressLint +import android.content.DialogInterface +import android.graphics.Typeface +import android.os.Bundle +import android.widget.LinearLayout +import android.widget.TextView +import androidx.preference.EditTextPreference +import androidx.preference.Preference +import androidx.preference.PreferenceManager +import androidx.recyclerview.widget.ItemTouchHelper +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.afollestad.materialdialogs.utils.MDUtil.getStringArray +import com.deniscerri.ytdl.R +import com.deniscerri.ytdl.ui.adapter.SortableTextItemAdapter +import com.deniscerri.ytdl.util.UiUtil +import com.google.android.material.dialog.MaterialAlertDialogBuilder + + +class AdvancedSettingsFragment : BaseSettingsFragment() { + override val title: Int = R.string.advanced + @SuppressLint("RestrictedApi") + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.advanced_preferences, rootKey) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/deniscerri/ytdl/ui/more/settings/MainSettingsFragment.kt b/app/src/main/java/com/deniscerri/ytdl/ui/more/settings/MainSettingsFragment.kt index 4c501a82..447a9728 100644 --- a/app/src/main/java/com/deniscerri/ytdl/ui/more/settings/MainSettingsFragment.kt +++ b/app/src/main/java/com/deniscerri/ytdl/ui/more/settings/MainSettingsFragment.kt @@ -128,6 +128,13 @@ class MainSettingsFragment : PreferenceFragmentCompat() { true } + val advanced = findPreference("advanced") + advanced?.summary = "PO Token$separator ${getString(R.string.other_youtube_extractor_args)}" + advanced?.setOnPreferenceClickListener { + navController.navigate(R.id.action_mainSettingsFragment_to_advancedSettingsFragment) + true + } + //about section ------------------------- updateUtil = UpdateUtil(requireContext()) diff --git a/app/src/main/java/com/deniscerri/ytdl/util/UiUtil.kt b/app/src/main/java/com/deniscerri/ytdl/util/UiUtil.kt index 9bb8389d..9ab80a72 100644 --- a/app/src/main/java/com/deniscerri/ytdl/util/UiUtil.kt +++ b/app/src/main/java/com/deniscerri/ytdl/util/UiUtil.kt @@ -508,6 +508,7 @@ object UiUtil { btn?.setImageResource(typeImageResource) val time = bottomSheet.findViewById(R.id.time) + val thumbnail = bottomSheet.findViewById(R.id.thumbnail) val formatNote = bottomSheet.findViewById(R.id.format_note) val container = bottomSheet.findViewById(R.id.container_chip) val codec = bottomSheet.findViewById(R.id.codec) @@ -533,6 +534,14 @@ object UiUtil { } } + thumbnail?.isVisible = item.thumb.isNotBlank() + thumbnail?.apply { + isVisible = item.thumb.isNotBlank() + setOnClickListener { + openLinkIntent(context, item.thumb) + } + } + if (item.type != DownloadViewModel.Type.command){ if (item.format.format_note == "?" || item.format.format_note == "") formatNote!!.visibility = View.GONE @@ -717,6 +726,7 @@ object UiUtil { } val time = bottomSheet.findViewById(R.id.time) + val thumbnail = bottomSheet.findViewById(R.id.thumbnail) val formatNote = bottomSheet.findViewById(R.id.format_note) val container = bottomSheet.findViewById(R.id.container_chip) val codec = bottomSheet.findViewById(R.id.codec) @@ -730,6 +740,14 @@ object UiUtil { time!!.text = SimpleDateFormat(DateFormat.getBestDateTimePattern(Locale.getDefault(), "ddMMMyyyy - HHmm"), Locale.getDefault()).format(calendar.time) time.isClickable = false + thumbnail?.isVisible = item.thumb.isNotBlank() + thumbnail?.apply { + isVisible = item.thumb.isNotBlank() + setOnClickListener { + openLinkIntent(context, item.thumb) + } + } + if (item.type != DownloadViewModel.Type.command){ if (item.format.format_note == "?" || item.format.format_note == "") formatNote!!.visibility = View.GONE diff --git a/app/src/main/java/com/deniscerri/ytdl/util/extractors/YTDLPUtil.kt b/app/src/main/java/com/deniscerri/ytdl/util/extractors/YTDLPUtil.kt index ff8bbf7e..7777e534 100644 --- a/app/src/main/java/com/deniscerri/ytdl/util/extractors/YTDLPUtil.kt +++ b/app/src/main/java/com/deniscerri/ytdl/util/extractors/YTDLPUtil.kt @@ -106,6 +106,10 @@ class YTDLPUtil(private val context: Context) { } request.addOption("-P", FileUtil.getCachePath(context) + "/tmp") + val extraCommands = sharedPreferences.getString("data_fetching_extra_commands", "")!! + if (extraCommands.isNotBlank()){ + request.addConfig(extraCommands) + } println(parseYTDLRequestString(request)) val youtubeDLResponse = YoutubeDL.getInstance().execute(request) @@ -267,6 +271,11 @@ class YTDLPUtil(private val context: Context) { } request.addOption("-P", FileUtil.getCachePath(context) + "/tmp") + val extraCommands = sharedPreferences.getString("data_fetching_extra_commands", "")!! + if (extraCommands.isNotBlank()){ + request.addConfig(extraCommands) + } + val txt = parseYTDLRequestString(request) println(txt) @@ -360,7 +369,10 @@ class YTDLPUtil(private val context: Context) { } request.addOption("-P", FileUtil.getCachePath(context) + "/tmp") - + val extraCommands = sharedPreferences.getString("data_fetching_extra_commands", "")!! + if (extraCommands.isNotBlank()){ + request.addConfig(extraCommands) + } val res = YoutubeDL.getInstance().execute(request) val results: Array = try { @@ -462,7 +474,10 @@ class YTDLPUtil(private val context: Context) { } request.addOption("-P", FileUtil.getCachePath(context) + "/tmp") - + val extraCommands = sharedPreferences.getString("data_fetching_extra_commands", "")!! + if (extraCommands.isNotBlank()){ + request.addConfig(extraCommands) + } val youtubeDLResponse = YoutubeDL.getInstance().execute(request) val json = JSONObject(youtubeDLResponse.out) @@ -1131,4 +1146,13 @@ class YTDLPUtil(private val context: Context) { return extractorArgs.joinToString(";") } + + private fun YoutubeDLRequest.addConfig(commandString: String) { + this.addOption( + "--config-locations", + File(context.cacheDir.absolutePath + "/${System.currentTimeMillis()}${UUID.randomUUID()}.txt").apply { + writeText(commandString) + }.absolutePath + ) + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/baseline_settings_suggest_24.xml b/app/src/main/res/drawable/baseline_settings_suggest_24.xml new file mode 100644 index 00000000..e7eb4bfa --- /dev/null +++ b/app/src/main/res/drawable/baseline_settings_suggest_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/history_item_details_bottom_sheet.xml b/app/src/main/res/layout/history_item_details_bottom_sheet.xml index f006c269..e497598e 100644 --- a/app/src/main/res/layout/history_item_details_bottom_sheet.xml +++ b/app/src/main/res/layout/history_item_details_bottom_sheet.xml @@ -91,6 +91,20 @@ app:layout_constraintTop_toTopOf="parent" android:focusable="true" /> + + + android:maxLines="10" + android:inputType="textMultiLine" /> diff --git a/app/src/main/res/navigation/settings_nav.xml b/app/src/main/res/navigation/settings_nav.xml index e98ae758..00eaed7e 100644 --- a/app/src/main/res/navigation/settings_nav.xml +++ b/app/src/main/res/navigation/settings_nav.xml @@ -41,5 +41,12 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f1e9e325..70423919 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -433,4 +433,7 @@ item(s) Socket Timeout Time to wait before giving up, in seconds + Advanced + Data Fetching Extra Commands + Thumbnail \ No newline at end of file diff --git a/app/src/main/res/xml/advanced_preferences.xml b/app/src/main/res/xml/advanced_preferences.xml new file mode 100644 index 00000000..e2a4f711 --- /dev/null +++ b/app/src/main/res/xml/advanced_preferences.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/general_preferences.xml b/app/src/main/res/xml/general_preferences.xml index 983d61c3..d25db531 100644 --- a/app/src/main/res/xml/general_preferences.xml +++ b/app/src/main/res/xml/general_preferences.xml @@ -102,27 +102,6 @@ app:useSimpleSummaryProvider="true" app:title="@string/format_source" /> - - - - - - + +