diff --git a/app/src/main/java/org/xbmc/kore/Settings.java b/app/src/main/java/org/xbmc/kore/Settings.java index 729b6830f..7d69259aa 100644 --- a/app/src/main/java/org/xbmc/kore/Settings.java +++ b/app/src/main/java/org/xbmc/kore/Settings.java @@ -172,6 +172,9 @@ public static String getRemoteBarItemsPrefKey(int hostId) { public static final String KEY_PREF_ALWAYS_SENDTOKODI_ADDON = "pref_always_sendtokodi_addon"; public static final boolean DEFAULT_PREF_ALWAYS_SENDTOKODI_ADDON = false; + public static final String KEY_PREF_YOUTUBE_ADDON_ID = "pref_youtube_addon_id"; + public static final String DEFAULT_PREF_YOUTUBE_ADDON_ID = "plugin.video.youtube"; + public static final String KEY_PREF_NAV_DRAWER_ITEMS = "pref_nav_drawer_items"; public static String getNavDrawerItemsPrefKey(int hostId) { return Settings.KEY_PREF_NAV_DRAWER_ITEMS + hostId; diff --git a/app/src/main/java/org/xbmc/kore/ShareOpenActivity.java b/app/src/main/java/org/xbmc/kore/ShareOpenActivity.java index a857cd68b..47014b377 100644 --- a/app/src/main/java/org/xbmc/kore/ShareOpenActivity.java +++ b/app/src/main/java/org/xbmc/kore/ShareOpenActivity.java @@ -10,6 +10,7 @@ import android.webkit.MimeTypeMap; import android.widget.Toast; +import androidx.annotation.Nullable; import androidx.core.content.pm.ShortcutManagerCompat; import androidx.preference.PreferenceManager; @@ -247,29 +248,8 @@ private String toPluginUrl(Uri playuri) { .getBoolean(Settings.KEY_PREF_ALWAYS_SENDTOKODI_ADDON, Settings.DEFAULT_PREF_ALWAYS_SENDTOKODI_ADDON); if (!alwaysSendToKodi) { - if (host.endsWith("youtube.com")) { - String videoId = playuri.getQueryParameter("v"); - String playlistId = playuri.getQueryParameter("list"); - Uri.Builder pluginUri = new Uri.Builder() - .scheme("plugin") - .authority("plugin.video.youtube") - .path("play/"); - boolean valid = false; - if (videoId != null) { - valid = true; - pluginUri.appendQueryParameter("video_id", videoId); - } - if (playlistId != null) { - valid = true; - pluginUri.appendQueryParameter("playlist_id", playlistId) - .appendQueryParameter("order", "default"); - } - if (valid) { - return pluginUri.build().toString(); - } - } else if (host.endsWith("youtu.be")) { - return "plugin://plugin.video.youtube/play/?video_id=" - + playuri.getLastPathSegment(); + if (host.endsWith("youtube.com") || host.endsWith("youtu.be")) { + return toYouTubePluginUrl(playuri); } else if (host.endsWith("vimeo.com")) { return PluginUrlUtils.toPluginUrlVimeo(playuri); } else if (host.endsWith("svtplay.se")) { @@ -317,6 +297,99 @@ private String toPluginUrl(Uri playuri) { return null; } + /** + * Converts a YouTube url to a Kodi plugin URL. + * + * @param playuri some URL for YouTube + * @return plugin URL + */ + @Nullable + private String toYouTubePluginUrl(Uri playuri) { + String preferredYouTubeAddonId = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) + .getString(Settings.KEY_PREF_YOUTUBE_ADDON_ID, Settings.DEFAULT_PREF_YOUTUBE_ADDON_ID); + + if (preferredYouTubeAddonId.equals("plugin.video.invidious")) { + return toInvidiousYouTubePluginUrl(playuri); + } else { + return toDefaultYouTubePluginUrl(playuri); + } + } + + /** + * Converts a YouTube url to an URL for the default YouTube add-on (plugin.video.youtube) + * + * @param playuri some URL for YouTube + * @return plugin URL + */ + @Nullable + private String toDefaultYouTubePluginUrl(Uri playuri) { + String host = playuri.getHost(); + + if (host.endsWith("youtube.com")) { + String videoId = playuri.getQueryParameter("v"); + String playlistId = playuri.getQueryParameter("list"); + Uri.Builder pluginUri = new Uri.Builder() + .scheme("plugin") + .authority("plugin.video.youtube") + .path("play/"); + boolean valid = false; + if (videoId != null) { + valid = true; + pluginUri.appendQueryParameter("video_id", videoId); + } + if (playlistId != null) { + valid = true; + pluginUri.appendQueryParameter("playlist_id", playlistId) + .appendQueryParameter("order", "default"); + } + if (valid) { + return pluginUri.build().toString(); + } + } else if (host.endsWith("youtu.be")) { + return "plugin://plugin.video.youtube/play/?video_id=" + + playuri.getLastPathSegment(); + } + + return null; + } + + /** + * Converts a YouTube url to an URL for the Invidious YouTube add-on (plugin.video.invidious) + * + * @param playuri some URL for YouTube + * @return plugin URL + */ + @Nullable + private String toInvidiousYouTubePluginUrl(Uri playuri) { + String host = playuri.getHost(); + + Uri.Builder pluginUri = new Uri.Builder() + .scheme("plugin") + .authority("plugin.video.invidious") + .path("/") + .appendQueryParameter("action", "play_video"); + + String videoIdParameterKey = "video_id"; + + String videoId; + if (host.endsWith("youtube.com")) { + videoId = playuri.getQueryParameter("v"); + } else if (host.endsWith("youtu.be")) { + videoId = playuri.getLastPathSegment(); + } else { + return null; + } + + if (videoId == null) { + return null; + } + + return pluginUri + .appendQueryParameter(videoIdParameterKey, videoId) + .build() + .toString(); + } + boolean isMediaFile(String mimeType) { if (mimeType == null) { return false; diff --git a/app/src/main/java/org/xbmc/kore/ui/sections/settings/SettingsFragment.java b/app/src/main/java/org/xbmc/kore/ui/sections/settings/SettingsFragment.java index 1b14e6a80..b5c61c78d 100644 --- a/app/src/main/java/org/xbmc/kore/ui/sections/settings/SettingsFragment.java +++ b/app/src/main/java/org/xbmc/kore/ui/sections/settings/SettingsFragment.java @@ -219,6 +219,12 @@ private void setupPreferences() { useHWVolKeysPref.setSummary(useHWVolKeysPref.getEntry()); } + // Preferred YouTube addon + ListPreference preferredYouTubeAddonPref = findPreference(Settings.KEY_PREF_YOUTUBE_ADDON_ID); + if (preferredYouTubeAddonPref != null) { + preferredYouTubeAddonPref.setSummary(preferredYouTubeAddonPref.getEntry()); + } + // About preference String nameAndVersion = context.getString(R.string.app_name); try { diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 881fbcd4d..324801fc6 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -174,4 +174,14 @@ when_in_foreground + + + @string/preferred_youtube_addon_youtube + @string/preferred_youtube_addon_invidious + + + plugin.video.youtube + plugin.video.invidious + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 311e128d5..3379465af 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -492,4 +492,9 @@ Always When Kore is in the foreground + + Preferred YouTube addon + YouTube (plugin.video.youtube) + Invidious (plugin.video.invidious) + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 1eccbef09..edbda0dbc 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -59,6 +59,14 @@ android:defaultValue="false" app:singleLineTitle="false"/> + +