diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java index a2d67b723..41be13841 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java @@ -59,7 +59,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { public void fetchPage() throws IOException, ExtractionException { Downloader downloader = NewPipe.getDownloader(); - String channelUrl = getCleanUrl() + CHANNEL_URL_PARAMETERS; + String channelUrl = super.getCleanUrl() + CHANNEL_URL_PARAMETERS; String pageContent = downloader.download(channelUrl); doc = Jsoup.parse(pageContent, channelUrl); @@ -67,12 +67,24 @@ public class YoutubeChannelExtractor extends ChannelExtractor { nextStreamsAjax = null; } + @Override + public String getCleanUrl() { + try { + return "https://www.youtube.com/channel/" + getId(); + } catch (ParsingException e) { + return super.getCleanUrl(); + } + } + @Override public String getId() throws ParsingException { try { - return getUrlIdHandler().getId(getCleanUrl()); + Element element = doc.getElementsByClass("yt-uix-subscription-button").first(); + if (element == null) element = doc.getElementsByClass("yt-uix-subscription-preferences-button").first(); + + return element.attr("data-channel-external-id"); } catch (Exception e) { - throw new ParsingException("Could not get channel id"); + throw new ParsingException("Could not get channel id", e); } } @@ -110,8 +122,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { @Override public String getFeedUrl() throws ParsingException { try { - String channelId = doc.getElementsByClass("yt-uix-subscription-button").first().attr("data-channel-external-id"); - return channelId == null ? "" : CHANNEL_FEED_BASE + channelId; + return CHANNEL_FEED_BASE + getId(); } catch (Exception e) { throw new ParsingException("Could not get feed url", e); } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java index d346b972c..3df3add37 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java @@ -41,7 +41,7 @@ public class YoutubeChannelExtractorTest { public void setUp() throws Exception { NewPipe.init(Downloader.getInstance()); extractor = YouTube.getService() - .getChannelExtractor("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw"); + .getChannelExtractor("https://www.youtube.com/user/Gronkh"); } @Test @@ -54,6 +54,16 @@ public class YoutubeChannelExtractorTest { assertEquals(extractor.getName(), "Gronkh"); } + @Test + public void testGetId() throws Exception { + assertEquals(extractor.getId(), "UCYJ61XIK64sp6ZFFS8sctxw"); + } + + @Test + public void testGetUrl() throws Exception { + assertEquals(extractor.getCleanUrl(), "https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw"); + } + @Test public void testGetDescription() throws Exception { assertEquals(extractor.getDescription(), "★ ★ ★ KLICK MICH HART, DU SAU! :D ★ ★ ★ Zart im Schmelz und süffig im Abgang. Ungebremster Spieltrieb seit 1896. Tägliche Folgen nonstop seit dem 01.04.2010!..."); @@ -71,7 +81,7 @@ public class YoutubeChannelExtractorTest { @Test public void testGetFeedUrl() throws Exception { - assertTrue(extractor.getFeedUrl(), extractor.getFeedUrl().contains("feed")); + assertEquals(extractor.getFeedUrl(), "https://www.youtube.com/feeds/videos.xml?channel_id=UCYJ61XIK64sp6ZFFS8sctxw"); } @Test