From 3e8e2a1532681321c7c349342e032414baee5051 Mon Sep 17 00:00:00 2001 From: mhmdanas Date: Fri, 22 Oct 2021 22:48:18 +0300 Subject: [PATCH] Add support for y2u.be links --- .../extractor/services/youtube/YoutubeParsingHelper.java | 4 ++++ .../linkHandler/YoutubeStreamLinkHandlerFactory.java | 3 ++- .../youtube/YoutubeCommentsLinkHandlerFactoryTest.java | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index 3cbf4b4fb..48ffbac0b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -162,6 +162,10 @@ public class YoutubeParsingHelper { || host.equalsIgnoreCase("y.com.cm"); } + public static boolean isY2ubeURL(@Nonnull final URL url) { + return url.getHost().equalsIgnoreCase("y2u.be"); + } + /** * Parses the duration string of the video expecting ":" or "." as separators * diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java index 65f06dba3..dcdea8736 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java @@ -110,7 +110,7 @@ public class YoutubeStreamLinkHandlerFactory extends LinkHandlerFactory { if (!Utils.isHTTP(url) || !(YoutubeParsingHelper.isYoutubeURL(url) || YoutubeParsingHelper.isYoutubeServiceURL(url) || YoutubeParsingHelper.isHooktubeURL(url) || - YoutubeParsingHelper.isInvidioURL(url))) { + YoutubeParsingHelper.isInvidioURL(url) || YoutubeParsingHelper.isY2ubeURL(url))) { if (host.equalsIgnoreCase("googleads.g.doubleclick.net")) { throw new FoundAdException("Error found ad: " + urlString); } @@ -160,6 +160,7 @@ public class YoutubeStreamLinkHandlerFactory extends LinkHandlerFactory { return assertIsId(viewQueryValue); } + case "Y2U.BE": case "YOUTU.BE": { String viewQueryValue = Utils.getQueryValue(url, "v"); if (viewQueryValue != null) { diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsLinkHandlerFactoryTest.java index 7aba0baa5..0fcaa1c7c 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsLinkHandlerFactoryTest.java @@ -61,4 +61,10 @@ public class YoutubeCommentsLinkHandlerFactoryTest { assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://invidio.us/VM_6n762j6M&t=20").getId()); } + @Test + public void getIdFromY2ube() throws ParsingException { + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://y2u.be/VM_6n762j6M").getId()); + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://Y2U.Be/VM_6n762j6M").getId()); + } + }