diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/SplashPresenter.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/SplashPresenter.java index d4cba5c655..4468b505a3 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/SplashPresenter.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/SplashPresenter.java @@ -6,7 +6,6 @@ import com.liskovsoft.sharedutils.helpers.Helpers; import com.liskovsoft.sharedutils.helpers.MessageHelpers; import com.liskovsoft.sharedutils.mylogger.Log; -import com.liskovsoft.sharedutils.prefs.GlobalPreferences; import com.liskovsoft.smartyoutubetv2.common.app.presenters.base.BasePresenter; import com.liskovsoft.smartyoutubetv2.common.app.views.SplashView; import com.liskovsoft.smartyoutubetv2.common.app.views.ViewManager; @@ -128,7 +127,7 @@ private void applyNewIntent(Intent intent) { } else { String searchText = IntentExtractor.extractSearchText(intent); - if (searchText != null || IntentExtractor.isVoiceCommand(intent)) { + if (searchText != null || IntentExtractor.isStartVoiceCommand(intent)) { SearchPresenter searchPresenter = SearchPresenter.instance(getContext()); searchPresenter.startSearch(searchText); } else { diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/utils/IntentExtractor.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/utils/IntentExtractor.java index 34c25eb948..0f949dc929 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/utils/IntentExtractor.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/utils/IntentExtractor.java @@ -1,6 +1,7 @@ package com.liskovsoft.smartyoutubetv2.common.utils; import android.content.Intent; +import android.net.Uri; import com.liskovsoft.sharedutils.helpers.Helpers; import com.liskovsoft.sharedutils.querystringparser.UrlQueryString; import com.liskovsoft.sharedutils.querystringparser.UrlQueryStringFactory; @@ -24,6 +25,10 @@ public static String extractVideoId(Intent intent) { return null; } + if (extractVoiceQuery(intent.getData()) != null) { + return null; + } + // Don't Uri directly or you might get UnsupportedOperationException on some urls. UrlQueryString parser = UrlQueryStringFactory.parse(intent.getData()); String videoId = parser.get(VIDEO_ID_KEY); @@ -49,6 +54,12 @@ public static String extractSearchText(Intent intent) { return null; } + String voiceQuery = extractVoiceQuery(intent.getData()); + + if (voiceQuery != null) { + return voiceQuery; + } + // Don't Uri directly or you might get UnsupportedOperationException on some urls. UrlQueryString parser = UrlQueryStringFactory.parse(intent.getData()); @@ -93,7 +104,14 @@ public static boolean isChannelUrl(Intent intent) { && Helpers.contains(new String[] {SUBSCRIPTIONS_URL, HISTORY_URL, RECOMMENDED_URL}, intent.getData().toString()); } - public static boolean isVoiceCommand(Intent intent) { + public static boolean isStartVoiceCommand(Intent intent) { return intent != null && intent.getData() != null && intent.getData().toString().contains("launch=voice"); } + + /** + * Example: https://www.youtube.com/tv?voice={"youtubeAssistantRequest":{"query":"Russian YouTube","queryIntent":"CgxTZWFyY2hJbnRlbnQSFAoFcXVlcnkSCxoJCgdSdXNzaWFuEiYKCGRvY190eXBlEhoaGAoWWU9VVFVCRV9ET0NfVFlQRV9WSURFTw==","youtubeAssistantParams":{"personalDataParams":{"showPersonalData":false}},"enablePrefetchLogging":true},"updateYoutubeSettings":{"enableSafetyMode":false,"enablePersonalResults":false},"hasEntityBar":false}&command_id=CWGIYL6nN8Gi3AP_5Y6wAQ&launch=voice&vq=Russian%20YouTube + */ + private static String extractVoiceQuery(Uri data) { + return Helpers.runMultiMatcher(data.toString(), ":{\"query\":\"([^\"]*)\""); + } }