add exception handler for texthighlight, add prefer non drc audio preference
This commit is contained in:
parent
3ce4247da9
commit
8c254c95d6
7 changed files with 104 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ import com.deniscerri.ytdl.database.models.DownloadItem
|
||||||
import com.deniscerri.ytdl.database.models.Format
|
import com.deniscerri.ytdl.database.models.Format
|
||||||
import com.deniscerri.ytdl.database.models.ResultItem
|
import com.deniscerri.ytdl.database.models.ResultItem
|
||||||
import com.deniscerri.ytdl.database.viewmodel.ResultViewModel
|
import com.deniscerri.ytdl.database.viewmodel.ResultViewModel
|
||||||
|
import com.deniscerri.ytdl.util.Extensions.getIDFromYoutubeURL
|
||||||
import com.deniscerri.ytdl.util.Extensions.isYoutubeChannelURL
|
import com.deniscerri.ytdl.util.Extensions.isYoutubeChannelURL
|
||||||
import com.deniscerri.ytdl.util.Extensions.isYoutubeURL
|
import com.deniscerri.ytdl.util.Extensions.isYoutubeURL
|
||||||
import com.deniscerri.ytdl.util.Extensions.isYoutubeWatchVideosURL
|
import com.deniscerri.ytdl.util.Extensions.isYoutubeWatchVideosURL
|
||||||
|
|
@ -173,7 +174,7 @@ class ResultRepository(private val resultDao: ResultDao, private val commandTemp
|
||||||
val res = if (newpipeExtractorResult.isSuccess) {
|
val res = if (newpipeExtractorResult.isSuccess) {
|
||||||
newpipeExtractorResult.getOrNull()!!
|
newpipeExtractorResult.getOrNull()!!
|
||||||
}else{
|
}else{
|
||||||
ytdlpUtil.getFromYTDL(inputQuery, resultsGenerated = {})
|
ytdlpUtil.getFromYTDL("https://youtu.be/${inputQuery.getIDFromYoutubeURL()}", resultsGenerated = {})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resetResults) {
|
if (resetResults) {
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,7 @@ class GenerateYoutubePoTokensFragment : Fragment() {
|
||||||
val switch = requireView().findViewById<MaterialSwitch>(R.id.web_client_switch)
|
val switch = requireView().findViewById<MaterialSwitch>(R.id.web_client_switch)
|
||||||
val gvs = requireView().findViewById<TextView>(R.id.content_gvs)
|
val gvs = requireView().findViewById<TextView>(R.id.content_gvs)
|
||||||
val player = requireView().findViewById<TextView>(R.id.content_player)
|
val player = requireView().findViewById<TextView>(R.id.content_player)
|
||||||
|
val subs = requireView().findViewById<TextView>(R.id.content_subs)
|
||||||
val visitorData = requireView().findViewById<TextView>(R.id.content_visitordata)
|
val visitorData = requireView().findViewById<TextView>(R.id.content_visitordata)
|
||||||
|
|
||||||
val playerClientDiv = requireView().findViewById<View>(R.id.playerclient_div)
|
val playerClientDiv = requireView().findViewById<View>(R.id.playerclient_div)
|
||||||
|
|
@ -99,6 +100,7 @@ class GenerateYoutubePoTokensFragment : Fragment() {
|
||||||
fun setValues(conf: YoutubeGeneratePoTokenItem) {
|
fun setValues(conf: YoutubeGeneratePoTokenItem) {
|
||||||
gvs.text = conf.poTokens.find { it.context == "gvs" }?.token ?: ""
|
gvs.text = conf.poTokens.find { it.context == "gvs" }?.token ?: ""
|
||||||
player.text = conf.poTokens.find { it.context == "player" }?.token ?: ""
|
player.text = conf.poTokens.find { it.context == "player" }?.token ?: ""
|
||||||
|
subs.text = conf.poTokens.find { it.context == "subs" }?.token ?: ""
|
||||||
visitorData.text = conf.visitorData
|
visitorData.text = conf.visitorData
|
||||||
playerClientText.text = conf.clients.joinToString(", ")
|
playerClientText.text = conf.clients.joinToString(", ")
|
||||||
}
|
}
|
||||||
|
|
@ -111,6 +113,7 @@ class GenerateYoutubePoTokensFragment : Fragment() {
|
||||||
|
|
||||||
gvs.setOnClickListener(clicker)
|
gvs.setOnClickListener(clicker)
|
||||||
player.setOnClickListener(clicker)
|
player.setOnClickListener(clicker)
|
||||||
|
subs.setOnClickListener(clicker)
|
||||||
visitorData.setOnClickListener(clicker)
|
visitorData.setOnClickListener(clicker)
|
||||||
|
|
||||||
playerClientDiv.setOnClickListener {
|
playerClientDiv.setOnClickListener {
|
||||||
|
|
@ -263,6 +266,10 @@ class GenerateYoutubePoTokensFragment : Fragment() {
|
||||||
webPoTokenResultLauncher.launch(intent)
|
webPoTokenResultLauncher.launch(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dialog.setNeutralButton(getString(R.string.cancel)) { dialogInterface: DialogInterface, _: Int ->
|
||||||
|
dialogInterface.dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@ import android.graphics.drawable.shapes.OvalShape
|
||||||
import android.media.MediaMetadataRetriever
|
import android.media.MediaMetadataRetriever
|
||||||
import android.media.MediaMetadataRetriever.METADATA_KEY_DURATION
|
import android.media.MediaMetadataRetriever.METADATA_KEY_DURATION
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.text.Editable
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
|
import android.text.TextWatcher
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
|
@ -49,6 +51,8 @@ import com.neoutils.highlight.core.Highlight
|
||||||
import com.neoutils.highlight.core.scheme.TextColorScheme
|
import com.neoutils.highlight.core.scheme.TextColorScheme
|
||||||
import com.neoutils.highlight.core.util.Match
|
import com.neoutils.highlight.core.util.Match
|
||||||
import com.neoutils.highlight.core.util.UiColor
|
import com.neoutils.highlight.core.util.UiColor
|
||||||
|
import com.neoutils.highlight.view.extension.applyTo
|
||||||
|
import com.neoutils.highlight.view.extension.removeAllSpans
|
||||||
import com.neoutils.highlight.view.extension.toSpannedString
|
import com.neoutils.highlight.view.extension.toSpannedString
|
||||||
import com.neoutils.highlight.view.text.HighlightTextWatcher
|
import com.neoutils.highlight.view.text.HighlightTextWatcher
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
|
|
@ -84,12 +88,34 @@ object Extensions {
|
||||||
TextColorScheme(regex = "\\d+(\\.\\d)?%".toRegex(), match = Match.fully(UiColor.Hex("#43a564"))),
|
TextColorScheme(regex = "\\d+(\\.\\d)?%".toRegex(), match = Match.fully(UiColor.Hex("#43a564"))),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
fun View.enableTextHighlight(){
|
fun View.enableTextHighlight(){
|
||||||
if (this is EditText || this is TextView){
|
if (this is EditText || this is TextView){
|
||||||
//init syntax highlighter
|
//init syntax highlighter
|
||||||
val highlight = Highlight(textHighlightSchemes)
|
val highlight = Highlight(textHighlightSchemes)
|
||||||
val highlightWatcher = HighlightTextWatcher(highlight)
|
val highlightWatcher = object : TextWatcher {
|
||||||
|
override fun beforeTextChanged(
|
||||||
|
p0: CharSequence?,
|
||||||
|
p1: Int,
|
||||||
|
p2: Int,
|
||||||
|
p3: Int
|
||||||
|
) = Unit
|
||||||
|
|
||||||
|
override fun onTextChanged(
|
||||||
|
p0: CharSequence?,
|
||||||
|
p1: Int,
|
||||||
|
p2: Int,
|
||||||
|
p3: Int
|
||||||
|
) = Unit
|
||||||
|
|
||||||
|
override fun afterTextChanged(p0: Editable?) {
|
||||||
|
p0?.apply {
|
||||||
|
kotlin.runCatching {
|
||||||
|
removeAllSpans()
|
||||||
|
highlight.applyTo(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this is EditText) {
|
if (this is EditText) {
|
||||||
this.addTextChangedListener(highlightWatcher)
|
this.addTextChangedListener(highlightWatcher)
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,11 @@ class FormatUtil(private var context: Context) {
|
||||||
formatImportance.remove("codec")
|
formatImportance.remove("codec")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val noDRC = sharedPreferences.getBoolean("no_prefer_drc_audio", false)
|
||||||
|
if (noDRC) {
|
||||||
|
formatImportance.add("no_drc")
|
||||||
|
}
|
||||||
|
|
||||||
return formatImportance
|
return formatImportance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -151,6 +156,14 @@ class FormatUtil(private var context: Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"no_drc" -> {
|
||||||
|
if (!a.format_note.contains("drc", false)) {
|
||||||
|
0
|
||||||
|
}else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
if (comparison != 0) return comparison
|
if (comparison != 0) return comparison
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,52 @@
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:checkable="true"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:backgroundTint="@android:color/transparent"
|
||||||
|
app:checkedIcon="@null"
|
||||||
|
app:shapeAppearance="@style/ShapeAppearanceOverlay.Avatar"
|
||||||
|
app:strokeWidth="0dp"
|
||||||
|
app:cardPreventCornerOverlap="true"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="15dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title_subs"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:text="PO Token (Subs)"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/content_subs"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="15dp"
|
||||||
|
android:maxLines="3"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:textSize="12sp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/title_subs" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
<com.google.android.material.card.MaterialCardView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:checkable="true"
|
android:checkable="true"
|
||||||
|
|
|
||||||
|
|
@ -489,4 +489,5 @@
|
||||||
<string name="preferred_format_size">Preferred Format Size</string>
|
<string name="preferred_format_size">Preferred Format Size</string>
|
||||||
<string name="smallest">Smallest</string>
|
<string name="smallest">Smallest</string>
|
||||||
<string name="largest">Largest</string>
|
<string name="largest">Largest</string>
|
||||||
|
<string name="no_prefer_drc_audio">Don\'t prefer DRC Audio</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,13 @@
|
||||||
app:summary="@string/preferred_format_id_summary"
|
app:summary="@string/preferred_format_id_summary"
|
||||||
app:title="@string/preferred_format_id" />
|
app:title="@string/preferred_format_id" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:widgetLayout="@layout/preferece_material_switch"
|
||||||
|
app:defaultValue="false"
|
||||||
|
app:icon="@drawable/baseline_audio_file_24"
|
||||||
|
app:key="no_prefer_drc_audio"
|
||||||
|
app:title="@string/no_prefer_drc_audio" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue