Skip to content

Commit

Permalink
Add support for the Invidious add-on for YouTube (xbmc#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtimme committed Oct 1, 2023
1 parent 93ad8b3 commit 416664e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/java/org/xbmc/kore/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public static String getRemoteBarItemsPrefKey(int hostId) {
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) {
Expand Down
46 changes: 45 additions & 1 deletion app/src/main/java/org/xbmc/kore/ShareOpenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,14 @@ private String toPluginUrl(Uri playuri) {
*/
@Nullable
private String toYouTubePluginUrl(Uri playuri) {
return toDefaultYouTubePluginUrl(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);
}
}

/**
Expand Down Expand Up @@ -346,6 +353,43 @@ private String toDefaultYouTubePluginUrl(Uri playuri) {
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;
Expand Down

0 comments on commit 416664e

Please sign in to comment.