add channel donations for youtube

This commit is contained in:
Christian Schabesberger 2018-04-08 15:58:42 +02:00
parent 17e7e5a359
commit 016c2fc549
3 changed files with 10 additions and 7 deletions

View file

@ -35,7 +35,8 @@ public enum MediaFormat {
// audio formats // audio formats
M4A (0x3, "m4a", "m4a", "audio/mp4"), M4A (0x3, "m4a", "m4a", "audio/mp4"),
WEBMA (0x4, "WebM", "webm", "audio/webm"), 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 int id;
public final String name; public final String name;

View file

@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; 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.Parser;
import org.schabi.newpipe.extractor.utils.Utils; import org.schabi.newpipe.extractor.utils.Utils;
@ -188,14 +189,16 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
public String[] getDonationLinks() throws ParsingException { public String[] getDonationLinks() throws ParsingException {
try { try {
ArrayList<String> links = new ArrayList<>(); ArrayList<String> links = new ArrayList<>();
Element linkHolder = doc.select("div[id=\"links-holder\"]").first(); Element linkHolder = doc.select("div[id=\"header-links\"]").first();
if(linkHolder == null) { if(linkHolder == null) {
// this occures if no links are embeded into the channel // this occures if no links are embeded into the channel
return new String[0]; return new String[0];
} }
for(Element a : linkHolder.select("a")) { for(Element a : linkHolder.select("a")) {
System.err.println(a.attr("abs:href")); String link = a.attr("abs:href");
links.add(a.attr("abs:href")); if(DonationLinkHelper.getServiceByLink(link) != DonationLinkHelper.DonationService.NO_DONATION) {
links.add(link);
}
} }
String[] retLinks = new String[links.size()]; String[] retLinks = new String[links.size()];
retLinks = links.toArray(retLinks); retLinks = links.toArray(retLinks);

View file

@ -106,11 +106,10 @@ public class YoutubeChannelExtractorTest {
} }
@Test @Test
@Ignore
public void testChannelDonation() throws Exception { public void testChannelDonation() throws Exception {
// this needs to be ignored since wed have to upgrade channel extractor to the new yt interface // this needs to be ignored since wed have to upgrade channel extractor to the new yt interface
// in order to make this work // in order to make this work
assertTrue(extractor.getDonationLinks().length != 0); assertTrue(extractor.getDonationLinks().length == 0);
} }
} }
@ -217,7 +216,7 @@ public class YoutubeChannelExtractorTest {
@Test @Test
public void testChannelDonation() throws Exception { public void testChannelDonation() throws Exception {
assertTrue(extractor.getDonationLinks().length == 0); assertTrue(extractor.getDonationLinks().length == 1);
} }
} }