diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java index 64517f907..98a4c4023 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java @@ -50,7 +50,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { try { return doc.select("div[id=pl-header] h1[class=pl-header-title]").first().text(); } catch (Exception e) { - throw new ParsingException("Could not get playlist name"); + throw new ParsingException("Could not get playlist name", e); } } @@ -59,7 +59,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { try { return doc.select("div[id=pl-header] div[class=pl-header-thumb] img").first().attr("abs:src"); } catch (Exception e) { - throw new ParsingException("Could not get playlist thumbnail"); + throw new ParsingException("Could not get playlist thumbnail", e); } } @@ -72,9 +72,11 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { @Override public String getUploaderUrl() throws ParsingException { try { - return doc.select("ul[class=\"pl-header-details\"] li").first().select("a").first().attr("abs:href"); + return YoutubeChannelExtractor.CHANNEL_URL_BASE + + doc.select("button[class*=\"yt-uix-subscription-button\"]") + .first().attr("data-channel-external-id"); } catch (Exception e) { - throw new ParsingException("Could not get playlist uploader name"); + throw new ParsingException("Could not get playlist uploader url", e); } } @@ -83,7 +85,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { try { return doc.select("span[class=\"qualified-channel-title-text\"]").first().select("a").first().text(); } catch (Exception e) { - throw new ParsingException("Could not get playlist uploader name"); + throw new ParsingException("Could not get playlist uploader name", e); } } @@ -92,7 +94,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { try { return doc.select("div[id=gh-banner] img[class=channel-header-profile-image]").first().attr("abs:src"); } catch (Exception e) { - throw new ParsingException("Could not get playlist uploader avatar"); + throw new ParsingException("Could not get playlist uploader avatar", e); } } @@ -248,6 +250,8 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { @Override public String getUploaderUrl() throws ParsingException { + // this url is not always in the form "/channel/..." + // sometimes Youtube provides urls in the from "/user/..." return getUploaderLink().attr("abs:href"); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java index 1aca59399..3f1b6c4b0 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java @@ -107,6 +107,8 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor { @Override public String getUploaderUrl() throws ParsingException { + // this url is not always in the form "/channel/..." + // sometimes Youtube provides urls in the from "/user/..." try { try { return item.select("div[class=\"yt-lockup-byline\"]").first() @@ -119,7 +121,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor { .text().split(" - ")[0]; } catch (Exception e) { System.out.println(item.html()); - throw new ParsingException("Could not get uploader", e); + throw new ParsingException("Could not get uploader url", e); } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java index b065aa630..df75470e3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java @@ -126,6 +126,8 @@ public class YoutubeTrendingExtractor extends KioskExtractor { } private Element getUploaderLink() { + // this url is not always in the form "/channel/..." + // sometimes Youtube provides urls in the from "/user/..." Element uploaderEl = el.select("div[class*=\"yt-lockup-byline \"]").first(); return uploaderEl.select("a").first(); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java index 9cfd6c00e..9f3c40490 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java @@ -100,7 +100,7 @@ public class YoutubePlaylistExtractorTest { @Test public void testUploaderUrl() throws Exception { - assertTrue(extractor.getUploaderUrl().contains("youtube.com")); + assertEquals("https://www.youtube.com/channel/UCs72iRpTEuwV3y6pdWYLgiw", extractor.getUploaderUrl()); } @Test @@ -185,8 +185,8 @@ public class YoutubePlaylistExtractorTest { public void testMoreRelatedItems() throws Exception { ListExtractor.InfoItemsPage currentPage = defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); - // Test for 2 more levels + // test for 2 more levels for (int i = 0; i < 2; i++) { currentPage = extractor.getPage(currentPage.getNextPageUrl()); defaultTestListOfItems(YouTube.getServiceId(), currentPage.getItems(), currentPage.getErrors()); @@ -214,7 +214,7 @@ public class YoutubePlaylistExtractorTest { @Test public void testUploaderUrl() throws Exception { - assertTrue(extractor.getUploaderUrl().contains("youtube.com")); + assertEquals("https://www.youtube.com/channel/UCHSPWoY1J5fbDVbcnyeqwdw", extractor.getUploaderUrl()); } @Test