add data sync id from webview
This commit is contained in:
parent
7bb418fc18
commit
90e16d203d
6 changed files with 56 additions and 4 deletions
|
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
|||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.webkit.CookieManager
|
||||
import android.webkit.WebView
|
||||
import android.widget.Toast
|
||||
|
|
@ -14,6 +15,7 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.core.view.forEach
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.PreferenceManager
|
||||
|
|
@ -21,6 +23,8 @@ import com.deniscerri.ytdl.R
|
|||
import com.deniscerri.ytdl.database.models.CookieItem
|
||||
import com.deniscerri.ytdl.database.viewmodel.CookieViewModel
|
||||
import com.deniscerri.ytdl.ui.BaseActivity
|
||||
import com.deniscerri.ytdl.util.Extensions.isYoutubeURL
|
||||
import com.deniscerri.ytdl.util.UiUtil
|
||||
import com.google.accompanist.web.AccompanistWebChromeClient
|
||||
import com.google.accompanist.web.AccompanistWebViewClient
|
||||
import com.google.accompanist.web.WebView
|
||||
|
|
@ -35,7 +39,7 @@ import kotlinx.coroutines.withContext
|
|||
|
||||
class WebViewActivity : BaseActivity() {
|
||||
private lateinit var cookiesViewModel: CookieViewModel
|
||||
private lateinit var webView: WebView
|
||||
private var webView: WebView? = null
|
||||
private lateinit var webViewCompose: ComposeView
|
||||
private lateinit var toolbar: MaterialToolbar
|
||||
private lateinit var generateBtn: MaterialButton
|
||||
|
|
@ -53,6 +57,23 @@ class WebViewActivity : BaseActivity() {
|
|||
lifecycleScope.launch {
|
||||
val appbar = findViewById<AppBarLayout>(R.id.webview_appbarlayout)
|
||||
toolbar = appbar.findViewById(R.id.webviewToolbar)
|
||||
if (!url.isYoutubeURL()) {
|
||||
toolbar.menu.forEach { it.isVisible = false }
|
||||
}else {
|
||||
toolbar.setOnMenuItemClickListener { m : MenuItem ->
|
||||
when(m.itemId) {
|
||||
R.id.get_data_sync_id -> {
|
||||
webView?.evaluateJavascript("ytcfg.get('DATASYNC_ID')") { id ->
|
||||
UiUtil.copyToClipboard(id.replace("\"", ""), this@WebViewActivity)
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
generateBtn = toolbar.findViewById(R.id.generate)
|
||||
webViewCompose = findViewById(R.id.webview_compose)
|
||||
cookieManager = CookieManager.getInstance()
|
||||
|
|
@ -61,6 +82,7 @@ class WebViewActivity : BaseActivity() {
|
|||
|
||||
webViewClient = object : AccompanistWebViewClient() {
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
webView = view
|
||||
super.onPageFinished(view, url)
|
||||
kotlin.runCatching {
|
||||
toolbar.title = view?.title ?: ""
|
||||
|
|
|
|||
|
|
@ -44,6 +44,26 @@ class AdvancedSettingsFragment : BaseSettingsFragment() {
|
|||
false
|
||||
}
|
||||
|
||||
findPreference<Preference>("youtube_other_extractor_args")?.apply {
|
||||
fun setValue() {
|
||||
val pf = prefs.getString("youtube_other_extractor_args", "")!!
|
||||
if (pf.length > 50) {
|
||||
this.summary = pf.take(50) + "..."
|
||||
}else {
|
||||
this.summary = pf
|
||||
}
|
||||
}
|
||||
|
||||
setOnPreferenceChangeListener { preference, newValue ->
|
||||
setValue()
|
||||
true
|
||||
}
|
||||
|
||||
setValue()
|
||||
|
||||
|
||||
}
|
||||
|
||||
val formatImportanceAudio: Preference? = findPreference("format_importance_audio")
|
||||
val formatImportanceVideo: Preference? = findPreference("format_importance_video")
|
||||
|
||||
|
|
|
|||
|
|
@ -1303,7 +1303,7 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
|
|||
|
||||
val dataSyncID = sharedPreferences.getString("youtube_data_sync_id", "")!!
|
||||
if (dataSyncID.isNotBlank()) {
|
||||
extractorArgs.add("player-skip=webpage,configs")
|
||||
extractorArgs.add("player_skip=webpage,configs")
|
||||
extractorArgs.add("data_sync_id=${dataSyncID}")
|
||||
}
|
||||
|
||||
|
|
@ -1322,7 +1322,7 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
|
|||
}
|
||||
|
||||
if (dataSyncID.isBlank()) {
|
||||
extractorArgs.add("player-skip=webpage,configs")
|
||||
extractorArgs.add("player_skip=webpage,configs")
|
||||
extractorArgs.add("visitor_data=${value.visitorData}")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:layout_scrollFlags="scroll"
|
||||
app:menu="@menu/webview_menu"
|
||||
app:navigationContentDescription="@string/back"
|
||||
app:navigationIcon="?attr/homeAsUpIndicator">
|
||||
|
||||
|
|
|
|||
10
app/src/main/res/menu/webview_menu.xml
Normal file
10
app/src/main/res/menu/webview_menu.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/get_data_sync_id"
|
||||
android:title="Get Data Sync ID"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
</menu>
|
||||
|
|
@ -35,7 +35,6 @@
|
|||
android:defaultValue=""
|
||||
android:icon="@drawable/ic_code"
|
||||
android:key="youtube_other_extractor_args"
|
||||
app:useSimpleSummaryProvider="true"
|
||||
android:title="@string/other_youtube_extractor_args" />
|
||||
</PreferenceCategory>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue