From f0b7ff899ffc5a6d63e6ee99d65d941de9d50ffc Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 8 Apr 2018 15:58:42 +0200 Subject: [PATCH] add channel donations for youtube --- .../java/org/schabi/newpipe/extractor/MediaFormat.java | 3 ++- .../services/youtube/YoutubeChannelExtractor.java | 9 ++++++--- .../services/youtube/YoutubeChannelExtractorTest.java | 5 ++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java b/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java index 217056bf7..e39e6977a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java @@ -35,7 +35,8 @@ public enum MediaFormat { // audio formats M4A (0x3, "m4a", "m4a", "audio/mp4"), WEBMA (0x4, "WebM", "webm", "audio/webm"), - MP3 (0x5, "MP3", "mp3", "audio/mpeg"); + MP3 (0x5, "MP3", "mp3", "audio/mpeg"), + OPUS (0x6, "opus", "opus", "audio/opus"); public final int id; public final String name; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java index 91a89fd05..195d20abc 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java @@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; +import org.schabi.newpipe.extractor.utils.DonationLinkHelper; import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Utils; @@ -188,14 +189,16 @@ public class YoutubeChannelExtractor extends ChannelExtractor { public String[] getDonationLinks() throws ParsingException { try { ArrayList links = new ArrayList<>(); - Element linkHolder = doc.select("div[id=\"links-holder\"]").first(); + Element linkHolder = doc.select("div[id=\"header-links\"]").first(); if(linkHolder == null) { // this occures if no links are embeded into the channel return new String[0]; } for(Element a : linkHolder.select("a")) { - System.err.println(a.attr("abs:href")); - links.add(a.attr("abs:href")); + String link = a.attr("abs:href"); + if(DonationLinkHelper.getServiceByLink(link) != DonationLinkHelper.DonationService.NO_DONATION) { + links.add(link); + } } String[] retLinks = new String[links.size()]; retLinks = links.toArray(retLinks); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java index bf953045a..510f210a9 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java @@ -106,11 +106,10 @@ public class YoutubeChannelExtractorTest { } @Test - @Ignore public void testChannelDonation() throws Exception { // this needs to be ignored since wed have to upgrade channel extractor to the new yt interface // in order to make this work - assertTrue(extractor.getDonationLinks().length != 0); + assertTrue(extractor.getDonationLinks().length == 0); } } @@ -217,7 +216,7 @@ public class YoutubeChannelExtractorTest { @Test public void testChannelDonation() throws Exception { - assertTrue(extractor.getDonationLinks().length == 0); + assertTrue(extractor.getDonationLinks().length == 1); } }