From 4b39cd571fa7cb9621feb4909fdefdc5b5622347 Mon Sep 17 00:00:00 2001 From: Aleksandr Gutnikov Date: Wed, 30 Oct 2024 15:38:25 +0100 Subject: [PATCH 1/3] YouTube cookie set to null by logout. --- app/src/main/java/com/zionhuang/music/App.kt | 4 +++- settings.gradle.kts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/zionhuang/music/App.kt b/app/src/main/java/com/zionhuang/music/App.kt index fe609d1a4..37a9b78f1 100644 --- a/app/src/main/java/com/zionhuang/music/App.kt +++ b/app/src/main/java/com/zionhuang/music/App.kt @@ -10,6 +10,7 @@ import coil.ImageLoaderFactory import coil.disk.DiskCache import com.zionhuang.innertube.YouTube import com.zionhuang.innertube.models.YouTubeLocale +import com.zionhuang.innertube.utils.parseCookieString import com.zionhuang.kugou.KuGou import com.zionhuang.music.constants.ContentCountryKey import com.zionhuang.music.constants.ContentLanguageKey @@ -37,6 +38,7 @@ import kotlinx.coroutines.launch import timber.log.Timber import java.net.Proxy import java.util.Locale +import kotlin.collections.contains @HiltAndroidApp class App : Application(), ImageLoaderFactory { @@ -95,7 +97,7 @@ class App : Application(), ImageLoaderFactory { .map { it[InnerTubeCookieKey] } .distinctUntilChanged() .collect { cookie -> - YouTube.cookie = cookie + YouTube.cookie = if ("SAPISID" in parseCookieString(cookie?: "")) cookie else null } } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 06a0c2243..5d58be3cf 100755 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,6 +10,10 @@ dependencyResolutionManagement { } } +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version("0.4.0") +} + rootProject.name = "InnerTune" include(":app") include(":innertube") From 2804a46d6b2268c754f922b9d82ae63bc811e3d3 Mon Sep 17 00:00:00 2001 From: Aleksandr Gutnikov Date: Fri, 1 Nov 2024 13:12:35 +0100 Subject: [PATCH 2/3] InnenTubeCookie and visitorData set to null by logout. --- .../java/com/zionhuang/music/ui/screens/LoginScreen.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/zionhuang/music/ui/screens/LoginScreen.kt b/app/src/main/java/com/zionhuang/music/ui/screens/LoginScreen.kt index 86b203d1d..c4859a7b2 100644 --- a/app/src/main/java/com/zionhuang/music/ui/screens/LoginScreen.kt +++ b/app/src/main/java/com/zionhuang/music/ui/screens/LoginScreen.kt @@ -21,6 +21,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.viewinterop.AndroidView import androidx.navigation.NavController import com.zionhuang.innertube.YouTube +import com.zionhuang.innertube.utils.parseCookieString import com.zionhuang.music.LocalPlayerAwareWindowInsets import com.zionhuang.music.R import com.zionhuang.music.constants.AccountChannelHandleKey @@ -35,6 +36,7 @@ import com.zionhuang.music.utils.reportException import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +import kotlin.collections.contains @SuppressLint("SetJavaScriptEnabled") @OptIn(ExperimentalMaterial3Api::class, DelicateCoroutinesApi::class) @@ -59,7 +61,8 @@ fun LoginScreen( webViewClient = object : WebViewClient() { override fun doUpdateVisitedHistory(view: WebView, url: String, isReload: Boolean) { if (url.startsWith("https://music.youtube.com")) { - innerTubeCookie = CookieManager.getInstance().getCookie(url) + var youTubeCookieString = CookieManager.getInstance().getCookie(url) + innerTubeCookie = if ("SAPISID" in parseCookieString(youTubeCookieString)) youTubeCookieString else "" GlobalScope.launch { YouTube.accountInfo().onSuccess { accountName = it.name @@ -84,6 +87,11 @@ fun LoginScreen( addJavascriptInterface(object { @JavascriptInterface fun onRetrieveVisitorData(newVisitorData: String?) { + if (innerTubeCookie == "") { + visitorData = "" + return + } + if (newVisitorData != null) { visitorData = newVisitorData } From 8033d61e77bd4dc044715e3d4b9f6e1e396a0c28 Mon Sep 17 00:00:00 2001 From: Aleksandr Gutnikov Date: Tue, 5 Nov 2024 13:28:46 +0100 Subject: [PATCH 3/3] Add removing visitorData and innerTubeCookie by logout. --- app/src/main/java/com/zionhuang/music/App.kt | 4 +--- .../zionhuang/music/ui/screens/LoginScreen.kt | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/zionhuang/music/App.kt b/app/src/main/java/com/zionhuang/music/App.kt index 37a9b78f1..fe609d1a4 100644 --- a/app/src/main/java/com/zionhuang/music/App.kt +++ b/app/src/main/java/com/zionhuang/music/App.kt @@ -10,7 +10,6 @@ import coil.ImageLoaderFactory import coil.disk.DiskCache import com.zionhuang.innertube.YouTube import com.zionhuang.innertube.models.YouTubeLocale -import com.zionhuang.innertube.utils.parseCookieString import com.zionhuang.kugou.KuGou import com.zionhuang.music.constants.ContentCountryKey import com.zionhuang.music.constants.ContentLanguageKey @@ -38,7 +37,6 @@ import kotlinx.coroutines.launch import timber.log.Timber import java.net.Proxy import java.util.Locale -import kotlin.collections.contains @HiltAndroidApp class App : Application(), ImageLoaderFactory { @@ -97,7 +95,7 @@ class App : Application(), ImageLoaderFactory { .map { it[InnerTubeCookieKey] } .distinctUntilChanged() .collect { cookie -> - YouTube.cookie = if ("SAPISID" in parseCookieString(cookie?: "")) cookie else null + YouTube.cookie = cookie } } } diff --git a/app/src/main/java/com/zionhuang/music/ui/screens/LoginScreen.kt b/app/src/main/java/com/zionhuang/music/ui/screens/LoginScreen.kt index c4859a7b2..0d8e15946 100644 --- a/app/src/main/java/com/zionhuang/music/ui/screens/LoginScreen.kt +++ b/app/src/main/java/com/zionhuang/music/ui/screens/LoginScreen.kt @@ -19,6 +19,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.viewinterop.AndroidView +import androidx.datastore.preferences.core.edit import androidx.navigation.NavController import com.zionhuang.innertube.YouTube import com.zionhuang.innertube.utils.parseCookieString @@ -31,6 +32,7 @@ import com.zionhuang.music.constants.InnerTubeCookieKey import com.zionhuang.music.constants.VisitorDataKey import com.zionhuang.music.ui.component.IconButton import com.zionhuang.music.ui.utils.backToMain +import com.zionhuang.music.utils.dataStore import com.zionhuang.music.utils.rememberPreference import com.zionhuang.music.utils.reportException import kotlinx.coroutines.DelicateCoroutinesApi @@ -61,9 +63,15 @@ fun LoginScreen( webViewClient = object : WebViewClient() { override fun doUpdateVisitedHistory(view: WebView, url: String, isReload: Boolean) { if (url.startsWith("https://music.youtube.com")) { - var youTubeCookieString = CookieManager.getInstance().getCookie(url) - innerTubeCookie = if ("SAPISID" in parseCookieString(youTubeCookieString)) youTubeCookieString else "" + val youtubeCookieString = CookieManager.getInstance().getCookie(url) GlobalScope.launch { + if ("SAPISID" in parseCookieString(youtubeCookieString)) { // if logged in + innerTubeCookie = youtubeCookieString + } else { // if logged out + context.dataStore.edit { settings -> + settings.remove(InnerTubeCookieKey) + } + } YouTube.accountInfo().onSuccess { accountName = it.name accountEmail = it.email.orEmpty() @@ -87,8 +95,12 @@ fun LoginScreen( addJavascriptInterface(object { @JavascriptInterface fun onRetrieveVisitorData(newVisitorData: String?) { - if (innerTubeCookie == "") { - visitorData = "" + if (innerTubeCookie == "") { // clear visitorData after logout (this will be regenerated in App.kt) + GlobalScope.launch { + context.dataStore.edit { settings -> + settings.remove(VisitorDataKey) + } + } return }