From e222867ec6e610dd662e66c3b613652b319664e7 Mon Sep 17 00:00:00 2001 From: blankie Date: Thu, 28 Jul 2022 20:56:45 +0700 Subject: [PATCH] Handle youtu.be URLs --- .../com/blankie/unshortify/ShareActivity.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/blankie/unshortify/ShareActivity.java b/app/src/main/java/com/blankie/unshortify/ShareActivity.java index f2e72fa..a72407b 100644 --- a/app/src/main/java/com/blankie/unshortify/ShareActivity.java +++ b/app/src/main/java/com/blankie/unshortify/ShareActivity.java @@ -56,7 +56,8 @@ public class ShareActivity extends Activity { : null; logVariable("host", host); if (host == null || (!host.equals("youtube.com") && - !host.endsWith(".youtube.com"))) { + !host.endsWith(".youtube.com") && + !host.equals("youtu.be"))) { Toast.makeText(getApplicationContext(), R.string.non_youtube_url, Toast.LENGTH_SHORT).show(); return; @@ -69,14 +70,20 @@ public class ShareActivity extends Activity { Toast.LENGTH_SHORT).show(); return; } - if (!path.toLowerCase(Locale.ROOT).startsWith("/shorts/")) { - Toast.makeText(getApplicationContext(), R.string.non_shorts_url, - Toast.LENGTH_SHORT).show(); - return; - } - final String[] pathSegments = urlParsed.getPath().split("/"); - if (pathSegments.length != 3) { + String videoId = null; + if (host.equals("youtu.be")) { + final String[] pathSegments = urlParsed.getPath().split("/"); + if (pathSegments.length == 2) { + videoId = pathSegments[1]; + } + } else if (path.toLowerCase(Locale.ROOT).startsWith("/shorts/")) { + final String[] pathSegments = urlParsed.getPath().split("/"); + if (pathSegments.length == 3) { + videoId = pathSegments[2]; + } + } + if (videoId == null || videoId.isEmpty()) { Toast.makeText(getApplicationContext(), R.string.non_shorts_url, Toast.LENGTH_SHORT).show(); return;