|
4 | 4 | import com.grack.nanojson.JsonObject; |
5 | 5 | import com.grack.nanojson.JsonParser; |
6 | 6 | import com.grack.nanojson.JsonParserException; |
| 7 | +import com.sun.org.apache.xerces.internal.xs.StringList; |
7 | 8 | import org.jsoup.Jsoup; |
8 | 9 | import org.jsoup.nodes.Document; |
9 | 10 | import org.jsoup.nodes.Element; |
10 | 11 | import org.schabi.newpipe.extractor.Downloader; |
11 | 12 | import org.schabi.newpipe.extractor.NewPipe; |
12 | 13 | import org.schabi.newpipe.extractor.StreamingService; |
| 14 | +import org.schabi.newpipe.extractor.UrlIdHandler; |
13 | 15 | import org.schabi.newpipe.extractor.channel.ChannelExtractor; |
14 | 16 | import org.schabi.newpipe.extractor.exceptions.ExtractionException; |
15 | 17 | import org.schabi.newpipe.extractor.exceptions.ParsingException; |
16 | 18 | import org.schabi.newpipe.extractor.stream.StreamInfoItem; |
17 | 19 | import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; |
| 20 | +import org.schabi.newpipe.extractor.utils.DonationLinkHelper; |
18 | 21 | import org.schabi.newpipe.extractor.utils.Parser; |
19 | 22 | import org.schabi.newpipe.extractor.utils.Utils; |
20 | 23 |
|
21 | 24 | import javax.annotation.Nonnull; |
22 | 25 | import java.io.IOException; |
| 26 | +import java.util.ArrayList; |
23 | 27 |
|
24 | 28 | /* |
25 | 29 | * Created by Christian Schabesberger on 25.07.16. |
@@ -181,6 +185,29 @@ public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException, |
181 | 185 | return new InfoItemsPage<>(collector, getNextPageUrlFromAjaxPage(ajaxJson, pageUrl)); |
182 | 186 | } |
183 | 187 |
|
| 188 | + @Override |
| 189 | + public String[] getDonationLinks() throws ParsingException { |
| 190 | + try { |
| 191 | + ArrayList<String> links = new ArrayList<>(); |
| 192 | + Element linkHolder = doc.select("div[id=\"header-links\"]").first(); |
| 193 | + if(linkHolder == null) { |
| 194 | + // this occures if no links are embeded into the channel |
| 195 | + return new String[0]; |
| 196 | + } |
| 197 | + for(Element a : linkHolder.select("a")) { |
| 198 | + String link = a.attr("abs:href"); |
| 199 | + if(DonationLinkHelper.getServiceByLink(link) != DonationLinkHelper.DonationService.NO_DONATION) { |
| 200 | + links.add(link); |
| 201 | + } |
| 202 | + } |
| 203 | + String[] retLinks = new String[links.size()]; |
| 204 | + retLinks = links.toArray(retLinks); |
| 205 | + return retLinks; |
| 206 | + } catch (Exception e) { |
| 207 | + throw new ParsingException("Could not get donation links", e); |
| 208 | + } |
| 209 | + } |
| 210 | + |
184 | 211 | private String getNextPageUrlFromAjaxPage(final JsonObject ajaxJson, final String pageUrl) |
185 | 212 | throws ParsingException { |
186 | 213 | String loadMoreHtmlDataRaw = ajaxJson.getString("load_more_widget_html"); |
|
0 commit comments