Skip to content

Commit 016c2fc

Browse files
committed
add channel donations for youtube
1 parent 17e7e5a commit 016c2fc

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public enum MediaFormat {
3535
// audio formats
3636
M4A (0x3, "m4a", "m4a", "audio/mp4"),
3737
WEBMA (0x4, "WebM", "webm", "audio/webm"),
38-
MP3 (0x5, "MP3", "mp3", "audio/mpeg");
38+
MP3 (0x5, "MP3", "mp3", "audio/mpeg"),
39+
OPUS (0x6, "opus", "opus", "audio/opus");
3940

4041
public final int id;
4142
public final String name;

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1818
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1919
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
20+
import org.schabi.newpipe.extractor.utils.DonationLinkHelper;
2021
import org.schabi.newpipe.extractor.utils.Parser;
2122
import org.schabi.newpipe.extractor.utils.Utils;
2223

@@ -188,14 +189,16 @@ public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException,
188189
public String[] getDonationLinks() throws ParsingException {
189190
try {
190191
ArrayList<String> links = new ArrayList<>();
191-
Element linkHolder = doc.select("div[id=\"links-holder\"]").first();
192+
Element linkHolder = doc.select("div[id=\"header-links\"]").first();
192193
if(linkHolder == null) {
193194
// this occures if no links are embeded into the channel
194195
return new String[0];
195196
}
196197
for(Element a : linkHolder.select("a")) {
197-
System.err.println(a.attr("abs:href"));
198-
links.add(a.attr("abs:href"));
198+
String link = a.attr("abs:href");
199+
if(DonationLinkHelper.getServiceByLink(link) != DonationLinkHelper.DonationService.NO_DONATION) {
200+
links.add(link);
201+
}
199202
}
200203
String[] retLinks = new String[links.size()];
201204
retLinks = links.toArray(retLinks);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,10 @@ public void testSubscriberCount() throws Exception {
106106
}
107107

108108
@Test
109-
@Ignore
110109
public void testChannelDonation() throws Exception {
111110
// this needs to be ignored since wed have to upgrade channel extractor to the new yt interface
112111
// in order to make this work
113-
assertTrue(extractor.getDonationLinks().length != 0);
112+
assertTrue(extractor.getDonationLinks().length == 0);
114113
}
115114
}
116115

@@ -217,7 +216,7 @@ public void testSubscriberCount() throws Exception {
217216

218217
@Test
219218
public void testChannelDonation() throws Exception {
220-
assertTrue(extractor.getDonationLinks().length == 0);
219+
assertTrue(extractor.getDonationLinks().length == 1);
221220
}
222221
}
223222

0 commit comments

Comments
 (0)