use match filter id for youtube playlist items instead if -I

This commit is contained in:
deniscerri 2025-08-31 09:18:32 +02:00
parent 9f82f43392
commit 2bf0d01648
No known key found for this signature in database
GPG key ID: 95C43D517D830350
5 changed files with 39 additions and 81 deletions

View file

@ -142,7 +142,7 @@ class MoreFragment : Fragment() {
lateinit var dialog: AlertDialog
val terminateDialog = MaterialAlertDialogBuilder(requireContext())
terminateDialog.setTitle(getString(R.string.confirm_terminate))
terminateDialog.setTitle(getString(R.string.kill_app))
val dialogView = layoutInflater.inflate(R.layout.dialog_terminate_app, null)
val checkbox = dialogView.findViewById<CheckBox>(R.id.doNotShowAgain)
terminateDialog.setView(dialogView)

View file

@ -53,11 +53,16 @@ class WebViewActivity : BaseActivity() {
private lateinit var cookies: String
private lateinit var webViewClient: AccompanistWebViewClient
private lateinit var preferences: SharedPreferences
private var incognito: Boolean = false
@SuppressLint("SetJavaScriptEnabled")
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.webview_activity)
url = intent.extras!!.getString("url")!!
incognito = intent.extras!!.getBoolean("incognito", false)
cookiesViewModel = ViewModelProvider(this)[CookieViewModel::class.java]
lifecycleScope.launch {
val appbar = findViewById<AppBarLayout>(R.id.webview_appbarlayout)
@ -69,6 +74,8 @@ class WebViewActivity : BaseActivity() {
toolbar.menu.children.firstOrNull { it.itemId == R.id.get_data_sync_id }?.isVisible = false
}
toolbar.menu.children.firstOrNull { it.itemId == R.id.incognito }?.isChecked = incognito
toolbar.setOnMenuItemClickListener { m : MenuItem ->
when(m.itemId) {
R.id.get_data_sync_id -> {
@ -77,16 +84,8 @@ class WebViewActivity : BaseActivity() {
}
}
R.id.incognito -> {
m.isChecked = !m.isChecked
webView.apply {
if (this == null) {
m.isChecked = false
return@apply
}
configureIncognito(this, m.isChecked)
this.reload()
}
intent.putExtra("incognito", !incognito)
recreate()
}
R.id.desktop -> {
m.isChecked = !m.isChecked
@ -164,35 +163,6 @@ class WebViewActivity : BaseActivity() {
}
private fun configureIncognito(webView: WebView, incognito: Boolean) {
if (!incognito) {
webView.settings.run {
cacheMode = WebSettings.LOAD_DEFAULT
domStorageEnabled = true
setGeolocationEnabled(true)
}
}else {
webView.settings.run {
cacheMode = WebSettings.LOAD_NO_CACHE
domStorageEnabled = false
setGeolocationEnabled(false)
}
}
if (incognito) {
WebStorage.getInstance().deleteAllData()
}
if (incognito) {
webView.apply {
clearHistory()
clearCache(true)
clearFormData()
}
}
}
private fun configureDesktopMode(webView: WebView, desktop: Boolean) {
webView.settings.apply {
if (desktop) {
@ -225,8 +195,22 @@ class WebViewActivity : BaseActivity() {
captureBackPresses = false, factory = { context ->
WebView(context).apply {
settings.run {
if (!incognito) {
cacheMode = WebSettings.LOAD_DEFAULT
domStorageEnabled = true
setGeolocationEnabled(true)
}else {
cacheMode = WebSettings.LOAD_NO_CACHE
domStorageEnabled = false
setGeolocationEnabled(false)
WebStorage.getInstance().deleteAllData()
this@apply.clearHistory()
this@apply.clearCache(true)
this@apply.clearFormData()
}
javaScriptEnabled = true
domStorageEnabled = true
javaScriptCanOpenWindowsAutomatically = true
if (Build.VERSION.SDK_INT >= 26) {
safeBrowsingEnabled = true

View file

@ -63,7 +63,8 @@ class PoTokenWebViewLoginActivity : BaseActivity() {
lifecycleScope.launch {
val appbar = findViewById<AppBarLayout>(R.id.webview_appbarlayout)
toolbar = appbar.findViewById(R.id.webviewToolbar)
//hide incognito
toolbar.menu.findItem(1).isVisible = false
toolbar.setOnMenuItemClickListener { m : MenuItem ->
when(m.itemId) {
R.id.get_data_sync_id -> {
@ -71,13 +72,6 @@ class PoTokenWebViewLoginActivity : BaseActivity() {
UiUtil.copyToClipboard(id.replace("\"", ""), this@PoTokenWebViewLoginActivity)
}
}
R.id.incognito -> {
m.isChecked = !m.isChecked
webView.apply {
configureIncognito(this, m.isChecked)
this.reload()
}
}
R.id.desktop -> {
m.isChecked = !m.isChecked
webView.apply {
@ -173,34 +167,6 @@ class PoTokenWebViewLoginActivity : BaseActivity() {
}
private fun configureIncognito(webView: WebView, incognito: Boolean) {
if (!incognito) {
webView.settings.run {
cacheMode = WebSettings.LOAD_DEFAULT
domStorageEnabled = true
setGeolocationEnabled(true)
}
}else {
webView.settings.run {
cacheMode = WebSettings.LOAD_NO_CACHE
domStorageEnabled = false
setGeolocationEnabled(false)
}
}
if (incognito) {
WebStorage.getInstance().deleteAllData()
}
if (incognito) {
webView.apply {
clearHistory()
clearCache(true)
clearFormData()
}
}
}
private fun configureDesktopMode(webView: WebView, desktop: Boolean) {
webView.settings.apply {
if (desktop) {
@ -232,11 +198,17 @@ class PoTokenWebViewLoginActivity : BaseActivity() {
.padding(paddingValues)
.fillMaxSize(),
captureBackPresses = false, factory = { context ->
WebStorage.getInstance().deleteAllData()
WebView(context).apply {
webView = this
clearHistory()
clearCache(true)
clearFormData()
settings.run {
cacheMode = WebSettings.LOAD_NO_CACHE
domStorageEnabled = false
setGeolocationEnabled(false)
javaScriptEnabled = true
domStorageEnabled = true
javaScriptCanOpenWindowsAutomatically = true
if (Build.VERSION.SDK_INT >= 26) {
safeBrowsingEnabled = true

View file

@ -21,6 +21,7 @@ import com.deniscerri.ytdl.database.models.YoutubeGeneratePoTokenItem
import com.deniscerri.ytdl.database.models.YoutubePlayerClientItem
import com.deniscerri.ytdl.database.viewmodel.DownloadViewModel
import com.deniscerri.ytdl.database.viewmodel.ResultViewModel
import com.deniscerri.ytdl.util.Extensions.getIDFromYoutubeURL
import com.deniscerri.ytdl.util.Extensions.getIntByAny
import com.deniscerri.ytdl.util.Extensions.getStringByAny
import com.deniscerri.ytdl.util.Extensions.isURL
@ -731,9 +732,8 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
}else{
isPlaylistItem = true
YoutubeDLRequest(downloadItem.playlistURL!!).apply {
if(downloadItem.playlistIndex == null){
val matchPortion = downloadItem.url.split("/").last().split("=").last().split("&").first()
request.addOption("--match-filter", "id~='${matchPortion}'")
if(downloadItem.playlistIndex == null || downloadItem.url.isYoutubeURL()){
request.addOption("--match-filter", "id~='${downloadItem.url.getIDFromYoutubeURL()}'")
}else{
request.addOption("-I", "${downloadItem.playlistIndex!!}:${downloadItem.playlistIndex}")
}

View file

@ -8,6 +8,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="5dp"
android:text="@string/confirm_terminate"
android:textStyle="bold" />
@ -16,6 +17,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:minWidth="0dp"
android:text="@string/dont_ask_again"/>
</LinearLayout>