Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parsing youtube.com/{live,shorts} URLs shared from other apps #1010

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
PluginUrlUtils: support parsing youtube.com/{live,shorts} URLs
YouTube now use the new format for live streams and shorts. The pattern
is https://www.youtube.com/{live,shorts}/<video id>. But other than
pattern change, the video ID is otherwise completely compatible with the
old format.

Since this pattern is similar to https://youtu.be/ format, re-use that
code by re-shuffle the conditions a bit. The change is applied to both
default and Invidious plugins.

Fixes: #966
peat-psuwit committed Feb 17, 2024
commit 81a8fdbe5dde2581d4d528c7459ed387b7596aa7
15 changes: 11 additions & 4 deletions app/src/main/java/org/xbmc/kore/utils/PluginUrlUtils.java
Original file line number Diff line number Diff line change
@@ -40,8 +40,9 @@ public class PluginUrlUtils {
@Nullable
public static String toDefaultYouTubePluginUrl(Uri playUri) {
String host = playUri.getHost();
String path = playUri.getPath();

if (host.endsWith("youtube.com")) {
if (host.endsWith("youtube.com") && path.equals("/watch")) {
String videoId = playUri.getQueryParameter("v");
String playlistId = playUri.getQueryParameter("list");
Uri.Builder pluginUri = new Uri.Builder()
@@ -61,7 +62,10 @@ public static String toDefaultYouTubePluginUrl(Uri playUri) {
if (valid) {
return pluginUri.build().toString();
}
} else if (host.endsWith("youtu.be")) {
} else if (host.endsWith("youtu.be") ||
(host.endsWith("youtube.com") && (
path.startsWith("/live/") || path.startsWith("/shorts/")))
) {
return "plugin://plugin.video.youtube/play/?video_id="
+ playUri.getLastPathSegment();
}
@@ -78,6 +82,7 @@ public static String toDefaultYouTubePluginUrl(Uri playUri) {
@Nullable
public static String toInvidiousYouTubePluginUrl(Uri playUri) {
String host = playUri.getHost();
String path = playUri.getPath();

Uri.Builder pluginUri = new Uri.Builder()
.scheme("plugin")
@@ -88,9 +93,11 @@ public static String toInvidiousYouTubePluginUrl(Uri playUri) {
String videoIdParameterKey = "video_id";

String videoId;
if (host.endsWith("youtube.com")) {
if (host.endsWith("youtube.com") && path.equals("/watch")) {
videoId = playUri.getQueryParameter("v");
} else if (host.endsWith("youtu.be")) {
} else if (host.endsWith("youtu.be") ||
(host.endsWith("youtube.com") && (
path.startsWith("/live/") || path.startsWith("/shorts/")))) {
videoId = playUri.getLastPathSegment();
} else {
return null;